public void CreateOrUpdate(CustomerBindingModel model) { var element = _customerStorage.GetElement(new CustomerBindingModel { CustomerName = model.CustomerName, CustomerSurname = model.CustomerSurname, Patronymic = model.Patronymic, Telephone = model.Telephone, Email = model.Email, Password = model.Password, UserType = model.UserType }); if (element != null && element.Id != model.Id) { throw new Exception("Телефон или Email уже был зарегестрирован!"); } if (model.Id.HasValue) { _customerStorage.Update(model); } else { _customerStorage.Insert(model); } }
public IHttpActionResult Create(CustomerBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customer = new Customer(); customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.Email = model.Email; customer.PhoneNumber = model.PhoneNumber; Context.Customers.Add(customer); Context.SaveChanges(); var url = Url.Link("GetCustomerById", new { Id = customer.Id }); //return Ok(); var customerModel = new CustomerViewModel(); customerModel.Id = customer.Id; customerModel.FirstName = customer.FirstName; customerModel.LastName = customer.LastName; customerModel.PhoneNumber = customer.PhoneNumber; customerModel.Email = customer.Email; return(Created(url, customerModel)); }
public void AddElement(CustomerBindingModel model) { Console.WriteLine("Добавление новой записи в бд"); customerServiceDB.AddElement(model); Console.WriteLine("Успешное добавление новой записи в бд"); }
public void Insert(CustomerBindingModel model) { using (var context = new MebelDatabase()) { context.Customers.Add(CreateModel(model, new Customer())); context.SaveChanges(); } }
public void Insert(CustomerBindingModel model) { using (var context = new AutoshowDbContext()) { context.Customers.Add(CreateModel(model, new Customer())); context.SaveChanges(); } }
public void UpdElement(CustomerBindingModel model) { Console.WriteLine($"Изменение записи {model.Id} в бд"); customerServiceDB.UpdElement(model); cache[model.Id] = customerServiceDB.GetElement(model.Id); Console.WriteLine($"Успешное изменение записи {model.Id} в бд"); }
public async Task <ActionResult> Register(CustomerBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await createCustomerCommand.Execute(model); return(Ok()); }
public void Delete(CustomerBindingModel model) { var element = CustomerStorage.GetElement(new CustomerBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Элемент не найден"); } CustomerStorage.Delete(model); }
private void buttonCheck_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { if (manager == null) { return; } CustomerBindingModel customer = manager.Plg["PluginCheck"](service.GetElement(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value))); } LoadData(); }
public List <CustomerViewModel> GetFilteredList(CustomerBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { return(context.Customers .Where(rec => rec.FullName.Contains(model.FullName)) .Select(CreateModel).ToList()); } }
public void Update(CustomerBindingModel model) { using (var context = new MebelDatabase()) { var element = context.Customers.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Заказчик не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public void Delete(CustomerBindingModel model) { var customer = _customerStorage.GetElement(new CustomerBindingModel { Id = model.Id }); if (customer == null) { throw new Exception("Заказчик не найден"); } _customerStorage.Delete(model); }
public CustomerViewModel GetElement(CustomerBindingModel model) { if (model == null) { return(null); } using (var context = new MebelDatabase()) { var customer = context.Customers .FirstOrDefault(rec => rec.Id == model.Id || rec.FullName == model.FullName); return(customer != null? CreateModel(customer) : null); } }
public void Update(CustomerBindingModel model) { using (var context = new AutoshowDbContext()) { var Customer = context.Customers.FirstOrDefault(rec => rec.Id == model.Id); if (Customer == null) { throw new Exception("Сотрудник не найден"); } CreateModel(model, Customer); context.SaveChanges(); } }
private void buttonSum_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { if (manager == null) { return; } CustomerBindingModel customer = manager.Plg["PluginSum"](service.GetElement(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value))); service.UpdElement(customer); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } LoadData(); }
public List <CustomerViewModel> Read(CustomerBindingModel model) { if (model == null) { return(CustomerStorage.GetFullList()); } if (model.Id.HasValue) { return(new List <CustomerViewModel> { CustomerStorage.GetElement(model) }); } return(CustomerStorage.GetFilteredList(model)); }
public void AddElement(CustomerBindingModel model) { Customer element = context.Customers.FirstOrDefault(rec => rec.CustomerFIO == model.CustomerFIO); if (element != null) { throw new Exception("Уже есть клиент с таким ФИО"); } context.Customers.Add(new Customer { CustomerFIO = model.CustomerFIO, State = model.State, Sum = model.Sum }); context.SaveChanges(); }
public void UpdElement(CustomerBindingModel model) { Customer element = source.Customers.FirstOrDefault(rec => rec.CustomerFIO == model.CustomerFIO && rec.Id != model.Id); if (element != null) { throw new Exception("Уже есть покупатель с таким ФИО"); } element = source.Customers.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } element.CustomerFIO = model.CustomerFIO; }
public void Delete(CustomerBindingModel model) { using (var context = new MebelDatabase()) { Customer element = context.Customers.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Customers.Remove(element); context.SaveChanges(); } else { throw new Exception("Заказчик не найден"); } } }
public void AddElement(CustomerBindingModel model) { Customer element = source.Customers.FirstOrDefault(rec => rec.CustomerFIO == model.CustomerFIO); if (element != null) { throw new Exception("Уже есть покупатель с таким ФИО"); } int maxId = source.Customers.Count > 0 ? source.Customers.Max(rec => rec.Id) : 0; source.Customers.Add(new Customer { Id = maxId + 1, CustomerFIO = model.CustomerFIO }); }
public CustomerBindingModel PluginWork(CustomerViewModel customer) { CustomerBindingModel newCustomer = new CustomerBindingModel { Id = customer.Id, CustomerFIO = customer.CustomerFIO, State = (CustomerStatus)Enum.Parse(typeof(CustomerStatus), customer.State, true), Sum = customer.Sum }; var form = new FormStatus(customer); if (form.ShowDialog() == DialogResult.OK) { newCustomer.State = (CustomerStatus)Enum.Parse(typeof(CustomerStatus), form.GetState, true); form.Close(); } return(newCustomer); }
public void Delete(CustomerBindingModel model) { using (var context = new AutoshowDbContext()) { Customer Customer = context.Customers.FirstOrDefault(rec => rec.Id == model.Id); if (Customer != null) { context.Customers.Remove(Customer); context.SaveChanges(); } else { throw new Exception("Сотрудник не найден"); } } }
//[Authorize] public CustomerBindingModel GetDomain(string email) { var user = UserManager.FindByEmail(email); var customer = user.Customer; var customerBindingModel = new CustomerBindingModel { Id = customer.Id, CompanyName = customer.CompanyName, LastName = customer.LastName, FirstName = customer.FirstName, MiddleName = customer.MiddleName, EmailAddress = customer.EmailAddress, Domain = customer.Domain }; return(customerBindingModel); }
public void UpdElement(CustomerBindingModel model) { Customer element = context.Customers.FirstOrDefault(rec => rec.CustomerFIO == model.CustomerFIO && rec.Id != model.Id); if (element != null) { throw new Exception("Уже есть клиент с таким ФИО"); } element = context.Customers.FirstOrDefault(rec => rec.Id == model.Id); if (element == null) { throw new Exception("Элемент не найден"); } element.CustomerFIO = model.CustomerFIO; element.State = model.State; element.Sum = model.Sum; context.SaveChanges(); }
public List <CustomerViewModel> GetFilteredList(CustomerBindingModel model) { if (model == null) { return(null); } using (var context = new AutoshowDbContext()) { return(context.Customers .Where(rec => rec.FirstName.Contains(model.FirstName)) .Select(rec => new CustomerViewModel { Id = rec.Id, FirstName = rec.FirstName, LastName = rec.LastName }).ToList()); } }
public void CreateOrUpdate(CustomerBindingModel model) { var element = CustomerStorage.GetElement(new CustomerBindingModel { FirstName = model.FirstName }); if (element != null && element.Id != model.Id) { throw new Exception("Уже есть покупатель с таким именем"); } if (model.Id.HasValue) { CustomerStorage.Update(model); } else { CustomerStorage.Insert(model); } }
public async Task Execute(CustomerBindingModel model) { var newCustomer = new Customer { CustomerId = Guid.NewGuid().ToString(), FirstName = model.FirstName, LastName = model.LastName, Address = model.LastName, PostCode = model.PostCode, PreferredName = model.PreferredName, PhoneNumber = model.PhoneNumber, PreferredDriverUserId = model.PreferredDriverUserId, ExtraInformation = model.ExtraInformation, Email = model.Email }; context.Customers.Add(newCustomer); await context.SaveChangesAsync(); }
public CustomerViewModel GetElement(CustomerBindingModel model) { if (model == null) { return(null); } using (var context = new AutoshowDbContext()) { var Customer = context.Customers .FirstOrDefault(rec => rec.Id == model.Id); return(Customer != null ? new CustomerViewModel { Id = Customer.Id, FirstName = Customer.FirstName, LastName = Customer.LastName } : null); } }
public void CreateOrUpdate(CustomerBindingModel model) { var customer = _customerStorage.GetElement(new CustomerBindingModel { FullName = model.FullName }); if (customer != null && customer.Id != model.Id) { throw new Exception("Уже есть такой пользователь"); } if (model.Id.HasValue) { _customerStorage.Update(model); } else { _customerStorage.Insert(model); } }
public IHttpActionResult Post(CustomerBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customer = Mapper.Map <Customer>(model); Context.Customers.Add(customer); Context.SaveChanges(); var url = Url.Link("DefaultApi", new { Controller = "Customer", Id = customer.Id }); //return Ok(); var customerModel = Mapper.Map <CustomerViewModel>(customer); return(Created(url, customerModel)); }