// GET: Order public ActionResult Index() { CategoryAndProduct catAndProduct = new CategoryAndProduct(); catAndProduct.categories = db.Categories.ToList(); return(View(catAndProduct)); }
public ActionResult GetProduct(int data) { CategoryAndProduct prod = new CategoryAndProduct(); prod.products = db.Products.Where(x => x.SubCatId == data).ToList(); return(PartialView("_GetProduct", prod)); }
// [HttpGet] public ActionResult GetSubCategory(int data) { CategoryAndProduct subcat = new CategoryAndProduct(); subcat.subCategories = db.SubCategories.Where(x => x.CatId == data).ToList(); return(PartialView("_GetSubCategory", subcat)); }
public JsonResult SaveOrder(CategoryAndProduct cp) { bool status = false; using (RotanaContext dc = new RotanaContext()) { Order order = new Order { UserId = cp.UserId, OrderDate = cp.OrderDate, CustomerName = cp.CustomerName, Address = cp.Address, City = cp.City, PhoneNumber = cp.PhoneNumber }; foreach (var i in cp.OrderProducts) { /*OrderProduct orderp = new OrderProduct * { * OrderId = i.OrderId, * ProductId = i.ProductId, * ProductName = i.ProductName, * UnitPrice = i.UnitPrice, * UnitQuantity = i.UnitQuantity * * }; * dc.OrderProducts.Add(orderp); * dc.SaveChanges();*/ order.OrderProducts.Add(i); } dc.Orders.Add(order); dc.SaveChanges(); /*int id = order.Id; * foreach (var i in cp.OrderProducts) * { * OrderProduct orderp = new OrderProduct * { * OrderId = order.Id, * ProductId = i.ProductId, * ProductName = i.ProductName, * UnitPrice = i.UnitPrice, * UnitQuantity = i.UnitQuantity * * }; * dc.OrderProducts.Add(orderp); * dc.SaveChanges(); * * }*/ status = true; } return(new JsonResult { Data = new { status = status } }); }
public ActionResult SubmitCreateNewItem(string name, string about, int producerVal, int colorVal, List <int> categoryVal, int?multiCategoryVal, decimal size, decimal price, decimal discountPrice, List <HttpPostedFileBase> imgFiles) { if (categoryVal == null && multiCategoryVal == null) { TempData["emptyCategory"] = "Məhsulun Kategoriyasını daxil edin!!"; return(View("CreateNewItem")); } if (string.IsNullOrWhiteSpace(name)) { TempData["emptyNameInput"] = "Məhsulun adını daxil edin"; return(View("CreateNewItem")); } if (imgFiles[0] != null && (categoryVal != null || multiCategoryVal != 0)) { bool findUser = false; Manager findSuperAdmin = new Manager(); Manager findAdmin = new Manager(); var newProduct = new Product(); newProduct.Name = name; newProduct.About = about; newProduct.ProducerId = producerVal; newProduct.colorId = colorVal; newProduct.SizeORCount = size; newProduct.Price = price; newProduct.DiscountPrice = discountPrice; if (multiCategoryVal != null) { var findMultiCategory = db.SubCategories.Where(w => w.DeletedDate == null && w.Id == multiCategoryVal).FirstOrDefault(); newProduct.SubCategory = findMultiCategory.SubCategoryName; } newProduct.isWaitListForAdmin = true; var checkAdmin = db.Manager.Where(w => w.DeletedDate == null && w.ManagerStatus.DeletedDate == null && w.ManagerStatus.StatusName == "SuperAdmin").ToList(); foreach (var item in checkAdmin) { if (Session[SessionKey.Admin].ToString() == item.Email) { findSuperAdmin = item; findUser = true; } } if (findUser == true) { newProduct.CreatedId = findSuperAdmin.Id; newProduct.SharedId = findSuperAdmin.Id; newProduct.isConfirm = true; newProduct.sharedDate = DateTime.Now; var subscribeUsers = db.Subscribes.Where(w => w.DeletedDate == null && w.isConfirm == true).ToList(); foreach (var user in subscribeUsers) { MailExtention.SendMail("Yeni Məhsul", newProduct.Name + " " + newProduct.Price + "AZN", user.Email); } } else { var checkSession = Session[SessionKey.Admin]; var findActiveAdmin = db.Manager.Where(w => w.DeletedDate == null && w.Email.ToString() == checkSession.ToString()).FirstOrDefault(); newProduct.isConfirm = false; newProduct.SharedId = findActiveAdmin.Id; } newProduct.CreatedDate = DateTime.Now; newProduct.imgPath = imgFiles.FirstOrDefault().FileName; db.products.Add(newProduct); foreach (var categoryItem in categoryVal) { var newCategoryAndProduct = new CategoryAndProduct(); newCategoryAndProduct.CategoryId = categoryItem; newCategoryAndProduct.ProductId = newProduct.Id; db.CategoryAndProduct.Add(newCategoryAndProduct); } string SaveLocation = ""; foreach (var file in imgFiles) { string fileName = Path.GetFileName(file.FileName); SaveLocation = Server.MapPath("~/Template/img/newImg/") + "\\" + fileName; try { var newImgPath = new imageProduct(); newImgPath.ProductId = newProduct.Id; newImgPath.imgPath = fileName; newImgPath.CreatedDate = DateTime.Now; db.imageProducts.Add(newImgPath); db.SaveChanges(); file.SaveAs(SaveLocation); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } db.SaveChanges(); var newProductOrWaitList = db.products.OrderByDescending(o => o.Id).Where(p => p.DeletedDate == null && (p.isWaitListForAdmin == true && p.isConfirm == false)); return(PartialView("~/Areas/AdGetOn/Views/Admin/newAddProduct.cshtml", newProductOrWaitList)); } else { TempData["imgIsEmpty"] = "Şəkil Seçin !!"; return(View("CreateNewItem")); } }