2
Answers

avoid inserting duplicate value for every block

Garima Bansal

Garima Bansal

May 14
419
1

Hi,

1 application can have multiple blocks and a single compounding wall price for each application, and if c.wall value is added in any block then it should read-only for other block.

 

how can I do.

Answers (2)
2
Vishal Joshi

Vishal Joshi

244 7.8k 135.4k May 14

Hello,

Handel Duplicate value in calculation

As per the question, there are duplicate prices in add/update record. It's fine to have same value for each block because when you check for a single block you need the same value.
But, you can check in foreach loop if it's a duplicate or the same value you should take FirstOrDefault() or not add again if it's already added to the total price calculation.

 

Make the input field read-only

you can check if a value has already been added in a database or if it's not null or zero then you should set read-only  

Thanks

Vishal Joshi

Accepted
1
Jayraj Chhaya

Jayraj Chhaya

310 6k 94.1k May 14

To achieve this in a .NET application, you can utilize data structures like dictionaries or hashsets to store unique values for each block. Additionally, you can implement a mechanism to enforce read-only access to the compounding wall value across blocks.

using System;
using System.Collections.Generic;

public class Application
{
    private Dictionary<string, decimal> blockPrices = new Dictionary<string, decimal>();
    private decimal compoundingWallPrice;

    public void SetBlockPrice(string blockName, decimal price)
    {
        if (!blockPrices.ContainsKey(blockName))
        {
            blockPrices[blockName] = price;
        }
    }

    public decimal GetBlockPrice(string blockName)
    {
        return blockPrices.ContainsKey(blockName) ? blockPrices[blockName] : 0;
    }

    public decimal CompoundingWallPrice
    {
        get { return compoundingWallPrice; }
        private set { compoundingWallPrice = value; }
    }
}