public async Task <ActionResult> AddNewDiscount(AddNewDiscount newDiscount)
        {
            if (ModelState.IsValid)
            {
                await _servicesLogic.AddDiscount(newDiscount);

                return(RedirectToAction("Index"));
            }
            SelectList services = new SelectList(_servicesLogic.GetServicesFromDb(), "ServiceId", "ServiceName");

            ViewBag.Services = services;
            return(View("AddNewDiscountWindow"));
        }
Exemplo n.º 2
0
 public async Task AddDiscount(AddNewDiscount newDiscount)
 {
     var service = await _db.Services.Include(s => s.Discount).FirstOrDefaultAsync(s => s.ServiceId == newDiscount.ServiceId);
     if (service.Discount != null)
     {
         _db.Discounts.Remove(service.Discount);
     }
     service.Discount = new Discount()
     {
         Value = newDiscount.DiscountValue,
         FinishDate = newDiscount.FinishDate,
         StartDate = newDiscount.StartDate
     };
     service.PriceWithDiscount = GetNewPriceWithDiscount(service.Price, service.Discount.Value);
     _db.Entry(service).State = EntityState.Modified;
     await _db.SaveChangesAsync();
 }