public static DC.Customer Map(P1B.Customer customer) => new DC.Customer { CustomerId = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, DefaultLocation = customer.DefaultLocation };
public void AddCustomer(Project1.BLL.Customer customer) { var newCustomer = new Project1.DataAccess.DataClasses.Customer { FirstName = customer.FirstName, LastName = customer.LastName, DefaultLocation = customer.DefaultLocation }; Context.Customer.Add(newCustomer); SaveChangesAndCheckException(); }
public ActionResult Create(P1B.Customer customer) { try { if (customer.FirstName.Length == 0 || customer.LastName.Length == 0) { string message = "The customer must have a first and last name."; TempData["ErrorMessage"] = message; _logger.LogWarning(message); return(RedirectToAction("Error", "Home")); } if (CustomerRepo.CheckCustomerFullNameExists(customer.ReturnFullName())) { string message = "There is already a customer in the system with that first and last name."; TempData["ErrorMessage"] = message; _logger.LogWarning(message); return(RedirectToAction("Error", "Home")); } int defLocation = customer.DefaultLocation ?? 0; if (defLocation != 0) { bool LocationExists = LocRepo.CheckLocationExists(defLocation); if (!LocationExists) { string message = "This location is not in the database."; TempData["ErrorMessage"] = message; _logger.LogWarning(message); return(RedirectToAction("Error", "Home")); } } // TODO: Add insert logic here var newCustomer = new P1B.Customer { FirstName = customer.FirstName, LastName = customer.LastName, DefaultLocation = customer.DefaultLocation ?? null }; // TODO: Add insert logic here CustomerRepo.AddCustomer(newCustomer); return(RedirectToAction(nameof(Index))); // TODO: Add insert logic here } catch (Exception ex) { _logger.LogError(ex.ToString()); return(RedirectToAction("Error", "Home")); } }