Пример #1
0
        public string GetProfilePicturePath(SliderDto dto, string oldPath = null)
        {
            if (!dto.Items.Any(c => c.IsProfilePicture && !c.IsDeleted))
            {
                dto.Items.First(c => !c.IsDeleted).IsProfilePicture = true;
            }

            foreach (var c in dto.Items)
            {
                if (c.IsProfilePicture)
                {
                    if (!c.IsDeleted)
                    {
                        if (c.IsNew)
                        {
                            c.Path = _attachmentsManager.Save(new SavedFileDto
                            {
                                attachmentType = dto.attachmentType,
                                CanChangeName  = true,
                                File           = c.File,
                                SubFolderName  = dto.SubFolderName
                            });
                        }
                        return(c.Path);
                    }
                    //else
                    //{
                    //    return null;
                    //}
                }
            }
            return(oldPath);
        }
Пример #2
0
        public bool Add(SliderDto dto)
        {
            try
            {
                dto.Items.ForEach(c =>
                {
                    if (!c.IsProfilePicture)
                    {
                        c.Path = _attachmentsManager.Save(new SavedFileDto
                        {
                            attachmentType = dto.attachmentType,
                            CanChangeName  = true,
                            File           = c.File,
                            SubFolderName  = dto.SubFolderName
                        });
                    }

                    var Obj      = c.Adapt <T>();
                    Obj.ParentId = dto.ParentId;
                    _repository.Insert(Obj);
                });

                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(false);
            }
        }
Пример #3
0
        public ActionResult Gallery()
        {
            Operation       operation = new OpSliderBase();
            OperationResult result    = _manager.ExecuteOperation(operation);
            SliderDto       sl        = result.Items[0] as SliderDto;

            return(View(sl));
        }
