public ActionResult AddOrEdit(ProductViewModel ivm) { using (BhaiDBEntities db = new BhaiDBEntities()) { if (ivm.ProductId == 0) { tblProduct itm = new tblProduct(); itm.CategoryId = Convert.ToInt32(ivm.CategoryId); itm.ProductName = ivm.ProductName; itm.UnitPrice = ivm.UnitPrice; itm.SellingPrice = ivm.SellingPrice; itm.Description = ivm.Description; itm.IsSpecial = ivm.IsSpecial; HttpPostedFileBase fup = Request.Files["Photo"]; if (fup != null) { if (fup.FileName != "") { fup.SaveAs(Server.MapPath("~/UserCss/images/" + fup.FileName)); itm.Photo = fup.FileName; } } db.tblProducts.Add(itm); db.SaveChanges(); ViewBag.Message = "Created Successfully"; } else { tblProduct itm = db.tblProducts.Where(i => i.ProductId == ivm.ProductId).FirstOrDefault(); itm.CategoryId = Convert.ToInt32(ivm.CategoryId); itm.ProductName = ivm.ProductName; itm.UnitPrice = ivm.UnitPrice; itm.SellingPrice = ivm.SellingPrice; itm.Description = ivm.Description; itm.IsSpecial = ivm.IsSpecial; HttpPostedFileBase fup = Request.Files["Photo"]; if (fup != null) { if (fup.FileName != "") { fup.SaveAs(Server.MapPath("~/UserCss/images/" + fup.FileName)); itm.Photo = fup.FileName; } } db.SaveChanges(); ViewBag.Message = "Updated Successfully"; } ViewBag.Categories = db.tblCategories.ToList(); return(View(new ProductViewModel())); } }
public ActionResult AddOrEdit(tblCategory sm) { using (BhaiDBEntities db = new BhaiDBEntities()) { if (sm.CategoryId == 0) { db.tblCategories.Add(sm); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(sm).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Delete(int id) { using (BhaiDBEntities db = new BhaiDBEntities()) { tblProduct sm = db.tblProducts.Where(x => x.ProductId == id).FirstOrDefault(); db.tblProducts.Remove(sm); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddOrEdit(CategoryViewModel sm) { using (BhaiDBEntities db = new BhaiDBEntities()) { if (sm.CategoryId == 0) { tblCategory tb = new tblCategory(); tb.CategoryName = sm.CategoryName; db.tblCategories.Add(tb); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { tblCategory tbm = db.tblCategories.Where(m => m.CategoryId == sm.CategoryId).FirstOrDefault(); tbm.CategoryName = sm.CategoryName; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult ViewOrder_Post(int id) { using (BhaiDBEntities db = new BhaiDBEntities()) { tblOrder sm = db.tblOrders.Where(x => x.OrderId == id).FirstOrDefault(); sm.DeliveredStatus = "Confirmed"; db.SaveChanges(); return(RedirectToAction("ManageOrder", "Order")); } }
public ActionResult AddressAndPayment(OrderViewModel ovm) { var cart = ShoppingCart.GetCart(this.HttpContext); tblOrder tb = new tblOrder(); tb.Username = Session["username"].ToString(); tb.Firstname = ovm.Firstname; tb.Lastname = ovm.Lastname; tb.Address = ovm.Address; tb.Phone = ovm.Phone; tb.Total = cart.GetTotal(); tb.OrderDate = Convert.ToDateTime(DateTime.Today.ToShortDateString()); tb.DeliveredStatus = "Pending"; storeDB.tblOrders.Add(tb); storeDB.SaveChanges(); List <tblCart> lst = cart.GetCartItems(); foreach (var item in lst) { tblOrderDetail tbord = new tblOrderDetail(); tbord.OrderId = tb.OrderId; tbord.ProductId = item.ProductId; tbord.Quantity = item.Count; tbord.UnitPrice = item.tblProduct.UnitPrice; storeDB.tblOrderDetails.Add(tbord); storeDB.SaveChanges(); } ViewBag.Message = "Your Ordered Done Successfully, It Takes 2/3 Hours In Our working Days"; return(View()); }
public ActionResult Signup(UserViewModel uv) { tblUser tbl = db.tblUsers.Where(u => u.Username == uv.Username).FirstOrDefault(); if (tbl != null) { return(Json(new { success = false, message = "User Already Registerd" }, JsonRequestBehavior.AllowGet)); } else { tblUser tb = new tblUser(); tb.Username = uv.Username; tb.Password = uv.Password; db.tblUsers.Add(tb); db.SaveChanges(); tblUserRole ud = new tblUserRole(); ud.UserId = tb.UserId; ud.UserRoleId = 1003; db.tblUserRoles.Add(ud); db.SaveChanges(); return(Json(new { success = true, message = "User Registered Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ChangePassword(ChangePasswordViewModel ch) { string username = Session["username"].ToString(); tblUser us = db.tblUsers.Where(u => u.Username == username && u.Password == ch.OldPassword).FirstOrDefault(); if (us != null) { us.Password = ch.NewPassword; db.SaveChanges(); } else { return(Json(new { success = false, message = "You Enter Wrong Password" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = true, message = "Password Changed Successfully" }, JsonRequestBehavior.AllowGet)); }