コード例 #1
0
        public async Task <JsonResult> AddProduct(VmProduct product)
        {
            var ret        = new VM_JsonOnlyResult();
            var modelState = (new VmProductValidator()).Validate(product);

            if (!modelState.IsValid)
            {
                ret.Value = -1001;
                ret.Err   = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage));
                return(await Task.FromResult(Json(ret)));
            }

            m_ProductService.PreOnAddHandler =
                () => !m_ProductService.ProductIsExists(product.NagigatedDomainObject.Name);
            var added = await m_ProductService.AddObject(product.NagigatedDomainObject, true);

            if (added == AppServiceExecuteStatus.Success)
            {
                ret.Value  = product.NagigatedDomainObject.ID;
                ret.Result = true;
                return(Json(ret));
            }

            ret.Err = added.ToDescription();
            return(Json(ret));
        }
コード例 #2
0
ファイル: BLProduct.cs プロジェクト: amirrezabarin/WERC
        public int CreateProduct(VmProduct vmProduct)
        {
            var result = -1;

            try
            {
                var productRepository = UnitOfWork.GetRepository <ProductRepository>();

                var newProduct = new Product
                {
                    ShopOrderId   = vmProduct.ShopOrderId,
                    ShopProductId = vmProduct.ShopProductId,
                };

                productRepository.CreateProduct(newProduct);

                UnitOfWork.Commit();

                result = newProduct.Id;
            }
            catch (Exception ex)
            {
                result = -1;
            }

            return(result);
        }
