public void Insert(TransportBindingModel model) { using (var context = new TravelAgencyContext()) { context.Transport.Add(CreateModel(model, new Transport())); context.SaveChanges(); } }
public void Insert(TransportBindingModel model) { using (var context = new AutoServiceDatabase()) { context.Transports.Add(CreateModel(model, new Transport())); context.SaveChanges(); } }
private Transport CreateModel(TransportBindingModel model, Transport transport) { transport.Routefrom = model.Routefrom; transport.Routeto = model.Routeto; transport.Viewtransport = model.Viewtransport; transport.Priceticket = model.Priceticket; transport.Routeid = model.Routeid; return(transport); }
private Transport CreateModel(TransportBindingModel model, Transport transport) { transport.Number = model.Number; transport.Label = model.Label; transport.Model = model.Model; transport.Color = model.Color; transport.Year = model.Year; transport.ClientId = model.ClientId; return(transport); }
public void CreateOrUpdate(TransportBindingModel model) { if (model.Id.HasValue) { _transportStorage.Update(model); } else { _transportStorage.Insert(model); } }
public void Delete(TransportBindingModel model) { var element = _transportStorage.GetElement(new TransportBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Транспорт не найден"); } _transportStorage.Delete(model); }
public void Update(TransportBindingModel model) { using (var context = new AutoServiceDatabase()) { var element = context.Transports.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Транспорт не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public void Update(TransportBindingModel model) { using (var context = new TravelAgencyContext()) { var element = context.Transport.FirstOrDefault(rec => rec.Transportid == model.Id); if (element == null) { throw new Exception("Способ передвижения не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public List <TransportViewModel> Read(TransportBindingModel model) { if (model == null) { return(_transportStorage.GetFullList()); } if (model.Id.HasValue) { return(new List <TransportViewModel> { _transportStorage.GetElement(model) }); } return(_transportStorage.GetFilteredList(model)); }
public TransportViewModel GetElement(TransportBindingModel model) { if (model == null) { return(null); } using (var context = new AutoServiceDatabase()) { var transport = context.Transports .Include(rec => rec.Client) .FirstOrDefault(rec => rec.Number.Equals(model.Number) || rec.Id == model.Id); return(transport != null?CreateModel(transport) : null); } }
public List <TransportViewModel> GetFilteredList(TransportBindingModel model) { if (model == null) { return(null); } using (var context = new AutoServiceDatabase()) { return(context.Transports .Include(rec => rec.Client) .Where(rec => rec.Label.Contains(model.Label)) .Select(CreateModel).ToList()); } }
public TransportViewModel GetElement(TransportBindingModel model) { if (model == null) { return(null); } using (var context = new TravelAgencyContext()) { var accounting = context.Transport.Include(x => x.Route) .FirstOrDefault(rec => rec.Transportid == model.Id); return(accounting != null?CreateModel(accounting) : null); } }
public List <TransportViewModel> GetFilteredList(TransportBindingModel model) { if (model == null) { return(null); } using (var context = new TravelAgencyContext()) { return(context.Transport.Include(x => x.Route) .Where(rec => rec.Routeto == model.Routeto && rec.Routefrom == model.Routefrom) .Select(CreateModel) .ToList()); } }
public void Delete(TransportBindingModel model) { using (var context = new TravelAgencyContext()) { Transport element = context.Transport.FirstOrDefault(rec => rec.Transportid == model.Id); if (element != null) { context.Transport.Remove(element); context.SaveChanges(); } else { throw new Exception("Способ передвижения не найден"); } } }
public void CreateOrUpdate(TransportBindingModel model) { var element = _transportStorage.GetElement(new TransportBindingModel { Number = model.Number }); if (element != null && element.Id != model.Id) { throw new Exception("Уже есть транспорт с таким гос номером"); } if (model.Id.HasValue) { _transportStorage.Update(model); } else { _transportStorage.Insert(model); } }
private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxViewTransport.Text) || string.IsNullOrEmpty(textBoxPrice.Text)) { MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (dataGridView.SelectedRows.Count != 1) { return; } var route = _logicR.Read(new RouteBindingModel { Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value) })?[0]; TransportBindingModel model = new TransportBindingModel { Routefrom = route.Cityfrom, Routeto = route.Cityto, Routeid = route.Id, Viewtransport = textBoxViewTransport.Text, Priceticket = Convert.ToInt32(textBoxPrice.Text) }; if (Id.HasValue) { model.Id = Id; } _logicT.CreateOrUpdate(model); MessageBox.Show("Успешно", "Сохранено", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.InnerException?.Message + "\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }