public async Task <ActionResult> Edit(ManageCustomerViewModel model) { ApplicationDbContext appDb = new ApplicationDbContext(); if (ModelState.IsValid) { Customer customer = applicationDb.Customers.Find(User.Identity.GetUserId()); if (customer != null) { customer.Email = model.Email; customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.PhoneNumber = model.PhoneNumber; customer.Status = "changed"; customer.City = model.City; customer.BillingAddress = model.BillingAddress; // create a new customer object applicationDb.Entry(customer).State = System.Data.Entity.EntityState.Modified; applicationDb.SaveChanges(); } } return(View("Manage", model)); }
public IActionResult RegisterCustomer() { var model = new ManageCustomerViewModel(); model.Gender = _manageCustomerRepo.GetGender(); return(View(model)); }
public IActionResult UpdateCustomer(int id) { var model = new ManageCustomerViewModel(); model = _manageCustomerRepo.GetCustomer(id); model.Gender = _manageCustomerRepo.GetGender(); return(View(model)); }
public ActionResult Manage() { var customer = applicationDb.Customers.Find(User.Identity.GetUserId()); ManageCustomerViewModel model = new ManageCustomerViewModel { Id = User.Identity.GetUserId(), Email = customer.Email, BillingAddress = customer.BillingAddress, City = customer.City, FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumber = customer.PhoneNumber }; return(View(model)); }
public IActionResult UpdateCustomer(ManageCustomerViewModel model) { if (ModelState.IsValid) { _manageCustomerRepo.UpdateCustomer(model); return(RedirectToAction("ShowCustomer", "Customer", new { id = model.CustomerId })); } return(View(model)); }
public ActionResult Add() { var mt = _context.MembershipType.ToList(); var vm = new ManageCustomerViewModel { Customer = new Customer(), MembershipTypes = mt, }; return(View(vm)); }
public IActionResult RegisterCustomer(ManageCustomerViewModel model) { if (ModelState.IsValid) { _manageCustomerRepo.RegisterCustomer(model); return(RedirectToAction("ShowAccountInfo", "Account", new { id = model.AccountId })); } model.Gender = _manageCustomerRepo.GetGender(); return(View(model)); }
public ActionResult Edit(int id) { var mt = _context.MembershipType.ToList(); var c = _context.Customers.SingleOrDefault(cs => cs.id == id); var vm = new ManageCustomerViewModel { MembershipTypes = mt, Customer = c }; return(View(vm)); }
public ManageCustomerViewModel UpdateCustomer(ManageCustomerViewModel model) { var customer = _context.Customers.SingleOrDefault(c => c.CustomerId == model.CustomerId); customer.Givenname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.GivenName); customer.Surname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Surname); customer.Emailaddress = model.Email.ToLower(); customer.Streetaddress = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Address); customer.City = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.City); customer.NationalId = model.NationalId; customer.Country = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Country); customer.CountryCode = model.CountryCode.ToUpper(); customer.Gender = model.ChosenGender; customer.Zipcode = model.ZipCode; _context.SaveChanges(); return(model); }
public List <SelectListItem> GetGender() { ManageCustomerViewModel model = new ManageCustomerViewModel(); var male = new SelectListItem() { Value = "Male", Text = "Male" }; var female = new SelectListItem() { Value = "Female", Text = "Female" }; model.Gender.Add(male); model.Gender.Add(female); return(model.Gender); }
public ActionResult Save(ManageCustomerViewModel cust) { var customer = cust.Customer; var mem = _context.MembershipType.ToList(); var vm = new ManageCustomerViewModel { Customer = customer, MembershipTypes = mem }; if (!ModelState.IsValid) { if (cust.Customer.id == 0) { return(View("Add", vm)); } else { return(View("Edit", vm)); } } if (cust.Customer.id == 0) { _context.Customers.Add(cust.Customer); } else { var oldCust = _context.Customers.Single(c => c.id == cust.Customer.id); //oldCust.name = cust.Customer.name; //oldCust.isSubscribed = cust.Customer.isSubscribed; //oldCust.birthdate = cust.Customer.birthdate; //oldCust.MembershipType = cust.Customer.MembershipType; oldCust = cust.Customer; } _context.SaveChanges(); return(RedirectToAction("Index", "Customer")); }
public ManageCustomerViewModel RegisterCustomer(ManageCustomerViewModel model) { var newCustomer = new Customers() { Givenname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.GivenName), Surname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Surname), Emailaddress = model.Email.ToLower(), Streetaddress = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Address), City = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.City), NationalId = model.NationalId, Country = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Country), CountryCode = model.CountryCode.ToUpper(), Gender = model.ChosenGender, Zipcode = model.ZipCode }; _context.Customers.Add(newCustomer); var newAccount = new Accounts() { Created = DateTime.Now, Balance = 0, Frequency = "Monthly" }; _context.Accounts.Add(newAccount); var newDisposition = new Dispositions { Account = newAccount, Customer = newCustomer, Type = "Owner" }; _context.Dispositions.Add(newDisposition); _context.SaveChanges(); model.AccountId = newAccount.AccountId; return(model); }
public ManageCustomerViewModel GetCustomer(int id) { ManageCustomerViewModel model = new ManageCustomerViewModel(); model.Customers = _context.Customers.Where(c => c.CustomerId == id).ToList(); model.CustomerId = id; foreach (var c in model.Customers) { model.GivenName = c.Givenname; model.Surname = c.Surname; model.Email = c.Emailaddress; model.Address = c.Streetaddress; model.City = c.City; model.NationalId = c.NationalId; model.Country = c.Country; model.CountryCode = c.CountryCode; model.ChosenGender = c.Gender; model.ZipCode = c.Zipcode; } return(model); }