public static CouponManagement CreateCouponManagement(CouponCreateOrEditRequestModel request) { var coupon = new CouponManagement { Id = request.Id, Description = request.Description, DiscountAmount = request.DiscountAmount, DiscountType = request.DiscountType, IsInfinite = request.IsInfinite, IsBulk = request.IsBulk, IsForOneUse = request.IsForOneUse, UpdatedAt = DateTime.UtcNow.ToLocalTime(), isForB = request.isForB, isForA = request.isForA }; if (!request.IsBulk) { coupon.Codes = new List <CouponCode> { new CouponCode { Code = request.Code, IsActive = request.IsActive } }; } if (!request.IsInfinite) { coupon.ExpireDate = request.ExpireDate; } return(coupon); }
public async Task <IActionResult> Create(string userid, CouponCreateOrEditRequestModel request) { try { var model = CouponModelFactory.CreateCouponManagement(request); var result = await _repos.CreateAsync(model, userid, request.Quantity, request.CouponLength); if (result.Status != RepositoryActionStatus.Created) { return(Ok(new ApiResultError("Hata Oluştu:" + result.Message))); } var dto = CouponModelFactory.CreateCouponDTO(result.Entity); return(Ok(dto)); } catch (Exception ex) { return(ReturnErrorApiResult(ex)); } }
public IActionResult EditPost(string userid, CouponCreateOrEditRequestModel viewModel) { try { var model = CouponModelFactory.CreateCouponManagement(viewModel); model.UpdatedBy = userid; var result = _repos.Update(model); if (result.Status != RepositoryActionStatus.Updated) { return(Ok(new ApiResultError("Hata Oluştu:" + result.Message))); } var dto = CouponModelFactory.EditCouponDTO(result.Entity); return(Ok(dto)); } catch (Exception ex) { return(ReturnErrorApiResult(ex)); } }