public ActionResult Login(LoginViewModel l, string ReturnUrl = "") { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { var users = db.tblUsers.Where(a => a.Username == l.Username && a.Password == l.Password).FirstOrDefault(); if (users != null) { Session.Add("img", users.Photo); Session.Add("username", users.Username); FormsAuthentication.SetAuthCookie(l.Username, true); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { Session.Add("userid", users.UserId); if (users.UserRoles.Where(r => r.RoleId == 1).FirstOrDefault() != null) { return(RedirectToAction("DashBoard", "Admin")); } else { return(RedirectToAction("Index", "Home")); } } } else { ModelState.AddModelError("", "Invalid User"); } } return(View()); }
public ActionResult AddOrEdit(int id = 0) { if (id == 0) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { ViewBag.SubMenus = db.tblSubMenus.ToList(); ViewBag.Action = "Create New Item"; return(View(new ItemViewModel())); } } else { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { ViewBag.Action = "Edit Item"; ViewBag.Menus = db.tblSubMenus.ToList(); tblVehicle item = db.tblVehicles.Where(i => i.VehicleId == id).FirstOrDefault(); ItemViewModel itemvm = new ItemViewModel(); itemvm.ItemId = item.VehicleId; itemvm.SubMenuId = Convert.ToInt32(item.SubmenuId); itemvm.Title = item.Title; itemvm.Price = item.Price; itemvm.Description = item.Description; itemvm.SmallImage = item.SmallImage; itemvm.LargeImage = item.LargeImage; //HttpPostedFileBase fup = Request.Files["SmallImage"]; //if(fup!=null) //{ // if(fup.FileName!="") // { // fup.SaveAs(Server.MapPath("~/img/dogaccessories" + fup.FileName)); // } //} //HttpPostedFileBase fup1 = Request.Files["LargeImage"]; //if (fup1 != null) //{ // if (fup1.FileName != "") // { // fup1.SaveAs(Server.MapPath("~/img/dogaccessories" + fup1.FileName)); // itemvm.LargeImage = item.LargeImage; // } //} itemvm.IsAvailable = "Available"; ViewBag.SubMenus = db.tblSubMenus.ToList(); return(View(itemvm)); } } }
public ActionResult Delete(int id) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { tblSubMenu sm = db.tblSubMenus.Where(x => x.SubMenuId == id).FirstOrDefault(); db.tblSubMenus.Remove(sm); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ViewOrder_Post(int id) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { tblOrder sm = db.tblOrders.Where(x => x.OrderId == id).FirstOrDefault(); sm.DeliveredStatus = "Confirmed"; db.SaveChanges(); return(RedirectToAction("ManageOrder", "Order")); } }
public JsonResult GetData() { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { db.Configuration.LazyLoadingEnabled = false; List <SubMenuViewModel> lst = new List <SubMenuViewModel>(); var empList = db.tblSubMenus.Select(x => new { SubMenuId = x.SubMenuId, SubMenuName = x.SubMenuName }).ToList(); foreach (var item in empList) { lst.Add(new SubMenuViewModel() { SubMenuId = item.SubMenuId, SubMenuName = item.SubMenuName }); } return(Json(new { data = lst }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetData() { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { db.Configuration.LazyLoadingEnabled = false; List <UserViewModel> lstitem = new List <UserViewModel>(); var lst = db.tblUsers.ToList(); foreach (var item in lst) { lstitem.Add(new UserViewModel() { UserId = item.UserId, Username = item.Username, Photo = item.Photo }); } return(Json(new { data = lstitem }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetData() { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { db.Configuration.LazyLoadingEnabled = false; List <ItemViewModel> lstitem = new List <ItemViewModel>(); var lst = db.tblVehicles.ToList(); foreach (var item in lst) { lstitem.Add(new ItemViewModel() { ItemId = item.VehicleId, Title = item.Title, Price = item.Price, Description = item.Description, SmallImage = item.SmallImage, LargeImage = item.LargeImage, IsAvailable = item.IsAvailable }); } return(Json(new { data = lstitem }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetData() { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { db.Configuration.LazyLoadingEnabled = false; List <OrderViewModel> lstorder = new List <OrderViewModel>(); var empList = db.tblOrders.Select(x => new { OrderId = x.OrderId, Firstname = x.Firstname, Lastname = x.Lastname, Address = x.Address, Phone = x.Phone, Total = x.Total, OrderDate = x.OrderDate, DeliveredStatus = x.DeliveredStatus }).ToList(); foreach (var item in empList) { lstorder.Add(new OrderViewModel() { OrderId = item.OrderId, Firstname = item.Firstname, Lastname = item.Lastname, Address = item.Address, Phone = item.Phone, Total = item.Total.ToString(), OrderDate = item.OrderDate.ToString(), DeliveredStatus = item.DeliveredStatus }); } return(Json(new { data = lstorder }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ViewOrder(int id) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { List <OrderDetailsViewModel> lstod = new List <OrderDetailsViewModel>(); var empList = db.tblOrderDetails.Where(x => x.OrderId == id).ToList(); foreach (tblOrderDetail item in empList) { lstod.Add(new OrderDetailsViewModel() { ItemId = Convert.ToInt32(item.VehicleId), ItemName = item.tblVehicle.Title, Quantity = Convert.ToInt32(item.Quantity), UnitPrice = Convert.ToDecimal(item.UnitPrice) }); } Session.Add("itemlist", lstod); Session.Add("orderid", id); return(View(lstod)); } }
public ActionResult AddOrEdit(tblSubMenu sm) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { if (sm.SubMenuId == 0) { db.tblSubMenus.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 AddOrEdit(int id = 0) { if (id == 0) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { // ViewBag.Menus = db.tblMenus.ToList(); return(View(new tblSubMenu())); } } else { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { // ViewBag.Menus = db.tblMenus.ToList(); return(View(db.tblSubMenus.Where(x => x.SubMenuId == id).FirstOrDefault())); } } }
public ActionResult AddOrEdit(SubMenuViewModel sm) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { if (sm.SubMenuId == 0) { tblSubMenu tb = new tblSubMenu(); tb.SubMenuName = sm.SubMenuName; db.tblSubMenus.Add(tb); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { tblSubMenu tbm = db.tblSubMenus.Where(m => m.SubMenuId == sm.SubMenuId).FirstOrDefault(); tbm.SubMenuName = sm.SubMenuName; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult AddOrEdit(int id = 0) { if (id == 0) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { return(View(new SubMenuViewModel())); } } else { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { SubMenuViewModel sub = new SubMenuViewModel(); var menu = db.tblSubMenus.Where(x => x.SubMenuId == id).FirstOrDefault(); sub.SubMenuId = menu.SubMenuId; sub.SubMenuName = menu.SubMenuName; return(View(sub)); } } }
public ActionResult AddOrEdit(ItemViewModel ivm) { using (OnlineVehicleDBEntities db = new OnlineVehicleDBEntities()) { if (ivm.ItemId == 0) { tblVehicle itm = new tblVehicle(); itm.SubmenuId = Convert.ToInt32(ivm.SubMenuId); itm.Title = ivm.Title; itm.Price = ivm.Price; itm.Description = ivm.Description; HttpPostedFileBase fup = Request.Files["SmallImage"]; if (fup != null) { if (fup.FileName != "") { fup.SaveAs(Server.MapPath("~/images/ItemImages/" + fup.FileName)); itm.SmallImage = fup.FileName; } } HttpPostedFileBase fup1 = Request.Files["LargeImage"]; if (fup1 != null) { if (fup1.FileName != "") { fup1.SaveAs(Server.MapPath("~/images/ItemImages/" + fup1.FileName)); itm.LargeImage = fup1.FileName; } } itm.IsAvailable = "Available"; db.tblVehicles.Add(itm); db.SaveChanges(); ViewBag.Message = "Updated Successfully"; } else { tblVehicle itm = db.tblVehicles.Where(i => i.VehicleId == ivm.ItemId).FirstOrDefault(); itm.SubmenuId = Convert.ToInt32(ivm.SubMenuId); itm.Title = ivm.Title; itm.Price = ivm.Price; itm.Description = ivm.Description; HttpPostedFileBase fup = Request.Files["SmallImage"]; if (fup != null) { if (fup.FileName != "") { fup.SaveAs(Server.MapPath("~/images/ItemImages/" + fup.FileName)); itm.SmallImage = fup.FileName; } } HttpPostedFileBase fup1 = Request.Files["LargeImage"]; if (fup1 != null) { if (fup1.FileName != "") { fup1.SaveAs(Server.MapPath("~/images/ItemImages/" + fup1.FileName)); itm.LargeImage = fup1.FileName; } } db.SaveChanges(); ViewBag.Message = "Updated Successfully"; } ViewBag.SubMenus = db.tblSubMenus.ToList(); return(View(new ItemViewModel())); } }