/// <inheritdoc /> /// <exception cref="PromoNotFoundException">Thrown if the promo is not found</exception> public async Task <PromoViewModel> Update(UpdatePromoBody updatePromoBody) { var promo = await ApplicationContext.Promos.FirstOrDefaultAsync(x => x.Id == updatePromoBody.Id); if (promo == null) { throw new PromoNotFoundException(); } // sets values to new values promo.Active = updatePromoBody.Active; promo.Discount = updatePromoBody.Discount; promo.End = updatePromoBody.End; promo.Start = updatePromoBody.Start; try { await ApplicationContext.SaveChangesAsync(); return(Mapper.Map <PromoViewModel>(promo)); } catch (Exception ex) { Logger.LogInformation("Update exception {Exception}", ex.ToString()); throw; } }
public async Task <ActionResult <PromoViewModel> > Update(UpdatePromoBody updatePromoBody) { try { Logger.LogInformation("Updating {Id}", updatePromoBody.Id); var result = await PromoService.Update(updatePromoBody); return(result); } catch (Exception e) { Logger.LogInformation("Update exception {Exception}", e.ToString()); return(BadRequest(e)); } }