Exemplo n.º 1
0
    public async Task<ServiceResult> SaveAsync(IFormFile file, string path)
    {
      Check.NotNull(file, nameof(file));
      Check.NotNullOrEmpty(path, nameof(path));

      if (file.Length <= 0)
      {
        return ServiceResultFactory.BadRequestResult(nameof(file), "File not found.");
      }

      var relativePath = Constants.GetRelativePathToImage(path);
      var fullPath = Path.Combine(_environment.WebRootPath, relativePath);

      if (File.Exists(fullPath))
      {
        return ServiceResultFactory.BadRequestResult(nameof(path), "File already exist.");
      }

      var dirPath = Path.GetDirectoryName(fullPath);
      if (Directory.Exists(dirPath) == false)
      {
        Directory.CreateDirectory(dirPath);
      }

      using (var fileStream = new FileStream(fullPath, FileMode.Create))
      {
        await file.CopyToAsync(fileStream);
      }

      return ServiceResultFactory.Success;
    }
        public async Task <ServiceResult> Add([FromBody] InfoObjectAddModel apiEntity)
        {
            var type = Enum.Parse <InfoObjectType>(apiEntity.Type, ignoreCase: true);

            if (type == InfoObjectType.Image)
            {
                // validate file exist
                var fileExistValidationAttribute = new FileExistValidationAttribute(Constants.WEB_CONTENT_ROOT_PATH, Constants.DEFAULT_PATH_TO_IMAGE);
                var validationResult             = fileExistValidationAttribute.IsValid(apiEntity.Content);
                if (validationResult != ValidationResult.Success)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(apiEntity.Content), validationResult.ErrorMessage));
                }
            }

            var entity = InfoObjectAddModel.Map(apiEntity);

            var result = await _infoObjectService.AddAsync(entity);

            if (result.TryCastModel(out InfoObject infoObject))
            {
                result.ViewModel = InfoObjectViewModel.Map(infoObject);
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task <ServiceResult> UpdateRoleAsync(Guid id, string newRole)
        {
            Check.NotNullOrEmpty(newRole, nameof(newRole));

            var user = await this.FindByAsync(x => x.Id == id);

            if (user == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            newRole = Role.Normalize(newRole);
            if (string.IsNullOrEmpty(newRole))
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateRoleAsync), "Incorrect role name."));
            }

            user.Role         = newRole;
            user.LastModified = DateTime.UtcNow;

            _context.Users.Update(user);

            var result = await _context.SaveAsync(nameof(UpdateRoleAsync));

            result.SetModelIfSuccess(user);

            return(result);
        }
Exemplo n.º 4
0
        public async Task <ServiceResult> UpdateAsync(Order model)
        {
            Check.NotNull(model, nameof(model));

            var order = await _context.Orders.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (order == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            if (order.DateOfApproved.HasValue || order.DateOfRejected.HasValue || order.DateOfClosed.HasValue)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), $"Order is already proccessed."));
            }

            var changed = false;

            // update name
            if (Utility.IsModified(order.Name, model.Name))
            {
                order.Name = model.Name;
                changed    = true;
            }

            // update mobile
            if (Utility.IsModified(order.Mobile, model.Mobile))
            {
                order.Mobile = model.Mobile;
                changed      = true;
            }

            // update address
            if (Utility.IsModified(order.Address, model.Address))
            {
                order.Address = model.Address;
                changed       = true;
            }

            // update comment
            if (Utility.IsModified(order.Comment, model.Comment))
            {
                order.Comment = model.Comment;
                changed       = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            _context.Orders.Update(order);

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(order);

            return(result);
        }
