public Task <FlatOwnerFamily> Create(FlatOwnerFamily flatOwnerFamily) { return(_flatOwnerFamilyRepository.Create(flatOwnerFamily)); }
public Task <List <ReportFlatOwnersTenantsDetail> > UploadFlatOwnersFamily(List <ReportFlatOwnersTenantsDetail> families) { var taskResult = Task.Run(async() => { using (var context = new DbContext()) { //validate foreach (var item in families) { StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(item.Society)) { sb.Append(",Society"); } if (string.IsNullOrEmpty(item.Building)) { sb.Append(",Building"); } if (string.IsNullOrEmpty(item.Wing)) { sb.Append(",Wing"); } if (string.IsNullOrEmpty(item.Floor)) { sb.Append(",Floor"); } if (string.IsNullOrEmpty(item.Flat)) { sb.Append(",Flat"); } if (string.IsNullOrEmpty(item.Owner)) { sb.Append(",Flat Owner"); } if (string.IsNullOrEmpty(item.OwnerType)) { sb.Append(",Flat Owner Type"); } if (string.IsNullOrEmpty(item.Name)) { sb.Append(",Name"); } if (string.IsNullOrEmpty(item.Gender)) { sb.Append(",Gender."); } if (string.IsNullOrEmpty(item.Relationship)) { sb.Append(",Relationship"); } if (sb.Length > 0) { sb.Append(" is/are missing."); sb.Append("<br />"); } var gender = context .MasterValues .FirstOrDefault(m => m.Type == (byte)EnMasterValueType.Gender && m.Text.Equals(item.Gender, StringComparison.InvariantCultureIgnoreCase)); if (gender == null) { sb.Append("Gender text not found in master."); sb.Append("<br />"); } var relationship = context .MasterValues .FirstOrDefault(m => m.Type == (byte)EnMasterValueType.Relationship && m.Text.Equals(item.Relationship, StringComparison.InvariantCultureIgnoreCase)); if (relationship == null) { sb.Append("Relationship text not found in master."); sb.Append("<br />"); } if (sb.Length > 0) { item.IsSuccess = false; item.Message = sb.ToString().Trim(','); continue; } var flatowner = (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 join mffo in context.MapsFlatToFlatOwner on fls.Id equals mffo.FlatId join fos in context.FlatOwners on mffo.FlatOwnerId equals fos.Id where msf.Society.Name.Equals(item.Society, StringComparison.InvariantCultureIgnoreCase) && f.Name.Equals(item.Building, StringComparison.InvariantCultureIgnoreCase) && f.Wing.Equals(item.Wing, StringComparison.InvariantCultureIgnoreCase) && flr.Name.Equals(item.Floor, StringComparison.InvariantCultureIgnoreCase) && fls.Name.Equals(item.Flat, StringComparison.InvariantCultureIgnoreCase) && fos.Name.Equals(item.Owner, StringComparison.InvariantCultureIgnoreCase) && mffo.FlatOwnerType == (item.OwnerType.Equals("Owner", StringComparison.InvariantCultureIgnoreCase) ? 1 : 2) select new { fo = fos }) .Select(f => f.fo) .FirstOrDefault(); if (flatowner == null) { item.IsSuccess = false; item.Message = string.Format("No flat found for {0}-{1}-{2}-{3}-{4}.", item.Society, item.Building, item.Wing, item.Floor, item.Flat); continue; } var family = new FlatOwnerFamily() { Name = item.Name, MobileNo = item.MobileNo, AadhaarCardNo = item.AadhaarCardNo, DateOfBirth = item.DateOfBirth, GenderId = gender.Id, RelationshipId = relationship.Id, FlatOwnerId = flatowner.Id }; try { await _flatOwnerFamilyRepository.Create(family); } catch (Exception ex) { item.IsSuccess = false; item.Message = ex.Message; continue; } item.IsSuccess = true; item.Message = "Done"; } return(families); } }); return(taskResult); }