Ejemplo n.º 1
0
        public int AddToCart(IUnitOfWork unitOfWork, ICartService cartService, Product product)
        {
            var cartItem = cartService.ODataQueryable().SingleOrDefault(
                    c => c.CartId == ShoppingCartId
                    && c.ProductId == product.Id);

            if (cartItem == null)
            {
                cartItem = new Cart
                {
                    CartId = ShoppingCartId,
                    ProductId = product.Id,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
                cartService.Insert(cartItem);
            }
            else
            {
                cartItem.Count++;
                cartService.Update(cartItem);
            }

            //save changes
            unitOfWork.SaveChanges();
            return cartItem.Count;
        }
Ejemplo n.º 2
0
        public ActionResult Input(ProductModel model)
        {
            if (ModelState.IsValid)
            {
                Product entity = null;
                try
                {
                    if (model.Id > 0)
                        entity = _productService.Find(model.Id);
                    else
                        entity = new Product() { CreatedDate = DateTime.Now };

                    #region Set value for category entity

                    entity.SKU = model.SKU;
                    entity.Name = model.Name;
                    entity.Alias = model.Alias;
                    entity.Brief = model.Brief;
                    entity.Description = model.Description;
                    entity.Price = entity.Price;
                    entity.IsActive = model.IsActive;
                    entity.DisplayOrder = model.DisplayOrder;
                    entity.Thumbnail = model.Thumbnail != null ? model.Thumbnail : "default.jpg";
                    entity.CategoryId = model.CategoryId;
                    entity.CallPrice = model.CallPrice;
                    entity.Capability = model.Capability;
                    entity.KeyBenefit = model.KeyBenefit;
                    entity.CaseStudy = model.CaseStudy;
                    entity.EnableGallery = model.EnableGallery;
                    entity.UpdatedDate = DateTime.Now;
                    entity.UpdatedBy = User.Identity.Name;
                    if (!string.IsNullOrEmpty(model.FileAttachTemp))
                        entity.FileAttach = model.FileAttachTemp;
                    entity.FileAttachName = model.FileAttachName;

                    #endregion

                    #region Perform save data
                    if (model.Id <= 0)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _productService.Insert(entity);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _productService.Update(entity);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }

                    return Json(new { Status = ResultStatus.Success, Message = StringTable.DataSaveSuccess });
                    #endregion
                }
                catch
                {
                    return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
                }
            }
            else
            {
                return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
            }
        }
Ejemplo n.º 3
0
        public ActionResult Input(int id = 0)
        {
            var entity = _productService.Find(id);

            if (entity == null)
            {
                entity = new Product()
                {
                    IsActive = true,
                    EnableGallery = true
                };
            }
            var model = entity.ToModel();
            ViewData["ListCategory"] = GetListCategory();

            return View(model);
        }