Exemplo n.º 5
0
        public async Task <ServiceResult> UpdateAsync(MenuItem model)
        {
            Check.NotNull(model, nameof(model));

            var menuItem = await _context.MenuItems.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (menuItem == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            var changed = false;

            // update text
            if (Utility.IsModified(menuItem.Text, model.Text))
            {
                // Doesn't supported StringComparison.OrdinalIgnoreCase by SQL
                var menuItemTextExist = await _context.MenuItems.AnyAsync(x => model.Text.ToLower() == x.Text.ToLower());

                if (menuItemTextExist)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), $"MenuItem text is already exist."));
                }

                menuItem.Text = model.Text;
                changed       = true;
            }

            // update order
            if (Utility.IsModified(menuItem.Order, model.Order))
            {
                menuItem.Order = model.Order;
                changed        = true;
            }

            // update iconPath
            if (Utility.IsModified(menuItem.IconPath, model.IconPath))
            {
                menuItem.IconPath = model.IconPath;
                changed           = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            _context.MenuItems.Update(menuItem);
            _context.History.Add(ChangeHistory.Create(TableName.MenuItem, ActionType.Modify));

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(menuItem);

            return(result);
        }
        public async Task <ServiceResult> UpdateAsync(ContentGroup model)
        {
            Check.NotNull(model, nameof(model));

            var contentGroup = await _context.ContentGroups.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (contentGroup == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            var changed = false;

            // update title
            if (Utility.IsModified(contentGroup.Title, model.Title))
            {
                contentGroup.Title = model.Title;
                changed            = true;
            }

            // update order
            if (Utility.IsModified(contentGroup.Order, model.Order))
            {
                contentGroup.Order = model.Order;
                changed            = true;
            }

            // update groupname
            if (model.GroupName != contentGroup.GroupName)
            {
                contentGroup.GroupName = model.GroupName;
                changed = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            _context.ContentGroups.Update(contentGroup);
            _context.History.Add(ChangeHistory.Create(model.GroupName, ActionType.Modify));

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(contentGroup);

            return(result);
        }
Exemplo n.º 7
0
    public ServiceResult Delete(string path)
    {
      Check.NotNullOrEmpty(path, nameof(path));

      var relativePath = Constants.GetRelativePathToImage(path);
      var fullPath = Path.Combine(_environment.WebRootPath, relativePath);

      if (File.Exists(fullPath) == false)
      {
        return ServiceResultFactory.BadRequestResult(nameof(path), "File not found.");
      }

      File.Delete(fullPath);

      return ServiceResultFactory.Success;
    }
Exemplo n.º 8
0
        private ServiceResult AuthUser(AppUser user, string password)
        {
            if (user == null)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AuthenticateAsync), "Username was not found."));
            }

            var success = _passwordManager.VerifyPassword(password, user.PasswordHash, user.PasswordSalt);

            if (success == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AuthenticateAsync), "Password is wrong."));
            }

            return(ServiceResultFactory.SuccessResult(user));
        }
        public async Task UpdatePassword_Params_Valid_Result_BadRequest()
        {
            _context
            .Setup(x => x.SaveAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(ServiceResultFactory.BadRequestResult(It.IsAny <string>(), It.IsAny <string>())));

            // Arrange
            var userService = new UserService(_context.Object, _passwordManager.Object);

            // Act
            var result = await userService.UpdatePasswordAsync(_data.First().Id, Constants.PASSWORD);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(ServiceResultKey.BadRequest, result.Key);
            Assert.NotEmpty(result.Errors);
        }
        public async Task Delete_Id_Valid_Result_BadRequest()
        {
            _context
            .Setup(x => x.SaveAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(ServiceResultFactory.BadRequestResult(It.IsAny <string>(), It.IsAny <string>())));

            // Arrange
            var userService = new UserService(_context.Object, null);

            // Act
            var result = await userService.DeleteAsync(_data.First().Id);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(ServiceResultKey.BadRequest, result.Key);
            Assert.NotEmpty(result.Errors);
        }
Exemplo n.º 11
0
        private async Task <ServiceResult> CloseAsync(Order order, Guid userId)
        {
            if (order.DateOfClosed.HasValue)
            {
                return(ServiceResultFactory.Success);
            }

            if (order.DateOfApproved.HasValue == false && order.DateOfRejected.HasValue == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(CloseAsync), "Order should be approved or rejected."));
            }

            order.DateOfClosed = DateTime.UtcNow;
            order.CloseUserId  = userId;

            _context.Orders.Update(order);

            return(await _context.SaveAsync(nameof(CloseAsync)));
        }
Exemplo n.º 12
0
        public async Task <ServiceResult> AddAsync(ShopItemDetail model)
        {
            Check.NotNull(model, nameof(model));

            var shopItemExist = await _context.ShopItems.AnyAsync(x => x.Id == model.ShopItemId);

            if (shopItemExist == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AddAsync), $"ShopItem not found with id: '{model.ShopItemId}'."));
            }

            _context.ShopItemDetails.Add(model);

            var result = await _context.SaveAsync(nameof(AddAsync));

            result.SetModelIfSuccess(model);

            return(result);
        }
