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()); } }
public void Update(UpdateInventoryDto updatedProduct) { _dbContext.ValidateData(updatedProduct); var product = _dbContext.Inventory.SingleOrDefault(o => o.ProductID == updatedProduct.ProductID); product.Merge(updatedProduct); _dbContext.SaveChanges(); }
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; }
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); } }
public ActionResult ChangeInventoryStatus([FromBody] UpdateInventoryDto dto) { _inventoryService.UpdateInventory(dto); return(Ok()); }