public ActionResult UpdateCustomer(CustomerVM model) { if (!checkSession()) { return(RedirectToAction("Index", "Index")); } if (ModelState.IsValid) { var newPostalArea = new PostalArea() { Area = model.PostalArea, PostCode = model.PostCode }; // Attempt to create new postal area: _adminService.addPostalArea(newPostalArea); Customer customer = new Customer() { BirthNo = model.BirthNo, FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, PhoneNo = model.PhoneNo, PostCode = model.PostCode }; _adminService.updateCustomer(customer); return(Json(new { success = true })); } // else return(PartialView("_EditCustomersPartial", model)); }
public ActionResult EditCustomerPartial(string birthNo) { if (!checkSession()) { return(RedirectToAction("Index", "Index")); } /*Debug.Indent(); * Debug.WriteLine("Ditt personummer er: " + birthNo);*/ var customer = _adminService.getCustomerByBirthNo(birthNo); PostalArea tempPA = _adminService.getPostalAreaByPostCode(customer.PostCode); /*PostalArea postalArea = new PostalArea() * { * Area = tempPA.Area * };*/ var model = new CustomerVM() { BirthNo = customer.BirthNo, FirstName = customer.FirstName, LastName = customer.LastName, Address = customer.Address, PhoneNo = customer.PhoneNo, PostCode = customer.PostCode, PostalArea = tempPA.Area }; return(PartialView("_EditCustomersPartial", model)); }
public bool addPostalArea(PostalArea postalArea) { if (postalArea != null) { return(true); } return(false); }
public ActionResult RegisterCustomer(RegisterCustomer regCustomer) { // If fields does not pass validation: if (!ModelState.IsValid) { // reload view: return(View()); } // Generate salt and create hashed password from salt string salt = BankService.generateSalt(); var passwordAndSalt = regCustomer.Password + salt; byte[] passwordDB = BankService.createHash(passwordAndSalt); // Create new PostalArea Domain model: PostalArea postalArea = new PostalArea() { Area = regCustomer.PostalArea, PostCode = regCustomer.PostCode }; // Add postal area to PostalAreas table in DB: bankService.addPostalArea(postalArea); // Create new customer domain model: Customer customer = new Customer() { BirthNo = regCustomer.BirthNo, FirstName = regCustomer.FirstName, LastName = regCustomer.LastName, Address = regCustomer.Address, PhoneNo = regCustomer.PhoneNo, PostCode = regCustomer.PostCode, //PostalArea = postalArea, Password = passwordDB, Salt = salt }; if (bankService.registerCustomer(customer)) { // If succesfull: return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } else { // If not successfull: return(View()); } }
// INSERT / DELETE public bool addPostalArea(PostalArea postalArea) { try { db.PostalAreas.Add(postalArea); db.SaveChanges(); return(true); } catch (Exception e) { string log = "Failed to add postal area.\t" + e.Message + "\t" + e.StackTrace.ToString(); Debug.Write(log); new LogErrors().errorLog(log); return(false); } }
public ActionResult AddCustomer(AddCustomer regCustomer) { string salt = AdminService.generateSalt(); var passwordAndSalt = regCustomer.Password + salt; byte[] passwordDB = AdminService.createHash(passwordAndSalt); PostalArea postalArea = new PostalArea() { Area = regCustomer.PostalArea, PostCode = regCustomer.PostCode }; _adminService.addPostalArea(postalArea); Customer customer = new Customer() { BirthNo = regCustomer.BirthNo, FirstName = regCustomer.FirstName, LastName = regCustomer.LastName, Address = regCustomer.Address, PhoneNo = regCustomer.PhoneNo, PostCode = regCustomer.PostCode, Password = passwordDB, Salt = salt }; if (_adminService.addCustomer(customer)) { // If succesfull: return(Json(new { success = true })); } else { // If not successfull: return(PartialView("_AddCustomerPartial", regCustomer)); } }
public bool addPostalArea(PostalArea postalArea) { return(postalAreaRepository.addPostalArea(postalArea)); }