public ActionResult Edit(DiscountCreateDTO req) { Response res = new Response(); if (ModelState.IsValid) { try { if (req.Id > 0) { res.Data = _discountRepository.Update(req); } else { var currentUser = OperatorProvider.Provider.GetCurrent(); req.CompanyId = currentUser.CompanyId.ToInt(); res.Data = _discountRepository.Create(req); } } catch (Exception ex) { res.Data = false; res.Message = ex.Message; } } else { res.Data = false; res.Message = string.Join(",", ModelState .SelectMany(ms => ms.Value.Errors) .Select(e => e.ErrorMessage)); } return(Json(res, JsonRequestBehavior.AllowGet)); }
public IActionResult AddDiscount(Discount discount) { if (ModelState.IsValid) { repo.Create(discount); return(RedirectToAction("Index")); } return(View(discount)); }
public override async Task <CouponModel> CreateDiscount(CreateDiscountRequest request, ServerCallContext context) { var coupon = _mapper.Map <Coupon>(request.Coupon); await _discountRepository.Create(coupon); _logger.LogInformation("Discount is created for ProductName : {productName}", coupon.ProductName); var couponModel = _mapper.Map <CouponModel>(coupon); return(couponModel); }
public ActionResult Create(Discount discount) { try { _discountRep.Create(discount); _discountRep.Save(); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task<ActionResult<Coupon>> CreateDiscount([FromBody] Coupon coupon) { await _repository.Create(coupon); return CreatedAtRoute("GetDiscount", new { productName = coupon.ProductName }, coupon); }