public ActionResult Create([Bind(Include = "Id,ProdDepartmentId,SizeRange,IsAuth,OpBy,OpOn,AuthBy,AuthOn")] ProdSize prodSize, int?BuyerInfo, int?BrandId) { if (ModelState.IsValid) { if (prodSize.ProdDepartmentId == 0) { ModelState.AddModelError("ProdDepartmentId", "Department type cannot be empty"); } else { if (db.ProdSize.Where(x => x.ProdDepartmentId == prodSize.ProdDepartmentId && x.SizeRange == prodSize.SizeRange).Count() > 0) { Danger("Exists! Try different", true); } else { prodSize.OpBy = 1; prodSize.OpOn = DateTime.Now; db.ProdSize.Add(prodSize); db.SaveChanges(); Success("Saved successfully!", true); return(RedirectToAction("Index")); } } } ViewBag.BuyerInfo = new SelectList(db.BuyerInfo.OrderBy(x => x.Name), "Id", "Name", BuyerInfo); ViewBag.BrandId = new SelectList(db.Brand.Where(X => X.BuyerInfoId == BuyerInfo).OrderBy(x => x.Name), "Id", "Name", BrandId); ViewBag.ProdDepartmentId = new SelectList(db.ProdDepartment.Where(x => x.Brand.BuyerInfoId == BuyerInfo).OrderBy(x => x.Name), "Id", "Name", prodSize.ProdDepartmentId); return(View(prodSize)); }
public ActionResult DeleteConfirmed(int id) { ProdSize prodSize = db.ProdSize.Find(id); db.ProdSize.Remove(prodSize); db.SaveChanges(); Success("Deleted successfully!", true); return(RedirectToAction("Index")); }
// GET: ProdSize/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProdSize prodSize = db.ProdSize.Find(id); if (prodSize == null) { return(HttpNotFound()); } return(View(prodSize)); }
public async Task <List <ProductResponse> > GetProductsUserFavAsync(string UserId) { var ProdFav = await(from p in _dataContext.product join uf in _dataContext.UserFavourites on p.Id equals uf.ProductId where uf.UserId == UserId join col in _dataContext.ProductColors on p.colorId equals col.Id into ProdCol from productColor in ProdCol.DefaultIfEmpty() join size in _dataContext.ProductSizes on p.sizeId equals size.Id into ProdSize from productSize in ProdSize.DefaultIfEmpty() select new ProductResponse { Id = p.Id, ArabicName = p.ArabicName, EnglishName = p.EnglishName, ArabicDescription = p.ArabicDescription, EnglishDescription = p.EnglishDescription, Price = p.Price, SalePrice = p.SalePrice, ImgUrl = p.ImgUrl, ProductRate = string.Format("{0:0.0}", Convert.ToDecimal(_dataContext.ProductReviews.Where( x => x.ProductId == p.Id).Select(t => t.Rate).Sum()) / Convert.ToDecimal(_dataContext.ProductReviews.Where( x => x.ProductId == p.Id).Count())), productColor = productColor, productSize = productSize, productAttributes = _dataContext.ProductAttributes.Where(x => x.ProductId == p.Id) .Select(x => new ProductAttributesResponse { ArabicName = x.ArabicName, EnglishName = x.EnglishName }).ToList(), productImages = _dataContext.ProductImages.Where(x => x.ProductId == p.Id) .Select(x => new ProductImageResponse { ImgUrl = x.ImgUrl, Ext = x.Ext }) .ToList(), }).ToListAsync(); return(ProdFav); }
// GET: ProdSize/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProdSize prodSize = db.ProdSize.Find(id); if (prodSize == null) { return(HttpNotFound()); } var selectedDepartment = db.ProdDepartment.SingleOrDefault(x => x.Id == prodSize.ProdDepartmentId); ViewBag.ProdDepartment = selectedDepartment.Name; ViewBag.BuyerId = selectedDepartment.Brand.BuyerInfo.Name; return(View(prodSize)); }
// GET: ProdSize/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProdSize prodSize = db.ProdSize.Find(id); if (prodSize == null) { return(HttpNotFound()); } var selectedBuyer = db.BuyerInfo.SingleOrDefault(x => x.Id == prodSize.ProdDepartment.Brand.BuyerInfoId); ViewBag.BuyerInfoId = new SelectList(db.BuyerInfo.OrderBy(x => x.Name), "Id", "Name", selectedBuyer.Id); ViewBag.BrandId = new SelectList(db.Brand.Where(x => x.BuyerInfoId == prodSize.ProdDepartment.Brand.BuyerInfoId).OrderBy(x => x.Name), "Id", "Name", prodSize.ProdDepartment.BrandId); //ViewBag.ProdCatTypeId = new SelectList(db.ProdCatType, "Id", "Name", prodSize.ProdCatTypeId); ViewBag.ProdDepartmentId = new SelectList(db.ProdDepartment.Where(x => x.Brand.BuyerInfoId == prodSize.ProdDepartment.Brand.BuyerInfoId).OrderBy(x => x.Name), "Id", "Name", prodSize.ProdDepartmentId); return(View(prodSize)); }