Пример #1
0
        public ActionResult Edit(Product product)
        {
            if (product.Shelved != null && product.Shelved.Value)
            {
                return(View("Error", new ErrorView()
                {
                    message = ProductCannotEdit
                }));
            }
            try
            {
                var pics = GetPictures(product);
                foreach (ProductPicture pic in pics)
                {
                    if (pic.ID == 0)
                    {
                        svc.Create(pic);
                    }
                    else
                    {
                        svc.Update(pic);
                    }
                }
                var specifications = GetSpecifications(product);
                foreach (var specification in specifications)
                {
                    if (specification.ID == 0)
                    {
                        svc.Create(specification);
                    }
                    else
                    {
                        svc.Update(specification);
                    }
                }

                //******************************************************
                product.Description = product.Description ?? "";
                product.Weight      = product.Weight ?? 0;
                //******************************************************

                svc.Update(product);
                product.Specifications  = specifications;
                product.ProductPictures = pics;
                ViewData["MallNames"]   = Makenames(product, MallSize);
                ViewBag.Tags            = GetTags(product.ID.Value);
                return(View(product));
            }
            catch (Exception e)
            {
                return(View("Error", new ErrorView()
                {
                    message = e.Message
                }));
            }
        }
Пример #2
0
        private Dictionary <long, string> Makenames(Product product, PictureSize size)
        {
            Dictionary <long, string> Names = new Dictionary <long, string>();

            if (product != null)
            {
                foreach (var pic in product.ProductPictures)
                {
                    Names.Add(pic.ID.Value, _pictureService.GetName(pic, size));
                }
            }
            return(Names);
        }
Пример #3
0
 public ActionResult Add(Product product)
 {
     try
     {
         if (string.IsNullOrEmpty(product.Name))
         {
             ErrorView error = new ErrorView()
             {
                 message = EmptyProductName
             };
             return(View("Error", error));
         }
         product.Specifications = GetSpecifications(product);
         var orignpics = GetPictures(product);
         product.OwnerID         = GetOwnerID();
         product.ProductPictures = orignpics;
         svc.Create(product);
         if (orignpics.Count > 0)
         {
             var newpics = new ProductPicture[orignpics.Count()];
             for (int i = 0; i < orignpics.Count(); i++)
             {
                 ProductPicture pic = new ProductPicture()
                 {
                     ID   = orignpics[i].ID,
                     Name = orignpics[i].Name,
                     Path = MakePath(product.ID.Value),
                 };
                 newpics[i] = pic;
             }
             svc.Update(newpics);
             _pictureService.Move(orignpics.ToArray(), newpics);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         ErrorView error = new ErrorView()
         {
             message = e.Message
         };
         return(View("Error", error));
     }
 }
Пример #4
0
        private Collection <Specification> GetSpecifications(Product product)
        {
            int count    = Convert.ToInt32(Request.Form["RowsCount"]);
            var response = new Collection <Specification>();
            //默认规格
            Specification defaultS = new Specification()
            {
                ID             = Convert.ToInt32(Request.Form["id0"]),
                ProductName    = product.Name,
                Name           = "",
                Price          = !String.IsNullOrEmpty(Request.Form["price0"]) ? Convert.ToDecimal(Request.Form["price0"]) : 0,
                Stock          = !String.IsNullOrEmpty(Request.Form["stock0"]) ? Convert.ToInt32(Request.Form["stock0"]) : 0,
                ReferencePrice = 0,
                WarningStock   = 0,
                IsDefault      = true,
                IsShow         = count == 0,
                OwnerID        = product.OwnerID,
                ProductID      = product.ID,
            };

            response.Add(defaultS);
            for (int i = 1; i < count + 1; i++)
            {
                Specification specification = new Specification()
                {
                    ID             = Convert.ToInt32(Request.Form["id" + i]),
                    ProductName    = product.Name,
                    Name           = Request.Form["name" + i],
                    Price          = !String.IsNullOrEmpty(Request.Form["price" + i]) ? Convert.ToDecimal(Request.Form["price" + i]) : 0,
                    Stock          = !String.IsNullOrEmpty(Request.Form["stock" + i]) ? Convert.ToInt32(Request.Form["stock" + i]) : 0,
                    ReferencePrice = 0,
                    WarningStock   = 0,
                    IsDefault      = false,
                    IsShow         = Convert.ToBoolean(Request.Form["isShow" + i]),
                    OwnerID        = product.OwnerID,
                    ProductID      = product.ID,
                };
                response.Add(specification);
            }
            return(response);
        }
Пример #5
0
        private Collection <ProductPicture> GetPictures(Product product)
        {
            int count = Convert.ToInt32(Request.Form["PicCount"]);
            Collection <ProductPicture> pictures = new Collection <ProductPicture>();

            for (int i = 0; i < count; i++)
            {
                if (!string.IsNullOrEmpty(Request.Form["picId" + i]))
                {
                    ProductPicture pic = new ProductPicture()
                    {
                        ID         = Convert.ToInt32(Request.Form["picId" + i]),
                        Name       = GetHashName(Request.Form["picName" + i]),
                        OriginName = Request.Form["picName" + i],
                        Path       = Request.Form["picPath" + i],
                        IsFirst    = Convert.ToBoolean(Request.Form["picIsFirst" + i]),
                        OwnerID    = product.OwnerID,
                        ProductID  = product.ID,
                    };
                    pictures.Add(pic);
                }
            }
            return(pictures);
        }