Example #1
0
        public ActionResult BasketRemoveProduct(SHOP_PRODS product)
        {
            ViewBag.Title    = "Basket Contents";
            ViewBag.Message  = "Basket page";
            ViewBag.Selected = "basket";
            ViewBag.LoggedIn = ControllerContext.HttpContext.User.Identity.IsAuthenticated;

            var model = (IList <SHOP_PRODS>)System.Web.HttpContext.Current.Session["ShoppingBasket"];

            if (model != null)
            {
                if (product != null)
                {
                    var prod = model.SingleOrDefault(p => p.prodId == product.prodId);
                    model.Remove(prod);
                    System.Web.HttpContext.Current.Session["ShoppingBasket"] = model;
                }
            }
            else
            {
                model = new List <SHOP_PRODS>();
                System.Web.HttpContext.Current.Session["ShoppingBasket"] = model;
            }
            return(RedirectToAction("Basket"));
        }
Example #2
0
 public void DeleteProduct(SHOP_PRODS shopProd)
 {
     using (var dbContext = new DataAccess.TeachersAssistantDbContext())
     {
         _unitOfWork.InitializeDbContext(dbContext);
         var product = _unitOfWork._bookingTimeRepository.DbContextTeachersAssistant.ShopProducts.SingleOrDefault(p => p.prodId == shopProd.prodId);
         if (product != null)
         {
             _unitOfWork._bookingTimeRepository.DbContextTeachersAssistant.ShopProducts.Remove(product);
             _unitOfWork.SaveChanges();
         }
     }
 }
        public ViewResult ManageProducts(ProductViewModel productModel)
        {
            var products = _repositoryServices.GetProductsList();

            ViewBag.ProductIdsList = GetProductList();

            if (productModel.Select != null)
            {
                if (productModel.ProductId < 1)
                {
                    ModelState.AddModelError("ProductId", "Product Id Required");
                }
                if (ModelState.IsValid)
                {
                    ModelState.Clear();
                    var prod = _repositoryServices.GetProductById(productModel.ProductId);
                    productModel = Mapper.Map(prod, typeof(SHOP_PRODS), typeof(ProductViewModel)) as ProductViewModel;
                    productModel.DocumentType = prod.IsPaidDocument ? 0 : prod.IsPaidVideo ? 1 : -1;
                    return(View("ManageProducts", productModel));
                }

                return(View("ManageProducts", productModel));
            }

            if (ModelState.IsValid)
            {
                var shopProd = new SHOP_PRODS
                {
                    prodName   = productModel.ProductName,
                    prodDesc   = productModel.ProductDescription,
                    prodPrice  = productModel.ProductPrice,
                    prodId     = productModel.ProductId,
                    DocumentId = productModel.DocumentId
                };

                if (productModel.Delete != null)
                {
                    _repositoryServices.DeleteProduct(shopProd);
                    return(View("SuccessfullCreation"));
                }
                if (shopProd != null && productModel.DocumentType != -1)
                {
                    shopProd.IsPaidDocument = productModel.DocumentType == 0;
                    shopProd.IsPaidVideo    = productModel.DocumentType == 1;
                }
                _repositoryServices.SaveOrUpdate(shopProd);
                return(View("SuccessfullCreation"));
            }
            return(View("ManageProducts", productModel));
        }
Example #4
0
 public void SaveOrUpdate(SHOP_PRODS shopProd)
 {
     using (var dbContext = new DataAccess.TeachersAssistantDbContext())
     {
         _unitOfWork.InitializeDbContext(dbContext);
         var product = _unitOfWork._bookingTimeRepository.DbContextTeachersAssistant.ShopProducts.SingleOrDefault(p => p.prodId == shopProd.prodId);
         if (product == null)
         {
             _unitOfWork._bookingTimeRepository.DbContextTeachersAssistant.ShopProducts.Add(shopProd);
         }
         else
         {
             product.prodName       = shopProd.prodName;
             product.prodPrice      = shopProd.prodPrice;
             product.prodDesc       = shopProd.prodDesc;
             product.IsPaidVideo    = shopProd.IsPaidVideo;
             product.IsPaidDocument = shopProd.IsPaidDocument;
             product.DocumentId     = shopProd.DocumentId;
         }
         _unitOfWork.SaveChanges();
     }
 }