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) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); var InfoToAdd = new AccountInfoModels(); InfoToAdd.AccountId = user.Id; InfoToAdd.Email = user.Email; db.AccountInfoModels.Add(InfoToAdd); db.SaveChanges(); // 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)); }
public async System.Threading.Tasks.Task <ActionResult> CreateAsync([Bind(Include = "Id,Email,Name,Class")] StudentModels studentModels) { if (ModelState.IsValid) { db.StudentModels.Add(studentModels); db.SaveChanges(); var user = new ApplicationUser { UserName = studentModels.Email, Email = studentModels.Email }; var result = await UserManager.CreateAsync(user, "Divine123!"); if (result.Succeeded) { var InfoToAdd = new AccountInfoModels(); InfoToAdd.AccountId = user.Id; InfoToAdd.Email = user.Email; InfoToAdd.Name = studentModels.Name; InfoToAdd.Role = "Student"; await UserManager.AddToRoleAsync(user.Id, "Student"); db.AccountInfoModels.Add(InfoToAdd); db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(studentModels)); }
public ActionResult DeleteConfirmed(int id) { StudentModels studentModels = db.StudentModels.Find(id); AccountInfoModels accountInfoModels = db.AccountInfoModels.Where(s => s.Email == studentModels.Email).SingleOrDefault(); db.AccountInfoModels.Remove(accountInfoModels); db.StudentModels.Remove(studentModels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Index(int Id, string Name, string Address, string CNP) { AccountInfoModels accountInfoModels = db.AccountInfoModels.Find(Id); if (accountInfoModels != null) { accountInfoModels.Name = Name; accountInfoModels.Address = Address; accountInfoModels.CNP = CNP; db.SaveChanges(); } string redirectUrl = "/Manage"; return(Redirect(redirectUrl)); }
public ActionResult Index(int Id, string Name, string Phone, string Address, string City, string State) { AccountInfoModels accountInfoModels = db.AccountInfoModels.Find(Id); if (accountInfoModels != null) { accountInfoModels.Name = Name; accountInfoModels.Phone = Phone; accountInfoModels.Address = Address; accountInfoModels.City = City; accountInfoModels.State = State; db.SaveChanges(); } string redirectUrl = "/Manage"; return(Redirect(redirectUrl)); }
public ActionResult PlaceOrder(int id) { string Name = User.Identity.GetUserName(); var result = db.CartModels.Find(id); AccountInfoModels accountInfoModels = db.AccountInfoModels.Where(s => s.Email == Name).FirstOrDefault(); if (accountInfoModels.Phone == null) { string redirectUrl = "/Manage/Index"; return(Redirect(redirectUrl)); } else { if (result != null) { var productToCart = db.ProductsChartModels.Where(b => b.CartId == id).ToList(); var userOrder = new OrderModels(); userOrder.AccountId = " "; userOrder.Email = Name; userOrder.TotalAmount = result.TotalAmount; userOrder.NumberOfProducts = result.NumberOfProducts; userOrder.Name = accountInfoModels.Name; userOrder.Address = accountInfoModels.Address; userOrder.City = accountInfoModels.City; userOrder.State = accountInfoModels.State; userOrder.Phone = accountInfoModels.Phone; db.OrderModels.Add(userOrder); db.SaveChanges(); var userOrderAftePlacement = db.OrderModels.Where(b => b.Email == Name).Where(b => b.Name == accountInfoModels.Name).OrderByDescending(s => s.Id).Take(1).FirstOrDefault(); foreach (var item in productToCart) { var product = db.ProductsModels.Find(item.ProductId); var productToOrder = new ProductOrderModels(); productToOrder.CartId = userOrderAftePlacement.Id; productToOrder.ProductId = product.Id; db.ProductOrderModels.Add(productToOrder); db.SaveChanges(); product.Stock = product.Stock - 1; db.ProductsChartModels.Remove(item); db.SaveChanges(); } result.TotalAmount = 0; result.NumberOfProducts = 0; db.SaveChanges(); } } string redirectUrl1 = "/Cart/Index"; return(Redirect(redirectUrl1)); }