public ICommandResult Handle(GetGroceriesCommand command) { var groceries = _groceriesRepository.GetById(command.Id); if (groceries == null) { AddNotification(new Notification("Groceries", "not found!")); return(null); } return(new GetGroceriesCommandResult(groceries.Id, groceries.Name, groceries.Price, groceries.Unity, groceries.Category)); }
public ICommandResult Handle(DeleteGroceriesCommand command) { var groceries = _groceriesRepository.GetById(command.Id); if (groceries == null) { AddNotification(new Notification("Id", "not found!")); return(null); } if (IsValid()) { _groceriesRepository.Delete(command.Id); } return(new DeleteGroceriesCommandResult(groceries.Id, groceries.Name)); }
public ICommandResult Handle(UpdateGroceriesCommand command) { var groceries = _groceriesRepository.GetById(command.Id); if (groceries == null) { AddNotification(new Notification("Id", "not found!")); return(null); } groceries.Update(command.Name, command.Price, command.Unity, command.Category); AddNotifications(groceries.Notifications); if (IsValid()) { _groceriesRepository.Update(groceries); } return(new UpdateGroceriesCommandResult(groceries.Id, groceries.Name, groceries.Price, groceries.Unity, groceries.Category)); }