Exemplo n.º 13
0
        public async Task <ServiceResult> AddAsync(Order model)
        {
            Check.NotNull(model, nameof(model));

            var cartExist = await _context.Carts.AnyAsync(x => x.Id == model.CartId);

            if (cartExist == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AddAsync), $"Cart not found with id: '{model.CartId}'."));
            }

            _context.Orders.Add(model);

            var result = await _context.SaveAsync(nameof(AddAsync));

            result.SetModelIfSuccess(model);

            return(result);
        }
Exemplo n.º 14
0
        public async Task <ServiceResult> ProccessOrderAsync(ProcessOrderType processOrder, Guid id, Guid userId)
        {
            var userExist = await _context.Users.AnyAsync(x => x.Id == userId);

            if (userExist == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(ProccessOrderAsync), "User not found."));
            }

            var order = await this.FindByAsync(x => x.Id == id);

            if (order == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            ServiceResult result;

            switch (processOrder)
            {
            case ProcessOrderType.Approve:
                result = await this.ApproveAsync(order, userId);

                break;

            case ProcessOrderType.Reject:
                result = await this.RejectAsync(order, userId);

                break;

            case ProcessOrderType.Close:
                result = await this.CloseAsync(order, userId);

                break;

            default:
                throw new NotImplementedException(nameof(ProcessOrderType));
            }

            result.SetModelIfSuccess(order);

            return(result);
        }
        public async Task <ServiceResult> AddAsync(InfoObject model)
        {
            Check.NotNull(model, nameof(model));

            var contentGroupExist = await _context.ContentGroups.AnyAsync(x => x.Id == model.ContentGroupId);

            if (contentGroupExist == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(model.ContentGroupId), $"ContentGroup not found with id: '{model.ContentGroupId}'."));
            }

            _context.InfoObjects.Add(model);
            _context.History.Add(ChangeHistory.Create(TableName.InfoObject, ActionType.Add));

            var result = await _context.SaveAsync(nameof(AddAsync));

            result.SetModelIfSuccess(model);

            return(result);
        }
Exemplo n.º 16
0
        public async Task <ServiceResult> SaveAsync(string code)
        {
            try
            {
                await this.SaveChangesAsync();

                return(ServiceResultFactory.Success);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(ServiceResultFactory.BadRequestResult(code, ex.InnerException.Message));
            }
            catch (DbUpdateException ex)
            {
                return(ServiceResultFactory.BadRequestResult(code, ex.InnerException.Message));
            }
            catch (Exception ex)
            {
                return(ServiceResultFactory.InternalServerErrorResult(ex.InnerException.Message));
            }
        }
Exemplo n.º 17
0
        public async Task <ServiceResult> AddAsync(AppUser model, string password)
        {
            Check.NotNull(model, nameof(model));
            Check.NotNullOrEmpty(model.Username, nameof(model.Username));
            Check.NotNullOrEmpty(model.Email, nameof(model.Email));
            Check.NotNullOrEmpty(password, nameof(password));

            // Doesn't supported StringComparison.OrdinalIgnoreCase by SQL
            var usernameExist = await this.ExistAsync(x => model.Username.ToLower() == x.Username.ToLower());

            if (usernameExist)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AddAsync), "Username is already taken."));
            }

            var emailExist = await this.ExistAsync(x => model.Email.ToLower() == x.Email.ToLower());

            if (emailExist)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AddAsync), "Email is already taken."));
            }

            model.Role = Role.Normalize(model.Role);
            if (string.IsNullOrEmpty(model.Role))
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AddAsync), "Incorrect role name."));
            }

            var(passwordHash, passwordSalt) = _passwordManager.CreatePasswordHash(password);
            model.PasswordHash = passwordHash;
            model.PasswordSalt = passwordSalt;

            _context.Users.Add(model);

            var result = await _context.SaveAsync(nameof(AddAsync));

            result.SetModelIfSuccess(model);

            return(result);
        }
