public ActionResult RegisterNewBuyer(BuyerRegistrationViewModel postModel) { if (ModelState.IsValid) { Mapper.CreateMap <BuyerRegistrationViewModel, Buyer>(); Mapper.CreateMap <BuyerRegistrationViewModel, User>(); Buyer buyer = Mapper.Map <BuyerRegistrationViewModel, Buyer>(postModel); User user = Mapper.Map <BuyerRegistrationViewModel, User>(postModel); UserComponent userComponent = new UserComponent(); ValidationResults vResult = userComponent.CreateUser(user); postModel.ValidationResult = vResult; if (vResult.Success == true) { BuyerComponent buyerComponent = new BuyerComponent(); vResult = buyerComponent.RegisterNewBuyer(buyer); postModel.ValidationResult = vResult; } } else { ListComponent lstComponent = new ListComponent(); postModel.Countries = lstComponent.GetListItemsById("Country"); postModel.Cities = lstComponent.GetListItemsById("City"); postModel.AreBothAddressSameOptions = lstComponent.GetListItemsById("YesOrNo"); } return(View("RegisterNewBuyer", postModel)); }
public ActionResult RegisterNewBuyerGet() { var viewModel = new BuyerRegistrationViewModel(); ListComponent lstComponent = new ListComponent(); viewModel.Countries = lstComponent.GetListItemsById("Country"); viewModel.Cities = lstComponent.GetListItemsById("City"); viewModel.AreBothAddressSameOptions = lstComponent.GetListItemsById("YesOrNo"); return(View("RegisterNewBuyer", viewModel)); }
public ActionResult BuyerRegistration(BuyerRegistrationViewModel buyerModel) { if (ModelState.IsValid) { Buyer buyer = new Buyer() { FirstName = buyerModel.FirstName, LastName = buyerModel.LastName, Gender = buyerModel.Gender, Email = buyerModel.Email, Phone = buyerModel.Phone, Address = buyerModel.Address, AreaId = Convert.ToInt32(buyerModel.AreaId) }; if (buyerService.Insert(buyer) == 1) { buyer.Id = buyerService.GetLastBuyerId(buyer); BuyerCredential credential = new BuyerCredential() { Username = buyerModel.Username, Password = buyerModel.Password, BuyerId = buyer.Id, Status = true }; if (buyerCredentialService.Insert(credential) == 1) { return(RedirectToAction("Index", "Login", new { id = 1 })); } else { return(View("Error")); } } else { return(View("Error")); } } else { return(View(buyerModel)); } }