Пример #4
0
        public JsonResult Slider(SliderDto dto)
        {
            OpSliderBase op = new OpSliderBase();

            op.Dto = dto;
            var result = _manager.ExecuteOperation(op);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public bool Update(SliderDto dto)
        {
            try
            {
                //added images
                dto.Items.Where(c => c.IsNew).ToList().ForEach(c =>
                {
                    if (!c.IsProfilePicture)
                    {
                        c.Path = _attachmentsManager.Save(new SavedFileDto
                        {
                            attachmentType = dto.attachmentType,
                            CanChangeName  = true,
                            File           = c.File,
                            SubFolderName  = dto.SubFolderName
                        });
                    }
                    var Obj      = c.Adapt <T>();
                    Obj.ParentId = dto.ParentId;
                    _repository.Insert(Obj);
                });

                //updated images
                dto.Items.Where(c => c.IsDataUpdated && !c.IsDeleted).ToList().ForEach(c =>
                {
                    var oldImage = _repository.GetById(c.Id);
                    if (oldImage != null)
                    {
                        c.Adapt(oldImage, typeof(SliderItemDto), typeof(ArticlesImages));
                        oldImage.ParentId = dto.ParentId;
                        _repository.Update(oldImage);
                        _unitOfWork.Commit();
                    }
                });

                //deleted images
                dto.Items.Where(c => c.IsDeleted && !string.IsNullOrEmpty(c.Path)).ToList().ForEach(c =>
                {
                    _attachmentsManager.Delete(c.Path);

                    var Obj = _repository.GetById(c.Id);
                    if (Obj != null)
                    {
                        _repository.Delete(c.Id);
                    }
                });

                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(false);
            }
        }
Пример #6
0
        public ActionResult Gallery()
        {
            OpSliderBase    op     = new OpSliderBase();
            OperationResult result = new OperationResult();

            result = _manager.ExecuteOperation(op);
            SliderDto dto = result.Items[0] as SliderDto;

            return(View(dto));
        }
Пример #7
0
        public async void DeleteDevice_ActionExecutes_ReturnResultWithDeviceDto(int id)
        {
            SliderDto deletedData = Sliders.Find(x => x.Id == id);

            _mockSliderService.Setup(x => x.Update(deletedData, id)).ReturnsAsync(Response <NoDataDto> .Success(200));
            var result = await _sliderController.Update(deletedData);

            Assert.IsType <ObjectResult>(result);

            ButtonDto deletedButtonData = Buttons.Find(x => x.Id == id);

            _mockButtonService.Setup(x => x.Update(deletedButtonData, id)).ReturnsAsync(Response <NoDataDto> .Success(200));
            var resultButton = await _buttonController.Update(deletedButtonData);

            Assert.IsType <ObjectResult>(resultButton);
        }
Пример #8
0
        public override OperationResult Execute(AspSiteBazaEntities entities)
        {
            SliderDto dto = new SliderDto();
            IEnumerable <PictureDto> iePictures =
                from p in entities.Sliders
                select new PictureDto
            {
                Alt = p.Picture.alt,
                Src = p.Picture.src
            };

            dto.Pictures = iePictures.ToList();
            OperationResult result = new OperationResult();

            result.Status   = true;
            result.Items    = new BaseDto[1];
            result.Items[0] = dto;
            return(result);
        }
Пример #9
0
        public override OperationResult execute(CimetEntities entities)
        {
            SliderDto dto = new SliderDto();
            IEnumerable <PictureDto> iePictures =
                from slider in entities.slider
                select new PictureDto
            {
                Alt  = slider.picture.alt,
                Src  = slider.picture.src,
                Text = slider.text
            };

            dto.Pictures = iePictures.ToList();

            OperationResult result = new OperationResult();

            result.Status   = true;
            result.Items    = new BaseDto[1];
            result.Items[0] = dto;
            return(result);
        }
Пример #10
0
        public bool Delete(SliderDto dto)
        {
            try
            {
                dto.Items.Where(c => !string.IsNullOrEmpty(c.Path)).ToList().ForEach(c =>
                {
                    _attachmentsManager.Delete(c.Path);

                    var Obj = _repository.GetById(c.Id);
                    if (Obj != null)
                    {
                        _repository.Delete(c.Id);
                    }
                });

                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(false);
            }
        }
Пример #11
0
        public ResultMessage Insert(ProductsDto newProductDto, IUserDto user)
        {
            var validationResult = _validator.Validate(newProductDto);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                var productFolderName = Guid.NewGuid().ToString();

                var newProduct = newProductDto.Adapt <DBModels.Products>();
                newProduct.IsActive      = null;
                newProduct.CreatedAt     = DateTime.Now;
                newProduct.CreatedBy     = user.Id;
                newProduct.SubFolderName = productFolderName;

                var sliderDto = new SliderDto
                {
                    attachmentType = AttachmentTypesEnum.Products,
                    Items          = newProductDto.UpdatedImages,
                    SubFolderName  = productFolderName
                };

                if (sliderDto.Items != null && sliderDto.Items.Count > 0)
                {
                    newProduct.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto);
                }

                if (user.IsAdmin)
                {
                    newProduct.IsActive = true;
                }

                _unitOfWork.ProductsRepository.Insert(newProduct);
                _unitOfWork.Commit();

                sliderDto.ParentId = newProduct.Id;
                _sliderManager.Add(sliderDto);

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK,
                    Data = GetById(newProduct.Id).Data
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsInsertError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Пример #12
0
        public ResultMessage Update(ProductsDto product, int id, IUserDto user)
        {
            var validationResult = _validator.Validate(product);

            if (!validationResult.IsValid)
            {
                return new ResultMessage
                       {
                           Status             = HttpStatusCode.BadRequest,
                           ValidationMessages = validationResult.GetErrorsList()
                       }
            }
            ;

            try
            {
                var oldProduct = _unitOfWork.ProductsRepository.GetById(id);

                if (oldProduct == null)
                {
                    return new ResultMessage
                           {
                               Status    = HttpStatusCode.NotFound,
                               ErrorCode = (int)ProductsErrorsCodeEnum.ProductsNotFoundError
                           }
                }
                ;

                if (!user.IsAdmin && oldProduct.CreatedBy != user.Id)
                {
                    return new ResultMessage
                           {
                               Status    = HttpStatusCode.NotFound,
                               ErrorCode = (int)ProductsErrorsCodeEnum.ProductsNotFoundError
                           }
                }
                ;

                oldProduct.Name = product.Name;
                if (product.ProfilePictureFile != null)
                {
                    oldProduct.ProfilePicture = _attachmentsManager.Save(new SavedFileDto
                    {
                        attachmentType = AttachmentTypesEnum.Products,
                        CanChangeName  = true,
                        File           = product.ProfilePictureFile
                    });
                }

                oldProduct.IsActive = product.IsActive = null;
                if (user.IsAdmin)
                {
                    oldProduct.IsActive = true;
                }

                oldProduct.IsSpecial   = product.IsSpecial;
                oldProduct.Price       = product.Price;
                oldProduct.ExpDate     = product.ExpDate;
                oldProduct.Description = product.Description;
                oldProduct.CategoryId  = product.CategoryId;
                oldProduct.PhoneNumber = product.PhoneNumber;

                oldProduct.UpdatedBy = user.Id;
                oldProduct.UpdatedAt = DateTime.Now;

                var sliderDto = new SliderDto
                {
                    attachmentType = AttachmentTypesEnum.Products,
                    Items          = product.UpdatedImages ?? new List <SliderItemDto>(),
                    SubFolderName  = oldProduct.SubFolderName,
                    ParentId       = id
                };

                //check profile picture
                if (sliderDto.Items.Count > 0)
                {
                    oldProduct.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto, oldProduct.ProfilePicture);
                }


                _unitOfWork.ProductsRepository.Update(oldProduct);
                _unitOfWork.Commit();

                // update files
                if (sliderDto.Items.Count > 0)
                {
                    _sliderManager.Update(sliderDto);
                }

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK,
                    Data = oldProduct.Adapt <ProductsDto>()
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError,
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsUpdateError
                });
            }
        }
 public async Task <IActionResult> Update([FromBody] SliderDto updateSlider)
 {
     return(ActionResultInstance(await _userService.Update(updateSlider, 1)));
 }
