public ActionResult Create(Product product) { using (var db = new ClassifyEntities()) { if (product.ProductImg != null) { product.Image = getimage(product); string path1 = "~/images/Productimages/"; var filename1 = Path.Combine(Server.MapPath(path1), product.Image); product.ProductImg.SaveAs(filename1); } product.Createddate = DateTime.Now; product.UserId = Convert.ToInt32(Session["UserId"]); db.Products.Add(product); if (db.SaveChanges() > 0) { TempData["Successmessage"] = "Product added successfully"; return(RedirectToAction("Index")); } else { ViewBag.Category2 = new SelectList(db.Categorymasters.ToList(), "Id", "Categoryname"); return(View(product)); } } }
public ActionResult Login(User user) { using (var Db = new ClassifyEntities()) { if (Db.Users.Any(x => x.Email == user.Email)) { user.Password = Crypto.Hash(user.Password, "MD5"); if (Db.Users.Any(x => x.Email == user.Email && x.Password == user.Password)) { var Userdata = Db.Users.Where(x => x.Email == user.Email && x.Password == user.Password).First(); if (Userdata.IsVerified == true && Userdata.IsActive == true) { Session["Name"] = Userdata.Firstname + " " + Userdata.Lastname; Session["UserId"] = Userdata.Id; return(RedirectToAction("Index", "Home")); } return(RedirectToAction("VerifyYourAccount")); } TempData["Error"] = "Incorrect password"; return(View(user)); } TempData["Error"] = "User is not Exist"; return(View(user)); } }
public ActionResult Edit(Userviewmodel userviewmodel) { if (ModelState.IsValid) { using (var db = new ClassifyEntities()) { if (db.Users.Any(x => x.Id == userviewmodel.Id)) { var status = UserUpdate(userviewmodel); if (status) { TempData["Successmessage"] = "Profile Successfully Updated"; return(RedirectToAction("UserProfile")); } TempData["Error"] = "Some thing went wrong"; return(View(User)); } else { Session.Abandon(); return(RedirectToAction("Login")); } } } return(View(User)); }
public ActionResult GetVerified(string tokken) { if (tokken == null && tokken.Length > 0) { TempData["Error"] = "Something WentWrong Please try after sometime"; return(RedirectToAction("VerifyYourAccount")); } using (var db = new ClassifyEntities()) { var base64EncodedBytes = System.Convert.FromBase64String(tokken); var original = System.Text.Encoding.ASCII.GetString(base64EncodedBytes); var data = original.Split(':'); var Email = data[0]; if (db.Users.Any(x => x.Email == Email && x.VerificationTokken == tokken)) { var User = db.Users.Single(x => x.Email == Email); if (User.IsVerified == true && User.IsActive == true) { return(RedirectToAction("Login")); } User.IsVerified = true; User.IsActive = true; db.Users.Attach(User); db.Entry(User).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["VerificationDone"] = "Your Account Successfully Verified"; return(RedirectToAction("Login")); } else { return(HttpNotFound()); } } }
//Main Index page public ActionResult Index() { using (var db = new ClassifyEntities()) { ViewBag.Category = db.Categorymasters.ToList(); return(View(db.Products.ToList())); } }
public JsonResult GetCity(int Id) { using (var db = new ClassifyEntities()) { db.Configuration.LazyLoadingEnabled = false; return(Json(db.Citymasters.Where(x => x.Stateid == Id).ToList(), JsonRequestBehavior.AllowGet)); } }
public JsonResult GetCountry() { using (var db = new ClassifyEntities()) { db.Configuration.LazyLoadingEnabled = false; return(Json(db.Countrymasters.ToList(), JsonRequestBehavior.AllowGet)); } }
public ActionResult Create() { using (var db = new ClassifyEntities()) { Product product = new Product(); ViewBag.Category2 = new SelectList(db.Categorymasters.ToList(), "Id", "Categoryname"); return(View(product)); } }
public ActionResult UserProfile() { using (var db = new ClassifyEntities()) { db.Configuration.LazyLoadingEnabled = false; var Id = Convert.ToInt32(Session["UserId"]); return(View(db.Users.Where(x => x.Id == Id).First())); } }
public ActionResult Edit(int Id) { var db = new ClassifyEntities(); if (db.Users.Any(x => x.Id == Id)) { var User = db.Users.Where(x => x.Id == Id).First(); return(View(User)); } else { return(HttpNotFound()); } }
public ActionResult Edit(int Id) { using (var db = new ClassifyEntities()) { if (db.Products.Any(x => x.Id == Id)) { ViewBag.Category2 = new SelectList(db.Categorymasters.ToList(), "Id", "Categoryname"); return(View(db.Products.Where(x => x.Id == Id).FirstOrDefault())); } else { return(HttpNotFound()); } } }
public ActionResult Delete(int Id) { using (var db = new ClassifyEntities()) { if (db.Products.Any(x => x.Id == Id)) { db.Products.Remove(db.Products.Where(x => x.Id == Id).First()); db.SaveChanges(); TempData["Successmessage"] = "Product Deleted successfully"; return(RedirectToAction("Index")); } else { return(HttpNotFound()); } } }
public ActionResult Register(User user) { if (ModelState.IsValid) { using (var db = new ClassifyEntities()) { if (!db.Users.Any(x => x.Email == user.Email && x.Contactnumber == user.Contactnumber)) { user.Password = Crypto.Hash(user.Password, "MD5"); user.VerificationTokken = Tokkens(user); user.Createddate = DateTime.Now; user.Modifieddate = DateTime.Now; user.IsActive = true; user.IsVerified = false; SendMail(user, user.VerificationTokken); user.MailSent = true; db.Users.Add(user); try { db.SaveChanges(); TempData["Successmessage"] = "Registration Successful"; return(RedirectToAction("MailHasbeebSent")); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); raise = new InvalidOperationException(message, raise); Console.WriteLine(message); } } throw raise; } } TempData["Error"] = "Email and Contactnumber Already Exist"; return(View(user)); } } return(View(user)); }
private bool UserUpdate(Userviewmodel User) { using (var db = new ClassifyEntities()) { var Userdata = db.Users.Where(x => x.Id == User.Id).First(); Userdata.Firstname = User.Firstname; Userdata.Lastname = User.Lastname; Userdata.Modifieddate = DateTime.Now; Userdata.State = User.State; Userdata.Country = User.Country; Userdata.City = User.City; Userdata.Zipcode = User.Zipcode; db.Users.Attach(Userdata); db.Entry(Userdata).State = System.Data.Entity.EntityState.Modified; var status = db.SaveChanges() > 0 ? true : false; return(status); } }
public ActionResult DeleteMultiple(int[] MultipleDelId) { if (MultipleDelId != null && MultipleDelId.Length > 0) { using (var db = new ClassifyEntities()) { var List = new List <Product>(); for (int i = 0; i < MultipleDelId.Length; i++) { var Id = MultipleDelId[i]; db.Products.Remove(db.Products.Where(x => x.Id == Id).First()); } db.SaveChanges(); TempData["Successmessage"] = "Products successfully Deleted"; return(RedirectToAction("Index")); } } TempData["Error"] = "Can't Delete Multiple item"; return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name,Category,Code,Price,Description,Status,Discount")] Product product) { using (var db = new ClassifyEntities()) { if (product.ProductImg != null) { product.Image = getimage(product); string path1 = "~/images/Productimages/"; var filename1 = Path.Combine(Server.MapPath(path1), product.Image); product.ProductImg.SaveAs(filename1); } else { product.Image = db.Products.Where(x => x.Id == product.Id).First().Image; } var Productdata = db.Products.Where(x => x.Id == product.Id).First(); Productdata.Image = product.Image; Productdata.Name = product.Name; Productdata.Category = product.Category; Productdata.Price = product.Price; Productdata.Code = product.Code; Productdata.Description = product.Description; Productdata.Status = product.Status; Productdata.Discount = product.Discount; Productdata.ModifiedDate = DateTime.Now; db.Products.Attach(Productdata); db.Entry(Productdata).State = System.Data.Entity.EntityState.Modified; if (db.SaveChanges() > 0) { TempData["Successmessage"] = "Product Edited successfully"; return(RedirectToAction("Index")); } else { ViewBag.Category2 = new SelectList(db.Categorymasters.ToList(), "Id", "Categoryname"); return(View(product)); } } }