コード例 #3
0
        public async Task <IActionResult> PutProduct([FromRoute] Guid id, [FromBody] VmProduct vmProduct, CancellationToken cancellationToken)
        {
            if (id != vmProduct.Id)
            {
                return(BadRequest());
            }

            var productView = _mapper.Map <ProductView>(vmProduct);
            await _productService.UpdateProductAsync(productView, cancellationToken);

            try
            {
                await _productService.CommitAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await ProductExists(id, cancellationToken))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        public ActionResult WishList()
        {
            #region Cart list
            HttpCookie cookieCart = Request.Cookies["Cart"];
            if (cookieCart != null)
            {
                List <string> CartList = cookieCart.Value.Split(',').ToList();

                CartList.RemoveAt(CartList.Count - 1);

                ViewBag.CartList      = CartList;
                ViewBag.CartListCount = CartList.Count;
            }
            else
            {
                ViewBag.CartListCount = 0;
            }
            #endregion
            VmProduct model = new VmProduct();
            if (model != null)
            {
                List <string> WishList = Request.Cookies["WishList"].Value.Split(',').ToList();
                WishList.RemoveAt(WishList.Count - 1);
                ViewBag.WishListCount = WishList.Count;

                model.HeaderImage = db.HeaderImages.FirstOrDefault(h => h.Page == "WishList");
                model.Products    = db.Products.Include("ProductImages").Where(p => WishList.Contains(p.Id.ToString()) == true).ToList();
            }
            ViewBag.HomeSetting = db.HomeSettings
                                  .Include("HomeSocials")
                                  .Include("HomeSocials.SocialType").FirstOrDefault();
            return(View(model));
        }
コード例 #5
0
 public ActionResult SaleProduct(int?id)
 {
     if (id != null)
     {
         SaleBanner sale = db.SaleBanner.Find(id);
         if (sale != null)
         {
             if (sale.StartDate < DateTime.Now && sale.EndDate > DateTime.Now)
             {
                 VmProduct model = new VmProduct();
                 model.ProductInfos = db.ProductInfos.Include("Images")
                                      .Include("Product")
                                      .Include("SaleBanner")
                                      .Include("Size")
                                      .Include("Color")
                                      .Include("sizeOptions").Where(s => s.SaleBannerId == id).ToList();
                 return(View(model));
             }
             else
             {
                 return(RedirectToAction("index", "Product"));
             }
         }
         else
         {
             return(RedirectToAction("Error", "Home"));
         }
     }
     else
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
コード例 #6
0
 public IActionResult Post([FromBody] VmProduct product)
 {
     unitOfWork.Product.Add(new Product {
         CategoryId = product.CategoryId, Description = product.Description, ProductName = product.ProductName, ProductId = product.ProductId
     });
     unitOfWork.Complete();
     return(Ok());
 }
コード例 #7
0
        public ActionResult ProductDetails(int?Id)
        {
            VmProduct model = new VmProduct();

            #region Wish list
            HttpCookie cookie = Request.Cookies["WishList"];
            if (cookie != null)
            {
                List <string> WishList = cookie.Value.Split(',').ToList();

                WishList.RemoveAt(WishList.Count - 1);

                ViewBag.WishList      = WishList;
                ViewBag.WishListCount = WishList.Count;
            }
            else
            {
                ViewBag.WishListCount = 0;
            }
            #endregion

            #region Cart list
            HttpCookie cookieCart = Request.Cookies["Cart"];
            if (cookieCart != null)
            {
                List <string> CartList = cookieCart.Value.Split(',').ToList();

                CartList.RemoveAt(CartList.Count - 1);

                ViewBag.CartList      = CartList;
                ViewBag.CartListCount = CartList.Count;
            }
            else
            {
                ViewBag.CartListCount = 0;
            }
            #endregion
            Product product = db.Products.Include("Admin").Include("ProductCategory").Include("ProductImages").FirstOrDefault(p => p.Id == Id);
            if (product == null)
            {
                return(HttpNotFound());
            }
            model.Product     = product;
            model.HeaderImage = db.HeaderImages.FirstOrDefault(h => h.Page == "ProductDetails");
            model.Products    = db.Products.Include("Admin")
                                .Include("ProductCategory")
                                .Include("ProductImages")
                                .Where(p => p.ProductCategoryId == product.ProductCategoryId)
                                .OrderByDescending(o => o.Id)
                                .ToList();
            model.ProductImages = db.ProductImages.Where(i => i.ProductId == Id).ToList();
            ViewBag.HomeSetting = db.HomeSettings
                                  .Include("HomeSocials")
                                  .Include("HomeSocials.SocialType").FirstOrDefault();
            return(View(model));
        }
コード例 #8
0
        public async Task <ActionResult <VmProduct> > PostProduct([FromBody] VmProduct vmProduct, CancellationToken cancellationToken)
        {
            var productView = _mapper.Map <ProductView>(vmProduct);
            var dbProduct   = await _productService.AddProductAsync(productView, cancellationToken);

            await _productService.CommitAsync(cancellationToken);

            vmProduct.Id = dbProduct.Id;
            return(CreatedAtAction("GetProduct", new { id = dbProduct.Id }, vmProduct));
        }
コード例 #9
0
        public IActionResult Put([FromBody] VmProduct product, int id)
        {
            var find = unitOfWork.Product.Get(id);

            if (find == null)
            {
                return(NotFound());
            }
            find.CategoryId  = product.CategoryId;
            find.ProductName = product.ProductName;
            find.Description = product.Description;
            unitOfWork.Complete();
            return(Ok());
        }
コード例 #10
0
ファイル: BLProduct.cs プロジェクト: amirrezabarin/WERC
        public VmProduct GetProductById(int id)
        {
            var productRepository = UnitOfWork.GetRepository <ProductRepository>();

            var product = productRepository.GetProductById(id);

            var vmProduct = new VmProduct
            {
                Id            = product.Id,
                ShopOrderId   = product.ShopOrderId,
                ShopProductId = product.ShopProductId,
            };

            return(vmProduct);
        }
コード例 #11
0
        public ActionResult Subcategory(int?id)
        {
            ViewBag.Category = db.Category.Include("Subcategories").Where(s => s.Subcategories.Count != 0).ToList();

            #region Wish List and Cart
            HttpCookie cookieList = Request.Cookies["WishList"];
            HttpCookie cookieCart = Request.Cookies["Cart"];
            if (cookieList != null)
            {
                List <string> wishlist = Request.Cookies["WishList"].Value.Split(',').ToList();
                ViewBag.Wishlist = wishlist;
            }
            if (cookieCart != null)
            {
                List <string> cart = Request.Cookies["Cart"].Value.Split(',').ToList();
                cart.RemoveAt(cart.Count - 1);
                ViewBag.CartCount = cart.Count;
                ViewBag.Cart      = cart;
            }
            else
            {
                ViewBag.CartCount = 0;
            }

            #endregion

            if (id != null)
            {
                VmProduct pro = new VmProduct();
                pro.subcat = db.Subcategory.Find(id);
                if (pro.subcat == null)
                {
                    return(RedirectToAction("Error", "Home"));
                }
                pro.Products = db.Product.Include("productInfos")
                               .Include("productInfos.Images")
                               .Include("productInfos.SaleBanner")
                               .Where(c => c.ProCategories.FirstOrDefault().SubOfSubcategory.SubcategoryId == id)
                               .ToList();
                pro.SubOfSubcategories = db.SubOfSubcategory.Where(s => s.SubcategoryId == id).ToList();

                return(View(pro));
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
コード例 #12
0
        public async Task <IActionResult> Create([FromBody] VmProduct product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                return(Ok(await Service.Create(product)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #13
0
        public async Task <JsonResult> UpdateProduct(VmProduct product)
        {
            var ret        = new VM_JsonOnlyResult();
            var modelState = (new VmProductValidator()).Validate(product);

            if (!modelState.IsValid)
            {
                ;
                ret.Value = -1001;
                ret.Err   = string.Join(",", modelState.Errors.Select(m => m.ErrorMessage));
                return(await Task.FromResult(Json(ret)));
            }

            m_ProductService.PreOnUpdateHandler =
                () =>
            {
                var selfProduct = m_ProductService.GetProduct(product.NagigatedDomainObject.ID);
                if (selfProduct == null)
                {
                    return(null);
                }
                var otherUser = m_ProductService.GetProduct(product.NagigatedDomainObject.Name);
                if (otherUser == null || otherUser.ID == selfProduct.ID)
                {
                    return(selfProduct);
                }
                return(null);
            };
            m_ProductService.OnUpdatingHandler = (existOject, newObject) =>
            {
                ((Product)newObject).MapTo((Product)existOject);
            };
            var updatedRet = await m_ProductService.UpdateObject(product.NagigatedDomainObject, true);

            if (updatedRet == AppServiceExecuteStatus.Success)
            {
                ret.Value  = product.NagigatedDomainObject.ID;
                ret.Result = true;
                return(Json(ret));
            }

            ret.Err = updatedRet.ToDescription();
            return(Json(ret));
        }
コード例 #14
0
ファイル: BLProduct.cs プロジェクト: amirrezabarin/WERC
        public bool UpdateProduct(VmProduct vmProduct)
        {
            try
            {
                var productRepository = UnitOfWork.GetRepository <ProductRepository>();

                var updateableProduct = new Product
                {
                    Id            = vmProduct.Id,
                    ShopProductId = vmProduct.ShopProductId,
                    ShopOrderId   = vmProduct.ShopOrderId,
                };

                productRepository.UpdateProduct(updateableProduct);

                return(UnitOfWork.Commit());
            }
            catch
            {
                return(false);
            }
        }
コード例 #15
0
ファイル: UserController.cs プロジェクト: Shabnam-13/Shopwise
        public ActionResult RecentlyView()
        {
            #region Wish List and Cart
            HttpCookie cookieList = Request.Cookies["WishList"];
            HttpCookie cookieCart = Request.Cookies["Cart"];
            if (cookieList != null)
            {
                List <string> wishlist = Request.Cookies["WishList"].Value.Split(',').ToList();
                ViewBag.Wishlist = wishlist;
            }
            if (cookieCart != null)
            {
                List <string> cart = Request.Cookies["Cart"].Value.Split(',').ToList();
                cart.RemoveAt(cart.Count - 1);
                ViewBag.CartCount = cart.Count;
                ViewBag.Cart      = cart;
            }
            else
            {
                ViewBag.CartCount = 0;
            }

            #endregion
            ViewBag.Category = db.Category.Include("Subcategories").Where(s => s.Subcategories.Count != 0).ToList();

            VmProduct     model = new VmProduct();
            List <string> ids   = new List <string>();
            if (Request.Cookies["SeenProId"] != null)
            {
                ids.AddRange(Request.Cookies["SeenProId"].Value.Split(','));
            }
            model.SeenPro = db.Product.Include("productInfos").Include("productInfos.Images").Include("productInfos.SaleBanner")
                            .Where(i => ids.Contains(i.Id.ToString())).ToList();
            model.Ids = ids;
            return(View(model));
        }
コード例 #16
0
        public ActionResult Index()
        {
            #region Wish List and Cart
            HttpCookie cookieList = Request.Cookies["WishList"];
            HttpCookie cookieCart = Request.Cookies["Cart"];
            if (cookieList != null)
            {
                List <string> wishlist = Request.Cookies["WishList"].Value.Split(',').ToList();
                ViewBag.Wishlist = wishlist;
            }
            if (cookieCart != null)
            {
                List <string> cart = Request.Cookies["Cart"].Value.Split(',').ToList();
                cart.RemoveAt(cart.Count - 1);
                ViewBag.CartCount = cart.Count;
                ViewBag.Cart      = cart;
            }
            else
            {
                ViewBag.CartCount = 0;
            }

            #endregion
            ViewBag.Category = db.Category.Include("Subcategories").Where(s => s.Subcategories.Count != 0).ToList();

            VmProduct model = new VmProduct();
            model.Products = db.Product.Include("productInfos")
                             .Include("productInfos.Images")
                             .Include("productInfos.SaleBanner")
                             .Where(p => p.productInfos.Count != 0)
                             .ToList();
            model.ProductInfos = db.ProductInfos.ToList();
            model.Images       = db.ProductImages.ToList();

            return(View(model));
        }
コード例 #17
0
        // GET: Shopping
        public ActionResult Index(VmSearchShop searchModel, int page = 1)
        {
            VmProduct model = new VmProduct();

            #region Wish list
            HttpCookie cookie = Request.Cookies["WishList"];
            if (cookie != null)
            {
                List <string> WishList = cookie.Value.Split(',').ToList();

                WishList.RemoveAt(WishList.Count - 1);

                ViewBag.WishList      = WishList;
                ViewBag.WishListCount = WishList.Count;
            }
            else
            {
                ViewBag.WishListCount = 0;
            }
            #endregion

            #region Cart list

            HttpCookie    cookieCart = Request.Cookies["Cart"];
            List <string> CartList   = new List <string>();
            if (cookieCart != null)
            {
                CartList = cookieCart.Value.Split(',').ToList();
                CartList.RemoveAt(CartList.Count - 1);

                ViewBag.CartList      = CartList;
                ViewBag.CartListCount = CartList.Count;
            }
            else
            {
                ViewBag.CartListCount = 0;
            }
            #endregion

            List <Product> products = db.Products.Include("ProductCategory").Include("ProductImages").Include("PetTypeToProducts").Include("PetTypeToProducts.PetType").ToList()
                                      .Where(p => (searchModel.CatId != null ? p.ProductCategoryId == searchModel.CatId : true) &&
                                             (searchModel.PetTypeId != null ? p.PetTypeId.Any(pt => pt == searchModel.PetTypeId) : true) &&
                                             ((searchModel.PriceMin != 0 && searchModel.PriceMin != null) ? p.Price >= searchModel.PriceMin : true) &&
                                             ((searchModel.PriceMax != 0 && searchModel.PriceMax != null)? p.Price <= searchModel.PriceMax : true) &&
                                             (searchModel.Search != null ? p.Name.Contains(searchModel.Search) : true)
                                             ).ToList();

            model.Products = products.OrderByDescending(o => o.Id).Skip((page - 1) * 12).Take(12).ToList();

            model.Product           = db.Products.Include("ProductCategory").Include("ProductImages").Include("PetTypeToProducts").Include("PetTypeToProducts.PetType").FirstOrDefault();
            model.ProductCategories = db.ProductCategories.ToList();
            model.HeaderImage       = db.HeaderImages.FirstOrDefault(h => h.Page == "Shop");
            model.PetTypes          = db.PetTypes.ToList();
            model.SearchShop        = searchModel;

            ViewBag.HomeSetting = db.HomeSettings
                                  .Include("HomeSocials")
                                  .Include("HomeSocials.SocialType").FirstOrDefault();
            model.PageCount   = Convert.ToInt32(Math.Ceiling(products.Count() / 12.0));
            model.Currentpage = page;
            //Include("PetTypeToProduct")
            ////    .Include("PetTypeToProduct.PetType")
            return(View(model));
        }
コード例 #18
0
        // GET: Checkout

        public ActionResult Checkout()
        {
            #region Wish list
            HttpCookie cookie = Request.Cookies["WishList"];
            if (cookie != null)
            {
                List <string> WishList = cookie.Value.Split(',').ToList();

                WishList.RemoveAt(WishList.Count - 1);

                ViewBag.WishList      = WishList;
                ViewBag.WishListCount = WishList.Count;
            }
            else
            {
                ViewBag.WishListCount = 0;
            }
            #endregion

            #region Cart list

            HttpCookie    cookieCart = Request.Cookies["Cart"];
            List <string> CartList   = new List <string>();
            if (cookieCart != null)
            {
                CartList = cookieCart.Value.Split(',').ToList();
                CartList.RemoveAt(CartList.Count - 1);

                ViewBag.CartList      = CartList;
                ViewBag.CartListCount = CartList.Count;
            }
            else
            {
                ViewBag.CartListCount = 0;
            }
            #endregion

            VmProduct model = new VmProduct();

            List <Product> products = new List <Product>();

            foreach (var item in CartList)
            {
                foreach (var prd in db.Products.Include("ProductImages").ToList())
                {
                    if (Convert.ToInt32(item.Split('-')[0]) == prd.Id)
                    {
                        prd.Count = Convert.ToDecimal(item.Split('-')[1]);
                        products.Add(prd);
                    }
                }
            }

            model.Products    = products;
            model.HeaderImage = db.HeaderImages.FirstOrDefault(i => i.Page == "Checkout");

            ViewBag.HomeSetting = db.HomeSettings
                                  .Include("HomeSocials")
                                  .Include("HomeSocials.SocialType").FirstOrDefault();
            return(View(model));
        }
コード例 #19
0
        public async Task <Product> Create(VmProduct model)
        {
            var product = Mapper.Map <Product>(model);

            return(await Repo.Create(product));
        }
コード例 #20
0
 public async Task Update(VmProduct model)
 {
     var product = Mapper.Map <Product>(model);
     await Repo.Update(product);
 }
コード例 #21
0
        public ActionResult Details(int?id)
        {
            #region Wish List and Cart
            HttpCookie cookieList = Request.Cookies["WishList"];
            HttpCookie cookieCart = Request.Cookies["Cart"];
            if (cookieList != null)
            {
                List <string> wishlist = Request.Cookies["WishList"].Value.Split(',').ToList();
                ViewBag.Wishlist = wishlist;
            }
            if (cookieCart != null)
            {
                List <string> cart = Request.Cookies["Cart"].Value.Split(',').ToList();
                cart.RemoveAt(cart.Count - 1);
                ViewBag.CartCount = cart.Count;
                ViewBag.Cart      = cart;
            }
            else
            {
                ViewBag.CartCount = 0;
            }

            #endregion

            #region Cookie
            List <string> ids    = new List <string>();
            HttpCookie    cookie = new HttpCookie("SeenProId");
            if (Request.Cookies["SeenProId"] != null)
            {
                ids.AddRange(Request.Cookies["SeenProId"].Value.Split(','));
                if (!ids.Any(i => i.Contains(id.ToString())))
                {
                    ids.Insert(0, id.ToString());
                }
                cookie.Value = string.Join(",", ids);
            }
            else
            {
                cookie.Value   = id.ToString();
                cookie.Expires = DateTime.Now.AddYears(1);
            }
            Response.Cookies.Add(cookie);
            #endregion
            ViewBag.Category = db.Category.Include("Subcategories").Where(s => s.Subcategories.Count != 0).ToList();

            if (id != null)
            {
                VmProduct model = new VmProduct();
                model.product = db.Product.Find(id);

                model.Products = db.Product.Include("productInfos")
                                 .Include("productInfos.Images")
                                 .Include("productInfos.SaleBanner")
                                 .Where(p => p.productInfos.Count != 0)
                                 .ToList();
                model.Colors             = db.Colors.Where(p => p.Products.FirstOrDefault().ProductId == id).ToList();
                model.Sizes              = db.Size.Where(p => p.Products.FirstOrDefault().ProductId == id).ToList();
                model.categories         = db.Category.ToList();
                model.subcategories      = db.Subcategory.ToList();
                model.SubOfSubcategories = db.SubOfSubcategory.ToList();
                model.subOfsubcat        = db.SubOfSubcategory.FirstOrDefault(s => s.proCategories.FirstOrDefault().ProductId == id);
                model.ProductInfos       = db.ProductInfos.Include("Images")
                                           .Include("SaleBanner")
                                           .Include("Size")
                                           .Include("Color")
                                           .Include("sizeOptions")
                                           .Include("Product")
                                           .Where(p => p.ProductId == id).ToList();
                model.productInfo = db.ProductInfos.Include("Product").FirstOrDefault(p => p.ProductId == id);
                model.sizeOptions = db.SizeOption.Where(p => p.productInfoId == model.productInfo.Id).ToList();

                List <string> Ids = new List <string>();
                if (Request.Cookies["SeenProId"] != null)
                {
                    Ids.AddRange(Request.Cookies["SeenProId"].Value.Split(','));
                }
                model.SeenPro = db.Product.Include("productInfos")
                                .Include("productInfos.Images")
                                .Include("productInfos.SaleBanner")
                                .Where(i => Ids.Contains(i.Id.ToString())).ToList();
                model.Ids = Ids;
                if (model.product == null)
                {
                    return(RedirectToAction("Error", "Home"));
                }
                return(View(model));
            }
            return(RedirectToAction("Error", "Home"));
        }