Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public ProductJsonModel(Product product)
 {
     Id = product.Id;
     Title = product.Title;
     Keywords = product.Keywords;
     Description = product.Description;
     Img = product.Img;
     Date = product.Date.FormatDateTime();
     Field1 = product.Field1;
     //Field2 = product.Field2;
     Field3 = product.Field3;
     Field4 = product.Field4;
     Field5 = product.Field5;
     Field6 = product.Field6;
     //Field7 = product.Field7;
     Field8 = product.Field8;
     Field9 = product.Field9;
     Price = product.Price;
     Currency = product.Currency;
     Measure = product.Measure;
     MinimumLotMeasure = product.MinimunLotSize;
     MinimumLotMeasure = product.MinimumLotMeasure;
     VendorCountry = product.VendorCountry;
     DeliveryTime = product.DeliveryTime;
     DeliveryPossibilityDay = product.DeliveryPossibilityDay;
     DeliveryPossibilityTime = product.DeliveryPossibilityTime;
     DeliveryPossibilityMeasure = product.DeliveryPossibilityMeasure;
     ProductCode = product.ProductCode;
     ProductBox = product.ProductBox;
     CategoryId = product.CategoryId;
     UserCategoryId = product.UserCategoryId;
     UserCategoryName = product.UserCategory != null ? product.UserCategory.Title : "";
     CategoryName = product.Category != null ? product.Category.Title : "";
     UserId = product.UserId;
 }
        public ActionResult SaveProduct(Product model, HttpPostedFileBase[] images, string deletedImages)
        {
            if (!IsAuthentificated)
            {
                return RedirectToAction("Register");
            }

            // Проверяем что у нас - создание или сохранение
            Product product = null;
            if (model.Id <= 0)
            {
                product = model;
                product.Date = DateTime.Now;
                product.User = CurrentUser;
                CurrentUser.Products.Add(product);
            }
            else
            {
                product = Locator.GetService<IProductsRepository>().Load(model.Id);
                product.Title = model.Title;
                product.Keywords = model.Keywords;
                product.CategoryId = model.CategoryId;
                product.UserCategoryId = model.UserCategoryId;
                product.User = CurrentUser;
                product.Field1 = model.Field1;
                product.Field3 = model.Field3;
                product.Field4 = model.Field4;
                product.Field5 = model.Field5;
                product.Field6 = model.Field6;
                product.Field8 = model.Field8;
                product.Field9 = model.Field9;
                product.Description = model.Description;
                product.Price = model.Price;
                product.Currency = model.Currency;
                product.Measure = model.Measure;
                product.MinimunLotSize = model.MinimunLotSize;
                product.MinimumLotMeasure = model.MinimumLotMeasure;
                product.VendorCountry = model.VendorCountry;
                product.DeliveryTime = model.DeliveryTime;
                product.DeliveryPossibilityDay = model.DeliveryPossibilityDay;
                product.DeliveryPossibilityMeasure = model.DeliveryPossibilityMeasure;
                product.DeliveryPossibilityTime = model.DeliveryPossibilityTime;
                product.ProductCode = model.ProductCode;
                product.ProductBox = model.ProductBox;

                // Информация о горячем товаре
                if (product.HotProducts == null)
                {
                    product.HotProducts = new HotProduct()
                        {
                            Clicks = 0,
                            EnableHotProduct = false,
                            PayedViews = 0,
                            Product = product,
                            Views = 0
                        };
                }
                product.HotProducts.EnableHotProduct = model.HotProducts.EnableHotProduct;
            }

            // Сохраняем изменения
            UsersRepository.SubmitChanges();

            // Сохраняем фотографию
            var productImageFile = Request.Files["ProductImage"];
            if (productImageFile != null && productImageFile.ContentLength > 0 && productImageFile.ContentType.Contains("image"))
            {
                var fileName = String.Format("prod-{0}-{1}{2}", product.Id,
                                             new Random(System.Environment.TickCount).Next(Int32.MaxValue),
                                             Path.GetExtension(productImageFile.FileName));
                FileUtils.SavePostedFile(productImageFile,"prodimage",fileName);
                product.Img = fileName;
                UsersRepository.SubmitChanges();
            }

            var imagesRepository = Locator.GetService<IProductImagesRepository>();

            if (images.Any())
            {

                foreach (var image in images)
                {
                    if (image != null && image.ContentLength > 0 && image.ContentType.Contains("image"))
                    {
                        var name = String.Format("prod-{0}-{1}{2}", product.Id,
                                             new Random(Environment.TickCount).Next(Int32.MaxValue),
                                             Path.GetExtension(image.FileName));

                        FileUtils.SavePostedFile(image, "prodimage", name);

                        imagesRepository.Add(new ProductImage
                            {
                                Image = name,
                                Product = product,
                                ProductId = product.Id,
                            });
                    }
                }

                imagesRepository.SubmitChanges();
            }

            if (!string.IsNullOrEmpty(deletedImages))
            {
                int[] imageIds = deletedImages.Split(',').Select(n => Convert.ToInt32(n)).ToArray();

                if (imageIds.Any())
                {
                    foreach (var imageId in imageIds)
                    {
                        var image = imagesRepository.Find(f => f.Id == imageId);
                        if (image != null)
                        {
                            imagesRepository.Delete(image);
                        }
                    }

                    imagesRepository.SubmitChanges();
                }
            }

            // Перенаправляемся на список продуктов
            return RedirectToAction("CategoryProducts",new {id = product.UserCategoryId});
        }
        public ActionResult SaveProduct(ProductJsonModel model)
        {
            var rep = Locator.GetService<IProductsRepository>();
            try
            {
                if (model.Id <= 0)
                {
                    var newProduct = new Product()
                    {
                        Date = DateTime.Now
                    };
                    model.UpdateProduct(newProduct);
                    rep.Add(newProduct);
                    rep.SubmitChanges();
                }
                else
                {
                    var prod = rep.Load(model.Id);
                    model.UpdateProduct(prod);
                    prod.Date = DateTime.Now;
                    rep.SubmitChanges();
                }

                return JsonSuccess();
            }
            catch (Exception e)
            {
                return JsonErrors(e.Message);
            }
        }