Exemplo n.º 18
0
        public async Task <ServiceResult> AddAsync(MenuItem model)
        {
            Check.NotNull(model, nameof(model));
            Check.NotNullOrEmpty(model.Text, nameof(model.Text));

            // Doesn't supported StringComparison.OrdinalIgnoreCase by SQL
            var menuItemExist = await this.ExistAsync(x => model.Text.ToLower() == x.Text.ToLower());

            if (menuItemExist)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(AddAsync), $"MenuItem text already exist."));
            }

            _context.MenuItems.Add(model);
            _context.History.Add(ChangeHistory.Create(TableName.MenuItem, ActionType.Add));

            var result = await _context.SaveAsync(nameof(AddAsync));

            result.SetModelIfSuccess(model);

            return(result);
        }
        public async Task Add_Model_Valid_Result_BadRequest()
        {
            _context
            .Setup(x => x.SaveAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(ServiceResultFactory.BadRequestResult(It.IsAny <string>(), It.IsAny <string>())));

            // Arrange
            var userService = new UserService(_context.Object, _passwordManager.Object);
            var user        = new AppUser
            {
                Username = "******",
                Email    = "*****@*****.**",
                Role     = Role.Admin
            };

            // Act
            var result = await userService.AddAsync(user, Constants.PASSWORD);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(ServiceResultKey.BadRequest, result.Key);
            Assert.NotEmpty(result.Errors);
        }
        public async Task <ServiceResult> Edit(Guid id, [FromBody] InfoObjectEditModel apiEntity)
        {
            if (string.Equals(apiEntity.Type, InfoObjectType.Image.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                // validate file exist
                var fileExistValidationAttribute = new FileExistValidationAttribute(Constants.WEB_CONTENT_ROOT_PATH, Constants.DEFAULT_PATH_TO_IMAGE);
                var validationResult             = fileExistValidationAttribute.IsValid(apiEntity.Content);
                if (validationResult != ValidationResult.Success)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(apiEntity.Content), validationResult.ErrorMessage));
                }
            }

            var entity = InfoObjectEditModel.Map(apiEntity, id);

            var result = await _infoObjectService.UpdateAsync(entity);

            if (result.TryCastModel(out InfoObject infoObject))
            {
                result.ViewModel = InfoObjectViewModel.Map(infoObject);
            }

            return(result);
        }
Exemplo n.º 21
0
        private async Task <ServiceResult> RejectAsync(Order order, Guid userId)
        {
            if (order.DateOfRejected.HasValue)
            {
                return(ServiceResultFactory.Success);
            }

            if (order.DateOfApproved.HasValue)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(RejectAsync), "Order is already approved."));
            }

            if (order.DateOfClosed.HasValue)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(RejectAsync), "Order is already closed."));
            }

            order.DateOfRejected = DateTime.UtcNow;
            order.RejectUserId   = userId;

            _context.Orders.Update(order);

            return(await _context.SaveAsync(nameof(RejectAsync)));
        }
Exemplo n.º 22
0
        public async Task <ServiceResult> UpdateAsync(AppUser model)
        {
            Check.NotNull(model, nameof(model));

            var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (user == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            var changed = false;

            // update username
            if (Utility.IsModified(user.Username, model.Username))
            {
                var usernameExist = await this.ExistAsync(x => x.Username == model.Username);

                if (usernameExist)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Username is already taken."));
                }

                user.Username = model.Username;
                changed       = true;
            }

            // update email
            if (Utility.IsModified(user.Email, model.Email))
            {
                var emailExist = await this.ExistAsync(x => x.Email == model.Email);

                if (emailExist)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Email is already taken."));
                }

                user.Email          = model.Email;
                user.EmailConfirmed = false;
                changed             = true;
            }

            // update firstname
            if (Utility.IsModified(user.FirstName, model.FirstName))
            {
                user.FirstName = model.FirstName;
                changed        = true;
            }

            // update lastname
            if (Utility.IsModified(user.LastName, model.LastName))
            {
                user.LastName = model.LastName;
                changed       = true;
            }

            // update phonenumber
            if (Utility.IsModified(user.PhoneNumber, model.PhoneNumber))
            {
                user.PhoneNumber = model.PhoneNumber;
                changed          = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            user.LastModified = DateTime.UtcNow;
            _context.Users.Update(user);

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(user);

            return(result);
        }
        public async Task <ServiceResult> UpdateAsync(InfoObject model)
        {
            Check.NotNull(model, nameof(model));

            var infoObject = await _context.InfoObjects.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (infoObject == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            var changed = false;

            // update contentGroup
            if (Utility.IsModified(infoObject.ContentGroupId, model.ContentGroupId))
            {
                var contentGroupExist = await _context.ContentGroups.AnyAsync(x => x.Id == model.ContentGroupId);

                if (contentGroupExist == false)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(model.ContentGroupId), $"ContentGroup not found with id: '{model.ContentGroupId}'."));
                }

                infoObject.ContentGroupId = model.ContentGroupId;
                changed = true;
            }

            // update content
            if (Utility.IsModified(infoObject.Content, model.Content))
            {
                infoObject.Content = model.Content;
                changed            = true;
            }

            // update type
            if (model.Type != infoObject.Type)
            {
                infoObject.Type = model.Type;
                changed         = true;
            }

            // update subOrder
            if (Utility.IsModified(infoObject.SubOrder, model.SubOrder))
            {
                infoObject.SubOrder = model.SubOrder;
                changed             = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            _context.InfoObjects.Update(infoObject);
            _context.History.Add(ChangeHistory.Create(TableName.InfoObject, ActionType.Modify));

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(infoObject);

            return(result);
        }
