public ActionResult EditVendor(Users.RegisterVendorFormData EditVendor) { Users LoggedUser = Login.GetLoggedUser(); if (LoggedUser == null) { return View("NoPermission"); } if (LoggedUser.Role == Roles.Vendedor) { return View("NoPermission"); } List<Users> VendorsList = Users.ListVendors(LoggedUser).ToList(); ViewBag.Error = true; #region Validation Validation validation = new Validation(); bool error = false; string PasswordError = null; try { validation.Password(EditVendor.Password1, EditVendor.Password2, true); } catch (Exception ex) { PasswordError = ex.Message; error = true; } string EmailError = null; try { validation.ClientEmail(EditVendor.Email); } catch (Exception ex) { EmailError = ex.Message; error = true; } #endregion Validation Users vendor = VendorsList.Find(i => i.Id == EditVendor.Id); if (!error) { if (!string.IsNullOrEmpty(EditVendor.Password1)) { vendor.Password = Encryption.MD5(EditVendor.Password1); } if (!string.IsNullOrEmpty(EditVendor.Email)) { vendor.Email = EditVendor.Email; } vendor.Update(); ViewBag.SaveSuccess = "Salvo com Sucesso"; ViewBag.Error = false; } ViewBag.Vendors = VendorsList.OrderBy(i => i.Id).ToList(); ViewBag.SelectedVendor = VendorsList.Find(i => i.Id == EditVendor.Id); ViewBag.PasswordError = PasswordError; ViewBag.EmailError = (vendor.Email == EditVendor.Email) ? null : EmailError; return View("Edit", new { Id = EditVendor.Id }); }
public ActionResult Register(Users.RegisterVendorFormData vendor) { ViewBag.Saved = ""; Users LoggedUser = Login.GetLoggedUser(); if (LoggedUser == null) { return Redirect("404"); } if (LoggedUser.Role == Roles.Vendedor) { return Redirect("NoPermission"); } #region Validations Validation validation = new Validation(); bool error = false; string NameError = null; try { validation.Name(vendor.Name); } catch (Exception ex) { NameError = ex.Message; error = true; } string SurNameError = null; try { validation.Name(vendor.SurName); } catch (Exception ex) { NameError = ex.Message; error = true; } string PasswordError = null; try { validation.Password(vendor.Password1, vendor.Password2); } catch (Exception ex) { PasswordError = ex.Message; error = true; } string EmailError = null; try { validation.ClientEmail(vendor.Email); } catch (Exception ex) { EmailError = ex.Message; error = true; } string CPFCNPJError = null; try { validation.CPFnCNPJ(vendor.CPFCNPJ); } catch (Exception ex) { CPFCNPJError = ex.Message; error = true; } #endregion Validations if (!error) { Users.NewVendorFromForm(vendor, LoggedUser); ViewBag.SaveSuccess = "Salvo com Sucesso"; return View("Register"); } ViewBag.Name = vendor.Name; ViewBag.SurName = vendor.SurName; ViewBag.Email = vendor.Email; ViewBag.CPFCNPJ = vendor.CPFCNPJ; ViewBag.NameError = NameError; ViewBag.SurNameError = SurNameError; ViewBag.PasswordError = PasswordError; ViewBag.EmailError = EmailError; ViewBag.CPFCNPJError = CPFCNPJError; return View("Register"); }