public async Task <IEnumerable <ServiceBillDTO> > GetAll(FlatDTO dto) { var flats = await buildingService.GetFlats(); var periods = await periodService.GetPeriods(); var typeofservices = await typeOfServiceService.GetTypeOfServices(); using (MUEContext db = new MUEContext()) { var servicebills = await db.ServiceBills.Where(s => s.FlatId == dto.FlatId).ToListAsync(); return(servicebills.Select(s => new ServiceBillDTO { FlatId = s.FlatId, PeriodId = s.PeriodId, ServiceBillId = s.ServiceBillId, TypeOfServiceId = s.TypeOfServiceId, Summ = s.Summ, Status = s.Status, Period = periods.Where(p => p.PeriodId == s.PeriodId).Select(p => p.Name).FirstOrDefault(), Flat = flats.Where(f => f.FlatId == s.FlatId).Select(f => f.Address).FirstOrDefault(), TypeOfService = typeofservices.Where(t => t.TypeOfServiceId == s.TypeOfServiceId).Select(t => t.Name).FirstOrDefault() }).ToList()); } }
public async Task <FlatDTO> Create(FlatDTO modelDTO) { var model = _mapper.Map <FlatDTO, Flat>(modelDTO); model.CreatedDate = DateTime.Now; model.CreatedBy = ""; var create = _db.Flats.Add(model); await _db.SaveChangesAsync(); return(_mapper.Map <Flat, FlatDTO>(create.Entity)); }
public async Task Create(FlatDTO dto, PeriodDTO periodDTO) { var billservice = await serviceBillService.GetAll(dto, periodDTO); double summ = 0; foreach (var item in billservice) { summ += item.Summ; } await Create(new SettlementSheetDTO { AmmountToBePaid = summ, FlatId = dto.FlatId, PeriodId = periodDTO.PeriodId, Status = 0, Flat = dto.Address, Period = periodDTO.Name, }); }
public async Task <FlatDTO> Update(int id, FlatDTO modelDTO) { if (id == modelDTO.Id) { var modelDetails = await _db.Flats.FirstOrDefaultAsync(x => x.Id == id); //Flat var model = _mapper.Map <FlatDTO, Flat>(modelDTO, modelDetails); //Flat model.UpdatedBy = ""; model.UpdateDate = DateTime.Now; var updateModel = _db.Flats.Update(model); await _db.SaveChangesAsync(); return(_mapper.Map <Flat, FlatDTO>(updateModel.Entity)); } else { return(null); } }
public async Task <IEnumerable <SettlementSheetDTO> > GetAll(FlatDTO flatDTO) { var flats = await buildingService.GetFlats(); var periods = await periodService.GetPeriods(); using (MUEContext db = new MUEContext()) { var ss = await db.SettlementSheets.Where(sse => sse.FlatId == flatDTO.FlatId).ToListAsync(); return(ss.Select(ssd => new SettlementSheetDTO { AmmountToBePaid = ssd.AmmountToBePaid, Description = ssd.Description, FlatId = ssd.FlatId, PeriodId = ssd.PeriodId, SettlementSheetId = ssd.SettlementSheetId, Status = ssd.Status, Flat = flats.Where(f => ssd.FlatId == f.FlatId).Select(f => f.Address).FirstOrDefault(), Period = periods.Where(p => ssd.PeriodId == p.PeriodId).Select(p => p.Name).FirstOrDefault() }).ToList()); } }
public async Task Create(FlatDTO dto, Guid PeriodId) { var period = await periodService.GetPeriodDTO(PeriodId); var previousPeriod = await periodService.GetPreviousPerioDTO(PeriodId); var meterReadings = await meterReadingService.GetForPeriod(PeriodId); IEnumerable <MeterReadingDTO> previousMeterReadings; if (previousPeriod == null) { previousMeterReadings = null; } else { previousMeterReadings = await meterReadingService.GetForPeriod(previousPeriod.PeriodId); } var tariffs = await tariffService.GetTariffs(); var tariffForFLat = tariffs.Where(t => t.FlatId == dto.FlatId).ToList(); foreach (var item in tariffForFLat) { if (item.IsMeter) { var CurrentValue = meterReadings.Where(m => m.FlatId == dto.FlatId && m.TypeofServiceId == item.TypeOfServiceId).FirstOrDefault(); MeterReadingDTO LastValue; if (previousMeterReadings == null) { LastValue = null; } else { LastValue = previousMeterReadings.Where(m => m.FlatId == dto.FlatId && m.TypeofServiceId == item.TypeOfServiceId).FirstOrDefault(); } if (LastValue == null) { if (CurrentValue == null) { await Create(new ServiceBillDTO { Summ = 0, FlatId = dto.FlatId, PeriodId = PeriodId, TypeOfServiceId = item.TypeOfServiceId }); } else { await Create(new ServiceBillDTO { Summ = CurrentValue.Value * item.Value, FlatId = dto.FlatId, PeriodId = PeriodId, TypeOfServiceId = item.TypeOfServiceId }); } } else { await Create(new ServiceBillDTO { Summ = LastValue.Value > CurrentValue.Value? 0 : (CurrentValue.Value - LastValue.Value) * item.Value, FlatId = dto.FlatId, PeriodId = PeriodId, TypeOfServiceId = item.TypeOfServiceId }); } } else { var CurrentValue = meterReadings.Where(m => m.FlatId == dto.FlatId && m.TypeofServiceId == item.TypeOfServiceId).FirstOrDefault(); if (CurrentValue == null) { await Create(new ServiceBillDTO { Summ = 0, FlatId = dto.FlatId, PeriodId = PeriodId, TypeOfServiceId = item.TypeOfServiceId }); } else { await Create(new ServiceBillDTO { Summ = (CurrentValue.Value) * item.Value, FlatId = dto.FlatId, PeriodId = PeriodId, TypeOfServiceId = item.TypeOfServiceId }); } } } }