示例#1
0
        public static void ValidateData(this IHDSContext context, UpdateInventoryDto dto)
        {
            var errors = new StringBuilder();

            // ProductID
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.ProductIDRequired));
            errors.AddIfExists(context.KeyExists <Inventory>(dto.ProductID, ValidationMessages.ProductIDNotFound));
            // Model
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.ModelRequired));
            errors.AddIfExists(dto.Model.ValidateLength(100, ValidationMessages.ModelLength));
            // Brand
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.BrandRequired));
            errors.AddIfExists(dto.Model.ValidateLength(100, ValidationMessages.BrandLength));
            // SerialNumber
            errors.AddIfExists(dto.Model.ValidateLength(100, ValidationMessages.SerialNumberLength));
            // ProductDescription
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.ProductDescriptionRequired));
            errors.AddIfExists(dto.Model.ValidateLength(1000, ValidationMessages.ProductDescriptionLength));
            // Cost
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.CostRequired));
            // Price
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.PriceRequired));
            // LocationID
            errors.AddIfExists(dto.Model.ValidateRequired(ValidationMessages.StoreIDRequired));
            errors.AddIfExists(context.KeyExists <Store>(dto.LocationID, ValidationMessages.StoreIDNotFound));

            if (errors.Length > 0)
            {
                throw new ValidationException(errors.ToString());
            }
        }
示例#2
0
        public void Update(UpdateInventoryDto updatedProduct)
        {
            _dbContext.ValidateData(updatedProduct);
            var product = _dbContext.Inventory.SingleOrDefault(o => o.ProductID == updatedProduct.ProductID);

            product.Merge(updatedProduct);

            _dbContext.SaveChanges();
        }
示例#3
0
 public static void Merge(this Inventory entity, UpdateInventoryDto dto)
 {
     entity.Model = dto.Model;
     entity.Brand = dto.Brand;
     entity.ProductDescription = dto.ProductDescription;
     entity.LocationID         = dto.LocationID;
     entity.SerialNumber       = dto.SerialNumber;
     entity.Cost    = dto.Cost;
     entity.Price   = dto.Price;
     entity.Updated = DateTime.UtcNow;
 }
示例#4
0
        public IActionResult UpdateDetails([Required][FromBody] UpdateInventoryDto updatedProduct)
        {
            try
            {
                _repo.Update(updatedProduct);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
        public void UpdateInventory(UpdateInventoryDto updateInventoryDto)
        {
            InventoryEventDto eventDto = null;

            try
            {
                var inventoryDto = _inventoryDao.GetInventoryById(updateInventoryDto.InventoryId);

                inventoryDto.StatusId = updateInventoryDto.NewStatusId;

                eventDto = new InventoryEventDto
                {
                    Description = "Inventory action",
                    EventDate   = DateTime.Now,
                    EventType   = (int)InventoryEventTypeEnum.InventoryStarted,
                    InventoryId = updateInventoryDto.InventoryId
                };

                if (updateInventoryDto.NewStatusId == 3)
                {
                    eventDto.EventType = (int)InventoryEventTypeEnum.InventoryEnded;
                    CreateReport(updateInventoryDto.InventoryId);
                }
                else if (updateInventoryDto.NewStatusId == 4)
                {
                    eventDto.EventType = (int)InventoryEventTypeEnum.InventoryCancelled;
                }

                _inventoryDao.UpdateInventory(inventoryDto);
                _inventoryDao.RemoveAllUsersFromInventory(inventoryDto.Id);
            }
            catch (Exception e)
            {
                eventDto = new InventoryEventDto
                {
                    Description = e.Message,
                    EventDate   = DateTime.Now,
                    InventoryId = 0,
                    EventType   = (int)InventoryEventTypeEnum.UnknownError
                };
            }
            finally
            {
                _inventoryDao.AddInventoryEvent(eventDto);
            }
        }
示例#6
0
 public ActionResult ChangeInventoryStatus([FromBody] UpdateInventoryDto dto)
 {
     _inventoryService.UpdateInventory(dto);
     return(Ok());
 }