public virtual ActionResult Create(ForwarderModel model) { if(string.IsNullOrWhiteSpace(model.Authentication.NewPassword)) ModelState.AddModelError("NewPassword", Validation.EmplyPassword); if(!ModelState.IsValid) { BindBag(); return View(); } try { var id = _forwarders.Add(model.Name, model.Authentication.Login, model.Authentication.NewPassword, model.Email, _identity.Language); _forwarders.SetCities(id, model.Cities); return RedirectToAction(MVC.ForwarderUser.Edit(id)); } catch(DublicateLoginException) { ModelState.AddModelError("Authentication.Login", Validation.LoginExists); BindBag(); return View(); } }
public virtual ActionResult Edit(long id, ForwarderModel model) { if(!ModelState.IsValid) { BindBag(); return View(); } try { _forwarders.Update(id, model.Name, model.Authentication.Login, model.Email); _forwarders.SetCities(id, model.Cities); if(!string.IsNullOrWhiteSpace(model.Authentication.NewPassword)) { var data = _forwarders.Get(id); _users.SetPassword(data.UserId, model.Authentication.NewPassword); } return RedirectToAction(MVC.ForwarderUser.Edit(id)); } catch(DublicateLoginException) { ModelState.AddModelError("Authentication.Login", Validation.LoginExists); BindBag(); return View(); } }
public virtual ViewResult Edit(long id) { BindBag(); var data = _forwarders.Get(id); var model = new ForwarderModel { Authentication = new AuthenticationModel(data.Login), Email = data.Email, Cities = _forwarders.GetCities(id), Name = data.Name }; return View(model); }