public void CreateOrUpdate(ZarplataBindingModel model) { using (var context = new KursachDatabase()) { Zarplata element = model.Id.HasValue ? null : new Zarplata(); if (model.Id.HasValue) { element = context.Zarplatas.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } } else { element = new Zarplata(); context.Zarplatas.Add(element); } element.UserId = model.UserId; element.Name = model.Name; element.Summa = model.Summa; element.data = model.data; context.SaveChanges(); } }
public void CreateOrUpdate(DogovorBindingModel model) { using (var context = new KursachDatabase()) { Dogovor element = context.Dogovors.FirstOrDefault(rec => rec.Id != model.Id); if (model.Id.HasValue) { element = context.Dogovors.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Склад не найден"); } } else { element = new Dogovor(); context.Dogovors.Add(element); element.ClientId = model.ClientId; element.AgentId = model.AgentId; element.data = model.data; } element.Summa = model.Summa; context.SaveChanges(); } }
public void CreateOrUpdate(ReisBindingModel model) { using (var context = new KursachDatabase()) { Reis element = model.Id.HasValue ? null : new Reis(); if (model.Id.HasValue) { element = context.Reiss.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } } else { element = new Reis(); context.Reiss.Add(element); } element.Name = model.Name; element.Cena = model.Cena; element.OfId = model.OfId; element.ToId = model.ToId; element.Time = model.Time; context.SaveChanges(); } }
public void CreateOrUpdate(ClientBindingModel model) { using (var context = new KursachDatabase()) { Client element = model.Id.HasValue ? null : new Client(); if (model.Id.HasValue) { element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } } else { element = new Client(); context.Clients.Add(element); } element.Email = model.Email; element.PhoneNumber = model.PhoneNumber; element.UserId = model.UserId; element.Pasport = model.Pasport; element.ClientFIO = model.ClientFIO; context.SaveChanges(); } }
public void CreateOrUpdate(AgentBindingModel model) { using (var context = new KursachDatabase()) { Agent element = model.Id.HasValue ? null : new Agent(); if (model.Id.HasValue) { element = context.Agents.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } } else { element = new Agent(); context.Agents.Add(element); } element.Name = model.Name; element.Oklad = model.Oklad; element.UserId = model.UserId; element.Comission = model.Comission; context.SaveChanges(); } }
public void Delete(ZarplataBindingModel model) { using (var context = new KursachDatabase()) { Zarplata element = context.Zarplatas.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Zarplatas.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } }
public void DeleteReisDogovor(Dogovor_ReisBM model) { using (var context = new KursachDatabase()) { Dogovor_Reis element = context.Dogovor_Reiss.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Dogovor_Reiss.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } }
public void AddReis(Dogovor_ReisBM model) { using (var context = new KursachDatabase()) { var werehouseCosmetics = context.Dogovor_Reiss.FirstOrDefault(rec => rec.DogovorId == model.DogovorId && rec.ReisId == model.ReisId); if (werehouseCosmetics == null) { context.Dogovor_Reiss.Add(new Dogovor_Reis { DogovorId = model.DogovorId, ReisId = model.ReisId, Obem = model.Obem, ves = model.ves, Comm = model.Comm, NadbavkaCena = model.NadbavkaCena, NadbavkaTime = model.NadbavkaTime }); } else { if (model.Id != 0) { werehouseCosmetics.NadbavkaCena = model.NadbavkaCena; werehouseCosmetics.NadbavkaTime = model.NadbavkaTime; } else { werehouseCosmetics.Obem += model.Obem; werehouseCosmetics.ves += model.ves; werehouseCosmetics.Comm = model.Comm; werehouseCosmetics.NadbavkaCena += model.NadbavkaCena; werehouseCosmetics.NadbavkaTime += model.NadbavkaTime; } } Reis element = context.Reiss.FirstOrDefault(rec => rec.Id == model.ReisId); context.SaveChanges(); } }
public void CreateOrUpdate(UserBindingModel model) { using (var context = new KursachDatabase()) { User element = model.Id.HasValue ? null : new User(); if (model.Id.HasValue) { element = context.Users.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } } else { element = new User(); context.Users.Add(element); } element.Status = model.Status; element.Login = model.Login; element.Password = model.Password; context.SaveChanges(); } }