コード例 #1
0
        public async Task <ResponseMessageDto> Put(MarketPurchaseRequestDto dto)
        {
            try
            {
                var(morningsupply, afternoonSupply) =
                    MarketPurchaseCalculation.GetMorningSupplyAndAfterNoonSupply(dto.MorningPurchase,
                                                                                 dto.AfternoonPurchase, Convert.ToInt32(dto.MorningRate), Convert.ToInt32(dto.AfternoonRate));
                var sumUp = Convert.ToDouble(morningsupply) +
                            Convert.ToDouble(afternoonSupply);
                string grandMilkTotal = TotalMilkCalculate.TotalMilkCalulate(dto.MorningPurchase, dto.AfternoonPurchase);
                dto.MorningAmount   = morningsupply;
                dto.AfternoonAmount = afternoonSupply;
                dto.TotalAmount     = Convert.ToInt32(sumUp);
                dto.TotalMilk       = grandMilkTotal;
                await _asyncRepository.PartialUpdate(dto, m => ///yahan woh values aengi jo ke update karni hongi
                {
                    m.MarketSupplierId  = dto.MarketSupplierId;
                    m.MorningPurchase   = dto.MorningPurchase;
                    m.MorningRate       = dto.MorningRate;
                    m.MorningAmount     = dto.MorningAmount;
                    m.AfternoonPurchase = dto.AfternoonPurchase;
                    m.AfternoonAmount   = dto.AfternoonAmount;
                    m.AfternoonRate     = dto.AfternoonRate;
                    m.TotalAmount       = dto.TotalAmount;
                    m.TotalMilk         = dto.TotalMilk;
                });

                return(new ResponseMessageDto()
                {
                    Id = dto.Id,
                    SuccessMessage = ResponseMessages.UpdateSuccessMessage,
                    Success = true,
                    Error = false
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessageDto()
                {
                    Id = Convert.ToInt16(Enums.FailureId),
                    FailureMessage = ResponseMessages.UpdateFailureMessage,
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }
コード例 #2
0
        public async Task <ResponseMessageDto> Post(MarketPurchaseRequestDto dto)
        {
            try
            {
                if (!await _marketPurchaseRepository.IsMarketSupplierInsertedOnCurrentDate(dto.MarketSupplierId))
                {
                    var(morningsupply, afternoonSupply) =
                        MarketPurchaseCalculation.GetMorningSupplyAndAfterNoonSupply(dto.MorningPurchase,
                                                                                     dto.AfternoonPurchase, Convert.ToInt32(dto.MorningRate), Convert.ToInt32(dto.AfternoonRate));
                    var sumUp = Convert.ToDouble(morningsupply) +
                                Convert.ToDouble(afternoonSupply);
                    string grandMilkTotal = TotalMilkCalculate.TotalMilkCalulate(dto.MorningPurchase, dto.AfternoonPurchase);
                    dto.MorningAmount   = morningsupply;
                    dto.AfternoonAmount = afternoonSupply;
                    dto.TotalAmount     = Convert.ToInt32(sumUp);
                    dto.TotalMilk       = grandMilkTotal;
                    var marketPucrchase = await _asyncRepository.AddAsync(_mapper.Map <MarketPurchase>(dto));

                    return(new ResponseMessageDto()
                    {
                        Id = marketPucrchase.Id,
                        SuccessMessage = ResponseMessages.InsertionSuccessMessage,
                        Success = true,
                        Error = false
                    });
                }
                return(new ResponseMessageDto()
                {
                    Id = Convert.ToInt16(Enums.FailureId),
                    FailureMessage = ResponseMessages.SupplierAlreadyInsertedInThisDate,
                    Success = false,
                    Error = true
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessageDto()
                {
                    Id = Convert.ToInt16(Enums.FailureId),
                    FailureMessage = ResponseMessages.InsertionFailureMessage,
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }