Example #1
0
        public async Task <ActionResult <BrandProduct> > Update([FromBody] BrandProduct body, [FromRoute] int Id = 0)
        {
            if (!ModelState.IsValid || Id < 1)
            {
                return(BadRequest(ModelState));
            }

            var GetItem = await _UnitOfWork.BrandProducts.GetById(Id);

            ResultData <BrandProduct> data = new ResultData <BrandProduct>();

            if (GetItem == null)
            {
                return(Ok(data));
            }
            #region
            GetItem.Name = body.Name;
            #endregion
            await _UnitOfWork.BrandProducts.Update(GetItem, true);

            data.Data    = body;
            data.Success = true;
            data.Message = "Thành công !";
            return(Ok(GetItem));
        }
Example #2
0
        public ActionResult DeleteProduct(int id, BrandProduct brandProduct)
        {
            var tan = db.BrandProducts.Find(id);

            db.BrandProducts.Remove(tan);
            db.SaveChanges();
            return(Redirect("/Admin/Brands"));
        }
Example #3
0
 public ActionResult AddProduct(int id, BrandProduct brandProduct)
 {
     if (ModelState.IsValid)
     {
         brandProduct.BrandID   = id;
         brandProduct.BrandName = db.Brands.Where(x => x.BrandID == id).Select(x => x.BrandName).FirstOrDefault();
         db.BrandProducts.Add(brandProduct);
         db.SaveChanges();
         return(RedirectToAction("Details/" + id));
     }
     return(View());
 }
Example #4
0
        public async Task <ActionResult <ResultData <BrandProduct> > > GetById([FromRoute] int Id)
        {
            ResultData <BrandProduct> data = new ResultData <BrandProduct>();
            BrandProduct Item = await _UnitOfWork.BrandProducts.GetById(Id);

            if (data == null)
            {
                return(data);
            }
            data.Data    = Item;
            data.Success = true;
            data.Message = "Thành công !";
            return(Ok(data));
        }
Example #5
0
        public async Task <ActionResult <BrandProduct> > Add([FromBody] BrandProduct body)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ResultData <BrandProduct> data = new ResultData <BrandProduct>();
            await _UnitOfWork.BrandProducts.Insert(body);

            await _UnitOfWork.Commit();

            data.Data    = body;
            data.Success = body.Id > 0 ? true : false;
            data.Message = body.Id > 0 ? "Thành công !" : "Thất bại !";
            return(Ok(data));
        }
Example #6
0
        public async Task <ActionResult <ActionResult <BrandProduct> > > Delete([FromRoute] int Id = 0)
        {
            if (Id < 1)
            {
                return(BadRequest(ModelState));
            }
            ResultData <BrandProduct> data = new ResultData <BrandProduct>();
            BrandProduct GetItem           = await _UnitOfWork.BrandProducts.GetById(Id);

            if (GetItem == null)
            {
                return(Ok(data));
            }

            GetItem.Status = 3;//delete
            await _UnitOfWork.BrandProducts.Delete(GetItem, true);

            data.Data    = GetItem;
            data.Success = true;
            data.Message = "Thành công !";

            return(Ok(data));
        }
