public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var customer = new Customer { Firstname = model.Firstname, Lastname = model.Lastname, BillingAdress = model.BillingAdress, BillingCity = model.BillingCity, BillingZip = model.BillingZip, DeliveryAdress = model.DeliveryAdress, DeliveryCity = model.DeliveryCity, DeliveryZip = model.DeliveryZip, EmailAdress = model.Email, PhoneNumber = model.PhoneNumber }; WebShopMobileDb Db = new WebShopMobileDb(); Db.Customers.Add(customer); Db.SaveChanges(); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
// GET: Pdf public ActionResult Receipt(int orderId, string payment, float total) { WebShopMobileDb Db = new WebShopMobileDb(); var user = User.Identity.Name; var model = Methods.FindCartOrder(user); var customer = Db.Customers.FirstOrDefault(x => x.EmailAdress == user); var model2 = Db.Orders.FirstOrDefault(x => x.Id == model.Id); model2.Processed = true; Db.SaveChanges(); model.OrderDate = DateTime.Now.ToShortDateString(); var reciept = new RecieptViewModel(model, customer, payment, total); return(Pdf(reciept)); }
public ActionResult EditUser(UserViewModel userView) { var user = AppDb.Users.FirstOrDefault(x => x.Email == userView.Email); var customer = Db.Customers.FirstOrDefault(x => x.EmailAdress == userView.Email); user.Email = userView.Email; customer.EmailAdress = userView.Email; user.EmailConfirmed = userView.EmailConfirmed; user.PhoneNumber = userView.PhoneNumber; customer.PhoneNumber = userView.PhoneNumber; user.PhoneNumberConfirmed = userView.PhoneNumberConfirmed; customer.Firstname = userView.Firstname; customer.Lastname = userView.Lastname; customer.BillingAdress = userView.BillingAdress; customer.BillingCity = userView.BillingCity; customer.BillingZip = userView.BillingZip; customer.DeliveryAdress = userView.DeliveryAdress; customer.DeliveryCity = userView.DeliveryCity; customer.DeliveryZip = userView.DeliveryZip; user.LockoutEnabled = userView.LockoutEnabled; if (userView.UserRoles != null) { foreach (var item in userView.UserRoles) { var roleId = AppDb.Roles.FirstOrDefault(x => x.Name == item).Id; var role = user.Roles.FirstOrDefault(x => x.RoleId == roleId); user.Roles.Remove(role); } } AppDb.SaveChanges(); Db.SaveChanges(); return(RedirectToAction("AllUsers")); }
public ActionResult RemoveFromCart(int cellId, int orderId) { var model = Db.Orders.Include("OrderRows").FirstOrDefault(x => x.Id == orderId); var cell = model.OrderRows.FirstOrDefault(x => x.Id == cellId); model.OrderRows.Remove(cell); Db.OrderRows.Remove(cell); if (model.OrderRows.Count == 0) { Db.Orders.Remove(model); } Db.SaveChanges(); if (Request.IsAjaxRequest()) { return(RedirectToAction("Cart", new { remove = true })); } return(RedirectToAction("Cart")); }