public ActionResult CriarConta() { MinhaContaPageModel pageModel = new MinhaContaPageModel(); this.BindBasePageModel(pageModel); pageModel.User = new User(); pageModel.User.Email = Request.QueryString["Email"]; return View("../CustomCode/VICommerce/" + EcommerceContext.AccountDomain + "/MinhaConta", pageModel); }
public ActionResult MinhaContaPost(MinhaContaPageModel model) { string extendedProperties = Request.QueryString["ep"]; User newUser = null; bool isUpdate = false; if (!string.IsNullOrEmpty(base.EcommerceContext.LoggedUserId)) { if (!string.IsNullOrEmpty(this.EcommerceContext.LoggedUserId)) { newUser = customerAPIClient.GetLoggedCustomerById(this.EcommerceContext.LoggedUserId); } isUpdate = true; } else { newUser = model.User; } if (isUpdate) { if (model.ShippingAddress != null) { newUser.Addresses = new List<Address>(); newUser.Addresses.Add(model.ShippingAddress); newUser.Addresses[0].MainAddress = true; } newUser.FirstName = model.User.FirstName; newUser.LastName = model.User.LastName; newUser.Birthdate = model.User.Birthdate; newUser.DocumentNumber = model.User.DocumentNumber; newUser.DocumentNumber2 = model.User.DocumentNumber2; newUser.Gender = model.User.Gender; newUser.MobilePhone = model.User.MobilePhone; newUser.Newsletter = model.User.Newsletter; newUser.NewsletterSMS = model.User.NewsletterSMS; newUser.PhoneNumber1 = model.User.PhoneNumber1; newUser.PhoneNumber2 = model.User.PhoneNumber2; customerAPIClient.UpdateLoggedCustomer(newUser); //account updated return RedirectToAction("MinhaConta"); } else { newUser.ExtendedProperties = new Dictionary<string, object>(); if (!String.IsNullOrEmpty(extendedProperties)) { foreach (string p in extendedProperties.Split(',')) { string[] nameAndValue = p.Split(':'); string name = nameAndValue[0]; string value = nameAndValue[1]; newUser.ExtendedProperties.Add(name, value); } } try { newUser.Username = model.User.Email; if (string.IsNullOrEmpty(newUser.FirstName) && string.IsNullOrEmpty(newUser.LastName)) { if (model.User.Email != null) { //pega valor até o @ do email informado string str = model.User.Email; int index = str.IndexOf('@'); string sub; if (index >= 0) { sub = str.Substring(0, index); } else { throw new ApplicationException("Email informado em formato inválido."); } newUser.FirstName = sub; } } var u = customerAPIClient.CreateCustomer(newUser); string access_token = base.authorizationClient.GetPasswordToken(newUser, EcommerceContext.AccountId, EcommerceContext.AccountToken); this.LoggedUserAccessTokenInContext = access_token; //FormsAuthentication.SetAuthCookie(access_token, true); //account created //return RedirectToAction("MinhaConta"); } catch (Exception ex) { this.BindBasePageModel(model); ViewBag.Error = ex.Message; return View("../CustomCode/VICommerce/" + EcommerceContext.AccountDomain + "/MinhaConta", model); } if (!string.IsNullOrEmpty(Request.QueryString["redirect"])) { var retorno = Request.QueryString["redirect"]; return Redirect(retorno); } return RedirectToAction("MinhaConta"); } }
public ActionResult MinhaConta() { MinhaContaPageModel pageModel = new MinhaContaPageModel(); this.BindBasePageModel(pageModel); if (!string.IsNullOrEmpty(this.EcommerceContext.LoggedUserId)) { pageModel.User = customerAPIClient.GetLoggedCustomerById(this.EcommerceContext.LoggedUserId); if ((pageModel.User.Addresses != null) && (pageModel.User.Addresses.Count > 0)) { pageModel.ShippingAddress = pageModel.User.Addresses.Where(o => o.MainAddress).FirstOrDefault(); } } else { pageModel.User = new User(); pageModel.User.Email = Request.QueryString["Username"]; } //else //{ // return RedirectToAction("Login"); //throw new ApplicationException("Voce precisa estar logado"); //} return View("../CustomCode/VICommerce/" + EcommerceContext.AccountDomain + "/MinhaConta", pageModel); }