public async Task <ActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { //Check if user exists var isUserExists = _db.AppUsers.Any(x => x.Email == model.Email); if (isUserExists) { ModelState.AddModelError("Duplicate Email", "Email is already registered with us."); return(View(model)); } //Register user var newUser = new AppUser() { FullName = model.Fullname, Email = model.Email, MobileNo = model.MobileNo, UserPassword = model.Password }; _db.AppUsers.Add(newUser); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Login))); } return(View(model)); }
public async Task <ActionResult> Create(ProductModel model) { if (ModelState.IsValid) { var product = new Product() { Price = model.Price, ProductName = model.Name }; if (model != null) { using (var ms = new MemoryStream()) { await model.Image.InputStream.CopyToAsync(ms); product.ProductImage = ms.ToArray(); } } _db.Products.Add(product); await _db.SaveChangesAsync(); } return(View(model)); }