Esempio n. 1
0
        public override ServiceResult <ProductEntity> Update(ProductEntity item)
        {
            var result = base.Update(item);

            if (result.HasViolation)
            {
                return(result);
            }
            if (item.ProductTags != null)
            {
                _productTagService.Remove(m => m.ProductId == item.ID);
                _productTagService.BeginBulkSave();
                foreach (var tag in item.ProductTags.Where(m => m.Selected))
                {
                    _productTagService.Add(new ProductTag {
                        ProductId = item.ID, TagId = tag.ID
                    });
                }
                _productTagService.SaveChanges();
            }
            if (item.ProductImages != null)
            {
                _productImageService.BeginBulkSave();
                item.ProductImages.Each(m =>
                {
                    m.ProductId = item.ID;
                    SaveImages(m);
                });
                _productImageService.SaveChanges();
            }
            return(result);
        }
Esempio n. 2
0
 public IActionResult UploadFileToRepo(long id)
 {
     try
     {
         var files = Request.Form.Files;
         foreach (var file in files)
         {
             if (file.Length > 0)
             {
                 var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                 _fileService.SaveFileToPhysicalStorage(file, fileName);
                 var productImage = new ProductImage
                 {
                     ProductId = id,
                     ImgUrl    = @"https://localhost:44315/api/file/get/" + fileName
                 };
                 _productImageService.CreateProductImage(productImage);
             }
             else
             {
                 return(BadRequest("File Was Empty?"));
             }
         }
         _productImageService.SaveChanges();
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, $"Internal server error: {ex}"));
     }
 }
Esempio n. 3
0
        public async Task <IActionResult> Add([FromBody] ProductImageViewModel productImageVm)
        {
            var hasPermission = await _authorizationService.AuthorizeAsync(User, "PRODUCT", Operations.Create);

            if (hasPermission.Succeeded == false)
            {
                return(new BadRequestObjectResult(CommonConstants.Forbidden));
            }
            if (ModelState.IsValid)
            {
                _productImageService.Add(productImageVm);
                _productImageService.SaveChanges();
                return(new OkObjectResult(productImageVm));
            }
            return(new BadRequestObjectResult(ModelState));
        }
        public ActionResult DeleteProductImage(int id)
        {
            var modelFromRepo = _imageService.GetImageById(id);

            if (modelFromRepo == null)
            {
                return(NotFound());
            }
            _imageService.DeleteProductImage(modelFromRepo);
            _imageService.SaveChanges();
            return(NoContent());
        }
Esempio n. 5
0
        public override ServiceResult <ProductEntity> Update(ProductEntity item)
        {
            ServiceResult <ProductEntity> result = new ServiceResult <ProductEntity>();

            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (Count(m => m.Url == item.Url && m.ID != item.ID) > 0)
                {
                    result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists")));
                    return(result);
                }
            }
            _eventManager.Trigger(Events.OnProductUpdating, item);
            BeginTransaction(() =>
            {
                result = base.Update(item);
                if (!result.HasViolation)
                {
                    if (item.ProductTags != null)
                    {
                        _productTagService.Remove(m => m.ProductId == item.ID);
                        _productTagService.BeginBulkSave();
                        foreach (var tag in item.ProductTags.Where(m => m.Selected))
                        {
                            _productTagService.Add(new ProductTag {
                                ProductId = item.ID, TagId = tag.ID
                            });
                        }
                        _productTagService.SaveChanges();
                    }
                    if (item.ProductImages != null)
                    {
                        _productImageService.BeginBulkSave();
                        item.ProductImages.Each(m =>
                        {
                            m.ProductId = item.ID;
                            SaveImages(m);
                        });
                        _productImageService.SaveChanges();
                    }
                }
            });
            _eventManager.Trigger(Events.OnProductUpdated, item);
            return(result);
        }
        public override ServiceResult <ProductEntity> Update(ProductEntity item)
        {
            if (item.Url.IsNotNullAndWhiteSpace())
            {
                if (Count(m => m.Url == item.Url && m.ID != item.ID) > 0)
                {
                    var re = new ServiceResult <ProductEntity>();
                    re.RuleViolations.Add(new RuleViolation("Url", "UrlÒÑ´æÔÚ"));
                    return(re);
                }
            }
            var result = base.Update(item);

            if (result.HasViolation)
            {
                return(result);
            }
            if (item.ProductTags != null)
            {
                _productTagService.Remove(m => m.ProductId == item.ID);
                _productTagService.BeginBulkSave();
                foreach (var tag in item.ProductTags.Where(m => m.Selected))
                {
                    _productTagService.Add(new ProductTag {
                        ProductId = item.ID, TagId = tag.ID
                    });
                }
                _productTagService.SaveChanges();
            }
            if (item.ProductImages != null)
            {
                _productImageService.BeginBulkSave();
                item.ProductImages.Each(m =>
                {
                    m.ProductId = item.ID;
                    SaveImages(m);
                });
                _productImageService.SaveChanges();
            }
            return(result);
        }