public async Task <IActionResult> Edit(string id, [FromBody] PromoDiscountCreateModel model) { return(await this.Execute(true, true, async() => { await this.promoDiscounts.Edit(id, model); return this.Ok(); })); }
public async Task <IActionResult> Create([FromBody] PromoDiscountCreateModel model) { return(await this.Execute(true, true, async() => { string promoDiscountId = await this.promoDiscounts.Create(model); return this.Ok(new { promoDiscountId = promoDiscountId }); })); }
public async Task Edit(string promoId, PromoDiscountCreateModel data) { if (data.Discount < 0 || data.Discount > 100) { throw new ArgumentException("Discount must be between 0 and 100"); } if (!await this.db.PromoDiscounts.AnyAsync(p => p.Id == promoId)) { throw new ArgumentException("Cannot find promo in DB"); } PromoDiscount promo = await this.db.PromoDiscounts.FirstOrDefaultAsync(p => p.Id == promoId); promo.Name = data.Name; promo.Discount = data.Discount; promo.EndDate = data.EndDate; promo.StartDate = data.StartDate; await this.db.SaveChangesAsync(); }
public async Task <string> Create(PromoDiscountCreateModel data) { if (data.Discount < 0 || data.Discount > 100) { throw new ArgumentException("Discount must be between 0 and 100"); } PromoDiscount discount = new PromoDiscount { Name = data.Name, Discount = data.Discount, StartDate = data.StartDate, EndDate = data.EndDate }; await this.db.PromoDiscounts .AddAsync(discount); await this.db.SaveChangesAsync(); return(discount.Id); }