public Task UpdateTillDate(MapFlatToFlatOwner flatOwner) { var taskResult = Task.Run(() => { using (var context = new DbContext()) { var existingRecord = context .MapsFlatToFlatOwner .FirstOrDefault(p => p.FlatOwnerId == flatOwner.FlatOwner.Id && p.FlatId == flatOwner.Flat.Id); if (existingRecord == null) { throw new Exception("Flat owner details not found"); } if (existingRecord.MemberTillDate.HasValue) { throw new Exception("Cannot update. Member till date already found."); } if (existingRecord.MemberSinceDate > flatOwner.MemberTillDate) { throw new Exception("Member Till date cannot be before Member Since Date"); } existingRecord.MemberTillDate = flatOwner.MemberTillDate; context.SaveChanges(); } }); return(taskResult); }
public Task UpdateSinceDate(MapFlatToFlatOwner flatOwner) { var taskResult = Task.Run(async() => { using (var context = new DbContext()) { var existingRecord = context .MapsFlatToFlatOwner .FirstOrDefault(p => p.FlatOwnerId == flatOwner.FlatOwner.Id && p.FlatId == flatOwner.Flat.Id); if (existingRecord == null) { throw new Exception("Flat owner details not found"); } var society = (from msf in context.MapsSocietiesToFacilities join f in context.Facilities on msf.FacilityId equals f.Id join flr in context.Floors on f.Id equals flr.FacilityId join fls in context.Flats on flr.Id equals fls.FloorId where fls.Id == flatOwner.FlatId select new { Society = msf.Society }) .Select(s => s.Society) .FirstOrDefault(); if (flatOwner.MemberSinceDate < society.DateOfIncorporation) { throw new Exception("Member since date cannot be before date of incorporation of the society"); } if (existingRecord.FlatOwner.IsApproved) { throw new Exception("Cannot update. Flat owner details approved."); } existingRecord.MemberSinceDate = flatOwner.MemberSinceDate; context.SaveChanges(); } }); return(taskResult); }
public Task UpdateSinceDate(MapFlatToFlatOwner flatOwner) { return(_flatOwnerServiceRepository.UpdateSinceDate(flatOwner)); }