public async Task Handle(UpdateRaffleItemCommand notification, CancellationToken cancellationToken) { var existingRafflItem = repository.GetById(notification.Id); if (NoChange(existingRafflItem, notification)) { return; } const string query = "UPDATE [RaffleItems] SET" + " ItemNumber = @ItemNumber, " + " Title = @Title," + " Description = @Description," + " ImageUrl = @ImageUrl," + " Category = @Category," + " Sponsor = @Sponsor," + " ItemValue = @ItemValue," + " Cost = @Cost," + " IsAvailable = @IsAvailable, " + " ForOver21 = @ForOver21, " + " LocalPickupOnly = @LocalPickupOnly," + " NumberOfDraws = @NumberOfDraws," + " WinningTickets = @WinningTickets, " + " UpdatedDate = GETUTCDATE() " + "WHERE Id = @Id"; using (var conn = new SqlConnection(connectionString)) { await conn.ExecuteAsync(query, notification); var raffleItem = repository.GetById(notification.Id); await mediator.Publish(new RaffleItemUpdated { RaffleItem = raffleItem }, cancellationToken); } }
public IActionResult Update(int id) { var raffleItem = raffleItemRepository.GetById(id); var model = new RaffleItemUpdateModel { Id = id, ItemNumber = raffleItem.ItemNumber, Title = raffleItem.Title, Description = raffleItem.Description, Category = raffleItem.Category, Sponsor = raffleItem.Sponsor, ItemValue = raffleItem.ItemValue, Cost = raffleItem.Cost, IsAvailable = raffleItem.IsAvailable, ForOver21 = raffleItem.ForOver21, LocalPickupOnly = raffleItem.LocalPickupOnly, NumberOfDraws = raffleItem.NumberOfDraws, Order = raffleItem.Order, WinningTickets = raffleItem.WinningTickets }; return(View("RaffleItemUpdate", model)); }
public RaffleItem GetById(int id) { return(repository.GetById(id)); }