Exemple #4
0
 /// <summary>
 /// Обновляет продукт
 /// </summary>
 /// <param name="item"></param>
 public void UpdateProduct(Product item)
 {
     item.Title = this.Title;
     item.Keywords = this.Keywords;
     item.Description = this.Description;
     item.Img = this.Img;
     item.Field1 = this.Field1;
     item.Field3 = this.Field3;
     item.Field4 = this.Field4;
     item.Field5 = this.Field5;
     item.Field6 = this.Field6;
     item.Field9 = this.Field9;
     item.Price = this.Price;
     item.Currency = this.Currency;
     item.Measure = this.Measure;
     item.MinimumLotMeasure = this.MinimumLotSize;
     item.MinimumLotMeasure = this.MinimumLotMeasure;
     item.VendorCountry = this.VendorCountry;
     item.DeliveryTime = this.DeliveryTime;
     item.DeliveryPossibilityDay = this.DeliveryPossibilityDay;
     item.DeliveryPossibilityTime = this.DeliveryPossibilityTime;
     item.DeliveryPossibilityMeasure = this.DeliveryPossibilityMeasure;
     item.ProductCode = this.ProductCode;
     item.ProductBox = this.ProductBox;
     if (this.CategoryId != item.CategoryId)
     {
         item.Category = Locator.GetService<ICategoriesRepository>().Load(this.CategoryId);
     }
     if (this.UserCategoryId != item.UserCategoryId && item.User != null)
     {
         item.UserCategory = item.User.UserCategories.FirstOrDefault(c => c.Id == this.UserCategoryId);
     }
     if (this.UserId != item.UserId)
     {
         item.User = Locator.GetService<IUsersRepository>().Load(this.UserId);
     }
 }
Exemple #5
0
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.UserCategory = null;
		}
Exemple #6
0
		private void attach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Category = this;
		}