public bool AddClient(ModelClient c, string city, string street, string country) { bool operationResult = false; using (ModelClinic modelClinic = new ModelClinic()) { Client client = Mapper.Map <Client>(c); Adress adress = new Adress { City = modelClinic.Cities.FirstOrDefault(cty => cty.Name == city) ?? new City { Name = city }, Street = modelClinic.Streets.FirstOrDefault(str => str.Name == street) ?? new Street { Name = street }, Country = modelClinic.Countries.FirstOrDefault(ctr => ctr.Name == country) ?? new Country { Name = country }, }; client.Adress = adress; try { modelClinic.Clients.Add(client); modelClinic.SaveChanges(); operationResult = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } return(operationResult); }
public ModelClient GetClient(string login, string password) { using (ModelClinic modelClinic = new ModelClinic()) { modelClinic.Configuration.ProxyCreationEnabled = false; ModelClient operationResult = null; var clientDb = modelClinic.Clients .Include(c1 => c1.Adress) .Include(c2 => c2.Adress.City) .Include(c3 => c3.Adress.Country) .Include(c4 => c4.Adress.Street) .Include(c5 => c5.Diagnoses) .Include(c6 => c6.Doctor) .Include(c7 => c7.Doctor.DocStatus) .SingleOrDefault(clt => clt.Login == login && clt.Password == password); operationResult = MapClient(clientDb); return(operationResult); } }