Пример #14
0
        public ResultMessage Update(ArticleAddDto article, int articleId, IUserDto user)
        {
            _logger.LogInformation($"START: Article.Update: Name:{article.Name}");

            var validationResult = _addValidator.Validate(article);

            if (!validationResult.IsValid)
            {
                _logger.LogInformation($"END: Article.Update: Id:{articleId} -- VALIDATION");
                return(new ResultMessage
                {
                    Status = HttpStatusCode.BadRequest,
                    ValidationMessages = validationResult.GetErrorsList()
                });
            }
            try
            {
                var articleData = _unitOfWork.ArticlesRepository.GetById(articleId);
                if (articleData == null || articleData.IsDraft)
                {
                    _logger.LogInformation($"END: Article.Update: Id:{articleId} -- NOTFOUND");
                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.NotFound,
                    });
                }


                if (user.IsAdmin || (user.Id == articleData.CreatedBy && (!articleData.IsActive.HasValue || !articleData.IsActive.Value)))
                {
                    article.Adapt(articleData, typeof(ArticleAddDto), typeof(DBModels.Articles));
                    articleData.UpdatedAt = DateTime.Now;
                    articleData.UpdatedBy = user.Id;

                    var sliderDto = new SliderDto
                    {
                        attachmentType = AttachmentTypesEnum.Articles,
                        Items          = article.UpdatedImages ?? new List <SliderItemDto>(),
                        SubFolderName  = articleData.SubFolderName,
                        ParentId       = articleId
                    };

                    //check profile picture
                    if (sliderDto.Items.Count > 0)
                    {
                        articleData.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto, article.ProfilePicture);
                    }

                    _unitOfWork.ArticlesRepository.Update(articleData);
                    _unitOfWork.Commit();

                    // update files
                    if (sliderDto.Items.Count > 0)
                    {
                        _sliderManager.Update(sliderDto);
                    }

                    _logger.LogInformation($"END: Article.Update: ID:{articleId} --SUCCESS");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.OK
                    });
                }
                else
                {
                    _logger.LogInformation($"END: Article.Update: Id:{articleId} -- UNAuthorized");

                    return(new ResultMessage
                    {
                        Status = HttpStatusCode.Unauthorized
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage
                {
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }
Пример #15
0
        public ResultMessage Insert(ArticleAddDto article, IUserDto user)
        {
            _logger.LogInformation($"START: Article.Insert: Name:{article.Name}");

            var validationResult = _addValidator.Validate(article);

            if (!validationResult.IsValid)
            {
                _logger.LogInformation($"END: Article.Insert: Name:{article.Name}  --VALIDATION");
                return(new ResultMessage
                {
                    Status = HttpStatusCode.BadRequest,
                    ValidationMessages = validationResult.GetErrorsList()
                });
            }
            try
            {
                var articleEntity = article.Adapt <DBModels.Articles>();
                articleEntity.CreatedAt = DateTime.Now;
                articleEntity.CreatedBy = user.Id;

                var articleFolderName = Guid.NewGuid().ToString();

                var sliderDto = new SliderDto
                {
                    attachmentType = AttachmentTypesEnum.Articles,
                    Items          = article.UpdatedImages,
                    SubFolderName  = articleFolderName
                };

                if (sliderDto.Items.Count > 0)
                {
                    articleEntity.ProfilePicture = _sliderManager.GetProfilePicturePath(sliderDto);
                }

                articleEntity.SubFolderName = articleFolderName;
                articleEntity.Images        = null;
                articleEntity.IsActive      = null;

                if (user.IsAdmin)
                {
                    articleEntity.IsActive = true;
                }

                _unitOfWork.ArticlesRepository.Insert(articleEntity);
                _unitOfWork.Commit();

                sliderDto.ParentId = articleEntity.Id;
                _sliderManager.Add(sliderDto);

                _logger.LogInformation($"END: Article.Insert: Name:{article.Name}  --SUCCESS");

                return(new ResultMessage
                {
                    Status = HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Empty);
                return(new ResultMessage()
                {
                    ErrorCode = (int)ProductsErrorsCodeEnum.ProductsInsertError,
                    Status = HttpStatusCode.InternalServerError
                });
            }
        }