public async Task <ActionResult> EditName([Bind(Include = "CustomerId,FName,LName")] CustomerEditView customer) { if (ModelState.IsValid) { var dbCustomer = await _repository.Customer.GetEditView(customer.CustomerId); if (dbCustomer == null) { return(HttpNotFound()); } dbCustomer.FName = customer.FName; dbCustomer.LName = customer.LName; await _repository.Commit(); var returnUrl = (string)Session["ReturnUrl"]; if (returnUrl != "") { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index")); } } return(View(customer)); }
public async Task <JsonResult> updateCusomerProfile(CustomerEditView EditedCustomer, string property) { bool Succeeded = false; PaskolUser user = UserManager.FindById(User.Identity.GetUserId()); if (user != null) { // Save artist details if (property == "Name") { if (Succeeded = ModelState.IsValidField("Name")) { user.UserName = EditedCustomer.Name; } } else if (property == "Email") { if (Succeeded = ModelState.IsValidField("Email")) { user.Email = EditedCustomer.Email; } } else if (property == "Phone") { if (Succeeded = ModelState.IsValidField("Phone")) { user.PhoneNumber = EditedCustomer.Phone; } } else if (property == "CompanyName") { if (Succeeded = ModelState.IsValidField("CompanyName")) { user.Customer.CompanyName = EditedCustomer.CompanyName; } } else if (property == "Password") { Succeeded = ModelState.IsValidField("Password"); } if ((Succeeded) && await UpdateUserAsync(user, EditedCustomer.Password)) { Succeeded = true; } else { Succeeded = false; } } return(Json(new ActionResponse() { Succeeded = Succeeded, FiledErrors = DicModelState })); }
public static PaskolUser UserFromCustomerDetails(this CustomerEditView userDetails, PaskolUser user) { PaskolUser RetUser = userDetails.UserFromUserDetails(user); if (RetUser.Customer == null) { RetUser.Customer = new Customer(); } RetUser.Customer.CompanyName = userDetails.CompanyName; RetUser.UserType = UserType.Customer; return(RetUser); }
public CustomerEditView GetCustomer(string userName) { CustomerEditView cv = new CustomerEditView(); var customer = db.customers.Find(userName); cv.userName = customer.userName; cv.eMail = customer.profile.eMail; cv.firstName = customer.profile.firstName; cv.surname = customer.profile.surname; cv.birthday = customer.profile.birthday; cv.countryUser = customer.countryUser; cv.descriptionUser = customer.profile.descriptionUser; return(cv); }
// GET: Customer/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(RedirectToAction("Login", "Customer")); } userName_tmp = id; CustomerEditView customer = GetCustomer(id); if (customer == null) { return(HttpNotFound()); } return(View(customer)); }
public async Task <ActionResult> CreateCustomer(CustomerEditView model) { if (ModelState.IsValid) { PaskolUser user = model.UserFromCustomerDetails(null); user.Status = UserStatus.Active; IdentityResult res = await CreateUserAsync(user, model.Password, new string[] { UserType.Customer.ToString() }); if (res.Succeeded) { return(RedirectToAction("Index")); } } return(View()); }
public async Task <ActionResult> EditCustomer(CustomerEditView EditedCustomer) { if (ModelState.IsValid) { PaskolUser user = await UserManager.FindByIdAsync(EditedCustomer.UserID); if (user != null) { // Save artist details EditedCustomer.UserFromCustomerDetails(user); if (await UpdateUserAsync(user, EditedCustomer.Password)) { return(RedirectToAction("index")); } } else { ModelState.AddModelError("", "User Not Found"); } } return(View(EditedCustomer)); }
public ActionResult Edit(CustomerEditView model, string id) { Boolean isValid = true; ViewBag.ErrorMessageEmail = null; ViewBag.ErrorMessageFirstName = null; ViewBag.ErrorMessageSurName = null; ViewBag.ErrorMessageBirthday = null; ViewBag.ErrorMessageCountry = null; ViewBag.ErrorMessageDescription = null; if (model.eMail == null) { ViewBag.ErrorMessageEmail = "Please enter an email address."; isValid = false; } else { var customers = db.customers.Include(c => c.profile); foreach (Customer c in customers) { if (c.profile.eMail == model.eMail && c.userName != model.userName) { ViewBag.ErrorMessageEmail = "E-mail already exists."; isValid = false; } } } if (model.firstName == null || model.firstName.Length < 4 || model.firstName.Length > 30) { ViewBag.ErrorMessageFirstName = "Please enter a valid first name between 3 and 30 characters."; isValid = false; } if (model.surname == null || model.surname.Length < 4 || model.surname.Length > 30) { ViewBag.ErrorMessageSurName = "Please enter a valid surname between 3 and 30 characters."; isValid = false; } if (model.birthday == null || model.birthday.ToString() == "01.01.0001 00:00:00") { ViewBag.ErrorMessageBirthday = "Please enter a birthday."; isValid = false; } else { DateTime today = DateTime.Now; var diff = (today - model.birthday).TotalDays; if (diff < 6570) { ViewBag.ErrorMessageBirthday = "You have to be 18 Years old to register on this homepage"; isValid = false; } if (diff > 43800) { ViewBag.ErrorMessageBirthday = "Your birth date would mean you are over 120 years old. Sorry that's not possible :-)"; isValid = false; } } if (model.countryUser == null) { ViewBag.ErrorMessageCountry = "Please select a country."; isValid = false; } if (model.descriptionUser != null && model.descriptionUser.Length > 300) { ViewBag.ErrorMessageDescription = "The maximum capacity are 300 characters."; isValid = false; } if (isValid == false) { return(View("Edit", model)); } else { Profile profile = db.profiles.Find(userName_tmp); profile.eMail = model.eMail; profile.firstName = model.firstName; profile.surname = model.surname; profile.birthday = model.birthday; profile.descriptionUser = model.descriptionUser; db.Entry(profile).CurrentValues.SetValues(profile); db.SaveChanges(); Customer customer = db.customers.Find(userName_tmp); customer.countryUser = model.countryUser; db.SaveChanges(); return(RedirectToAction("Index")); } }