Exemplo n.º 24
0
        public async Task <ServiceResult> UpdateAsync(ShopItemDetail model)
        {
            Check.NotNull(model, nameof(model));

            var shopItemDetail = await _context.ShopItemDetails.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (shopItemDetail == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            var changed = false;

            // update shopItem
            if (Utility.IsModified(shopItemDetail.ShopItemId, model.ShopItemId))
            {
                var shopItemExist = await _context.ShopItems.AnyAsync(x => x.Id == model.ShopItemId);

                if (shopItemExist == false)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), $"ShopItem not found with id: '{model.ShopItemId}'."));
                }

                shopItemDetail.ShopItemId = model.ShopItemId;
                changed = true;
            }

            // update suborder
            if (Utility.IsModified(shopItemDetail.SubOrder, model.SubOrder))
            {
                shopItemDetail.SubOrder = model.SubOrder;
                changed = true;
            }

            // update price
            if (Utility.IsModified(shopItemDetail.Price, model.Price))
            {
                shopItemDetail.Price = model.Price;
                changed = true;
            }

            // update kind
            if (Utility.IsModified(shopItemDetail.Kind, model.Kind))
            {
                shopItemDetail.Kind = model.Kind;
                changed             = true;
            }

            // update quantity
            if (Utility.IsModified(shopItemDetail.Quantity, model.Quantity))
            {
                shopItemDetail.Quantity = model.Quantity;
                changed = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            _context.ShopItemDetails.Update(shopItemDetail);

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(shopItemDetail);

            return(result);
        }
Exemplo n.º 25
0
        public async Task <ServiceResult> UpdateAsync(ShopItem model)
        {
            Check.NotNull(model, nameof(model));

            var shopItem = await _context.ShopItems.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (shopItem == null)
            {
                return(ServiceResultFactory.NotFound);
            }

            var changed = false;

            // update menuItem
            if (Utility.IsModified(shopItem.MenuItemId, model.MenuItemId))
            {
                var menuItemExist = await _context.MenuItems.AnyAsync(x => x.Id == model.MenuItemId);

                if (menuItemExist == false)
                {
                    return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), $"MenuItem not found with id: '{model.MenuItemId}'."));
                }

                shopItem.MenuItemId = model.MenuItemId;
                changed             = true;
            }

            // update title
            if (Utility.IsModified(shopItem.Title, model.Title))
            {
                shopItem.Title = model.Title;
                changed        = true;
            }

            // update description
            if (Utility.IsModified(shopItem.Description, model.Description))
            {
                shopItem.Description = model.Description;
                changed = true;
            }

            // update imagepath
            if (Utility.IsModified(shopItem.ImagePath, model.ImagePath))
            {
                shopItem.ImagePath = model.ImagePath;
                changed            = true;
            }

            if (changed == false)
            {
                return(ServiceResultFactory.BadRequestResult(nameof(UpdateAsync), "Nothing to update."));
            }

            _context.ShopItems.Update(shopItem);

            var result = await _context.SaveAsync(nameof(UpdateAsync));

            result.SetModelIfSuccess(shopItem);

            return(result);
        }