public async Task <ResponseMessageDto> ListPost(IEnumerable <CustomerSuppliedRequestDto> customerSupplied, DateTime date) { try { var customerSuppliedRequestDtos = customerSupplied.ToList(); foreach (var dto in customerSuppliedRequestDtos) { var customerCurrentRate = _customerRateRepository.GetCurrentRateByCustomerId(dto.CustomerId); var supply = CustomerSuppliedCalculation.GetMorningSupplyAndAfterNoonSupply(dto.MorningSupply, dto.AfternoonSupply, customerCurrentRate); var sumUp = Convert.ToDouble(supply.morningsupply) + Convert.ToDouble(supply.afternoonSupply); dto.Rate = customerCurrentRate; dto.Debit = 0; var credit = sumUp - dto.Debit; dto.Credit = Convert.ToInt32(credit); dto.Total = sumUp; dto.MorningAmount = Convert.ToDouble(supply.morningsupply); dto.AfternoonAmount = Convert.ToDouble(supply.afternoonSupply); } var model = customerSuppliedRequestDtos.Select(i => new CustomerSupplied() { CustomerId = i.CustomerId, CustomerTypeId = i.CustomerTypeId, MorningSupply = i.MorningSupply, AfternoonSupply = i.AfternoonSupply, CreatedOn = date.Date, Rate = Convert.ToInt32(i.Rate), MorningAmount = i.MorningAmount, AfternoonAmount = i.AfternoonAmount, Credit = i.Credit, Debit = i.Debit, Total = i.Total }); var result = await _customerSuppliedRepository.ListPost(model); return(new ResponseMessageDto() { Id = result, SuccessMessage = ResponseMessages.CustomerSuppliedListSuccessfullyInserted, Success = true, Error = false }); } catch (Exception e) { return(new ResponseMessageDto() { Id = Convert.ToInt16(Enums.FailureId), FailureMessage = ResponseMessages.CustomerSuppliedListFailed, Success = false, Error = true, ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message }); } }
public async Task <ResponseMessageDto> Post(CustomerSuppliedRequestDto dto) { try { if (!_customerSuppliedRepository.IsCustomerRecordAvailableOnParticularDate( dto.CustomerId, dto.CreatedOn.Date)) { var customerCurrentRate = _customerRateRepository.GetCurrentRateByCustomerId(dto.CustomerId); var supply = CustomerSuppliedCalculation.GetMorningSupplyAndAfterNoonSupply(dto.MorningSupply, dto.AfternoonSupply, customerCurrentRate); var sumUp = Convert.ToDouble(supply.morningsupply) + Convert.ToDouble(supply.afternoonSupply); dto.Rate = customerCurrentRate; var credit = sumUp - dto.Debit; dto.Credit = Convert.ToInt32(credit); dto.Total = sumUp; dto.MorningAmount = Convert.ToDouble(supply.morningsupply); dto.AfternoonAmount = Convert.ToDouble(supply.afternoonSupply); var customerSupplied = await _asyncRepository.AddAsync(_mapper.Map <CustomerSupplied>(dto)); return(new ResponseMessageDto() { Id = customerSupplied.Id, SuccessMessage = ResponseMessages.InsertionSuccessMessage, Success = true, Error = false }); } return(new ResponseMessageDto() { Id = Convert.ToInt16(Enums.FailureId), FailureMessage = ResponseMessages.CustomerAlreadyInsertedInThisDate, 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 }); } }