public async Task<ActionResult> Create(AgentEditModel model) { if (ModelState.IsValid) { var agent = _agentModelConverter.ConvertToSource(model); var pwd = Membership.GeneratePassword(8, 2); var roles = new List<ApplicationRole> { _agentViewRepository.MapTypeToRole(model.Type), ApplicationRole.Agent }; var result = await _membershipService.CreateAsync(agent,roles, pwd); if (result.Succeeded) { _mailService.SendEmailMessage("AgentCreated", new { Name = model.ProfileDetails.FullName, model.UserName, Password = pwd, }, model.Email, Constants.VanityMail, "Welcome to MyVanity", null); return RedirectToAction("Index"); } AddErrors(result); } return View(model); }
public Agent ConvertToSource(AgentEditModel model) { var agent = model.Id != 0 ? _unitOfWork.GetRepository<Agent>().FindById(model.Id) : new Agent(); var profile = _profileModelConverter.ConvertToSource(model.ProfileDetails); agent.PersonDetails = profile; agent = ModelConverterHelper.CopyObjectProperties(model, agent); return agent; }
public ActionResult Edit(AgentEditModel model) { if (ModelState.IsValid) { _agentViewRepository.Update(model); return RedirectToAction("Index"); } return View(model); }