public void AddDiagnosis(int IdClient, string name, string description) { var diagnos = _dbCtx.Diagnoses.FirstOrDefault(dig => dig.Name == name) ?? new Diagnosis() { Name = name, Description = description }; _dbCtx.Clients.FirstOrDefault(f => f.Id == IdClient).Diagnoses.Add(diagnos); _dbCtx.SaveChanges(); }
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); }