public void UpdateEntity(Customer customer) { customer.FirstName = FirstName; customer.MidleName = MidleName; customer.LastName = LastName; customer.Gender = (Gender)Gender; customer.CityId = CityId; customer.ContractSum = ContractSum; customer.MinSum = MinSum; customer.MaxSum = MaxSum; customer.ReheshSum = ReheshSum; customer.IsSiteAccess = IsSiteAccess; customer.DateMeeting = DateMeeting; customer.Status = (CustomerStatus)Status; UpdatePhone(customer, 0, Phone1); UpdatePhone(customer, 1, Phone2); UpdatePhone(customer, 2, Phone3); }
public static CustomerEditModel Create(Customer c) { var item = new CustomerEditModel() { EditId = c.Id, Gender = c.Gender.HasValue ? (int)c.Gender : (-1), CityId = c.CityId, CityName = c.City?.Name ?? string.Empty, ContractSum = c.ContractSum, FirstName = c.FirstName, MidleName = c.MidleName, LastName = c.LastName, IsArchive = c.IsArchive, IsSiteAccess = c.IsSiteAccess, MinSum = c.MinSum, MaxSum = c.MaxSum, ReheshSum = c.ReheshSum, DateMeeting = c.DateMeeting, Status = (int)c.Status, Phone1 = c.Phones.SingleOrDefault(x => x.Order == 0)?.Number, Phone2 = c.Phones.SingleOrDefault(x => x.Order == 1)?.Number, Phone3 = c.Phones.SingleOrDefault(x => x.Order == 2)?.Number, DistrictList = c.DistrictToClients.Select(x => x.DistrictId).ToList(), HousingTypeListIds = c.TypesHousingToCustomers.Select(x => x.TypesHousingId).ToList() }; return item; }
public void UpdateHousingTypes(Customer customer) { var toRemove = new List<TypesHousingToCustomer>(); foreach (var district in customer.TypesHousingToCustomers) { if (!HousingTypeListIds.Contains(district.TypesHousingId)) { toRemove.Add(district); } } toRemove.ForEach(x => customer.TypesHousingToCustomers.Remove(x)); foreach (var id in HousingTypeListIds) { var district = customer.TypesHousingToCustomers.FirstOrDefault(x => x.TypesHousingId == id); if (district == null) { customer.TypesHousingToCustomers.Add(new TypesHousingToCustomer() { ClientId = customer.Id, TypesHousingId = id }); } } }
private static void UpdatePhone(Customer item, int order, string phone) { var housingPhone = item.Phones.SingleOrDefault(x => x.Order == order); if (housingPhone != null) { housingPhone.Number = phone; } else if (!string.IsNullOrEmpty(phone)) { housingPhone = new CustomerPhone() { Number = phone, Order = order }; item.Phones.Add(housingPhone); } }
public void UpdateDistricts(Customer customer) { var toRemove = new List<DistrictToСlient>(); foreach (var district in customer.DistrictToClients) { if (!DistrictList.Contains(district.DistrictId)) { toRemove.Add(district); } } toRemove.ForEach(x => customer.DistrictToClients.Remove(x)); foreach (var districtId in DistrictList) { var district = customer.DistrictToClients.FirstOrDefault(x => x.DistrictId == districtId); if (district == null) { customer.DistrictToClients.Add(new DistrictToСlient() { ClientId = customer.Id, DistrictId = districtId }); } } }