Example #7
0
        private void SaveProduct(HttpContext context)
        {
            string  Id             = context.Request.Form["ctl00$cphMain$hId"].Trim();
            string  sProductName   = context.Request.Form["ctl00$cphMain$txtProductName"].Trim();
            string  sSubTitle      = context.Request.Form["ctl00$cphMain$txtSubTitle"].Trim();
            decimal dOriginalPrice = 0;
            decimal dProductPrice  = 0;
            float   discount       = 0;

            decimal.TryParse(context.Request.Form["ctl00$cphMain$txtOriginalPrice"].Trim(), out dOriginalPrice);
            decimal.TryParse(context.Request.Form["ctl00$cphMain$txtProductPrice"].Trim(), out dProductPrice);
            float.TryParse(context.Request.Form["ctl00$cphMain$txtDiscount"].Trim(), out discount);
            string sDiscountDescri = context.Request.Form["ctl00$cphMain$txtDiscountDescri"].Trim();
            int    stockNum        = 0;

            int.TryParse(context.Request.Form["ctl00$cphMain$txtStockNum"].Trim(), out stockNum);
            string sProductPictureId = context.Request.Form["productPictureId"].Trim();
            Guid   productPictureId  = Guid.Empty;

            Guid.TryParse(sProductPictureId, out productPictureId);
            string sCategoryId = context.Request.Form["categoryId"].Trim();
            Guid   categoryId  = Guid.Empty;

            Guid.TryParse(sCategoryId, out categoryId);
            string sBrandId = context.Request.Form["brandId"].Trim();
            Guid   brandId  = Guid.Empty;

            Guid.TryParse(sBrandId, out brandId);
            Guid customMenuId = Guid.Empty;

            Guid.TryParse(context.Request.Form["customMenuId"].Trim(), out customMenuId);
            string sOtherPicture = context.Request.Form["otherPic"].Trim();
            string sSizeItem     = context.Request.Form["sizeItem"].Trim();
            string sSizePicture  = context.Request.Form["sizePicture"].Trim();
            string sPayOption    = "";

            string content = context.Request.Form["txtContent"].Trim();

            content = HttpUtility.HtmlDecode(content);
            Guid gId = Guid.Empty;

            if (Id != "")
            {
                Guid.TryParse(Id, out gId);
            }

            ProductInfo model = new ProductInfo();

            model.Id               = gId;
            model.UserId           = WebCommon.GetUserId();
            model.LastUpdatedDate  = DateTime.Now;
            model.ProductName      = sProductName;
            model.SubTitle         = sSubTitle;
            model.OriginalPrice    = dOriginalPrice;
            model.ProductPrice     = dProductPrice;
            model.Discount         = discount;
            model.DiscountDescri   = sDiscountDescri;
            model.ProductPictureId = productPictureId;
            model.StockNum         = stockNum;
            model.CustomMenuId     = customMenuId;

            Product         bll   = new Product();
            ProductItem     piBll = new ProductItem();
            CategoryProduct cpBll = new CategoryProduct();
            BrandProduct    bpBll = new BrandProduct();

            ProductItemInfo piModel = new ProductItemInfo();

            piModel.OtherPicture = sOtherPicture;
            piModel.SizeItem     = sSizeItem;
            piModel.SizePicture  = sSizePicture;
            piModel.PayOption    = sPayOption;
            piModel.CustomAttr   = string.Empty;
            piModel.Descr        = content;
            piModel.ProductId    = gId;

            int effect = -1;

            if (!gId.Equals(Guid.Empty))
            {
                bll.Update(model);
                piBll.Update(piModel);

                CategoryProductInfo cpModel = cpBll.GetModel(gId);
                BrandProductInfo    bpModel = bpBll.GetModel(gId);

                #region 所属分类

                if (!categoryId.Equals(Guid.Empty))
                {
                    if (cpModel == null)
                    {
                        cpModel            = new CategoryProductInfo();
                        cpModel.ProductId  = gId;
                        cpModel.CategoryId = categoryId;
                        cpBll.Insert(cpModel);
                    }
                    else
                    {
                        if (!cpModel.CategoryId.Equals(categoryId))
                        {
                            cpModel.CategoryId = categoryId;
                            cpBll.Update(cpModel);
                        }
                    }
                }
                else
                {
                    if (cpModel != null)
                    {
                        cpBll.Delete(gId, cpModel.CategoryId);
                    }
                }

                #endregion
                #region 所属品牌

                if (!brandId.Equals(Guid.Empty))
                {
                    if (bpModel == null)
                    {
                        bpModel           = new BrandProductInfo();
                        bpModel.ProductId = gId;
                        bpModel.BrandId   = brandId;
                        bpBll.Insert(bpModel);
                    }
                    else
                    {
                        if (!bpModel.BrandId.Equals(brandId))
                        {
                            bpModel.BrandId = brandId;
                            bpBll.Update(bpModel);
                        }
                    }
                }
                else
                {
                    if (bpModel != null)
                    {
                        bpBll.Delete(gId, bpModel.BrandId);
                    }
                }

                #endregion

                effect = 1;
            }
            else
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    Guid productId = bll.Insert(model);
                    piModel.ProductId = productId;
                    piBll.Insert(piModel);
                    if (!categoryId.Equals(Guid.Empty))
                    {
                        CategoryProductInfo cpModel = new CategoryProductInfo();
                        cpModel.CategoryId = categoryId;
                        cpModel.ProductId  = productId;
                        cpBll.Insert(cpModel);
                    }
                    if (!brandId.Equals(Guid.Empty))
                    {
                        BrandProductInfo bpModel = new BrandProductInfo();
                        bpModel.BrandId   = brandId;
                        bpModel.ProductId = productId;
                        bpBll.Insert(bpModel);
                    }

                    effect = 1;

                    scope.Complete();
                }
            }

            if (effect != 1)
            {
                context.Response.Write("{\"success\": false,\"message\": \"操作失败,请正确输入\"}");
                return;
            }

            context.Response.Write("{\"success\": true,\"message\": \"操作成功\"}");
        }
 public ActionResult SalvarBrandProduct(BrandProduct brand)
 {
     ViewBag.Message = "Marcas de Coche";
     SaveEntity(brand);
     return base.View("Nuevo", brand);
 }
        public ActionResult SalvarProducto(Product product, string TypeName, string BrandName)
        {
            ViewBag.Message = "Productos";

            if (!string.IsNullOrEmpty(TypeName))
            {
                var oldType = this.DataService.TypeProductRepository.CreateQuery(Proyection.Basic)
                    .Where(TypeProductFields.TypeProductName, TypeName).ToList().FirstOrDefault();
                if (oldType == null)
                {
                    TypeProduct type = new TypeProduct();
                    type.TypeProductName = TypeName;
                    SaveEntity(type);
                    product.TypeProductId = type.TypeProductId;
                }
                else
                {
                    product.TypeProductId = oldType.TypeProductId;
                }
            }

            if (!string.IsNullOrEmpty(BrandName))
            {
                var oldBp = this.DataService.BrandProductRepository.CreateQuery(Proyection.Basic)
                    .Where(BrandProductFields.BrandProductName, BrandName).ToList().FirstOrDefault();
                if (oldBp == null)
                {
                    BrandProduct bp = new BrandProduct();
                    bp.BrandProductName = BrandName;
                    SaveEntity(bp);
                    product.BrandProductId = bp.BrandProductId;
                }
                else
                {
                    product.BrandProductId = oldBp.BrandProductId;
                }
            }

            SaveEntity(product);
            return this.Json(new { result = "success" });
        }