public async Task <API.Models.Voucher.VoucherRequestModel> GetById(int id)
        {
            API.Models.Voucher.VoucherRequestModel response;
            var voucher = await _voucherService.GetById(id);

            if (voucher != null)
            {
                response = new VoucherRequestModel
                {
                    VoucherId   = (long)voucher.VoucherId,
                    VoucherCode = voucher.VoucherCode,
                    StartDate   = voucher.StartDate,
                    EndDate     = voucher.EndDate,
                    Price       = voucher.Price
                };
            }
            else
            {
                response = new VoucherRequestModel
                {
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddMonths(3),
                };
            }

            return(response);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetById(string idVoucher)
        {
            var Voucher = await _VoucherService.GetById(idVoucher);

            if (Voucher == null)
            {
                return(BadRequest("Cannot find Voucher"));
            }
            return(Ok(Voucher));
        }
Exemplo n.º 3
0
        public ActionResult <Voucher> GetVoucher(int id)
        {
            var entity = _voucherSer.GetById(id);

            if (entity == null)
            {
                return(NotFound());
            }
            return(Ok(entity));
        }
Exemplo n.º 4
0
        public ActionResult ApplyDeal(int dealId)
        {
            var getVoucherById = _voucherService.GetById(dealId);

            if (getVoucherById.HasError)
            {
                return(Redirect("/Deals"));
            }

            _userSessionService.SelectDeal(Session["UserId"].ToString(), VoucherDetailsMapper.Map(
                                               new List <VoucherDetails>
            {
                new VoucherDetails
                {
                    Voucher = getVoucherById.Voucher,
                    AllowedDeliveryTypes = getVoucherById.AllowedDeliveryTypes,
                    AllowedSizes         = getVoucherById.AllowedSizes
                }
            })[0]);
            return(Redirect("/Deals"));
        }
Exemplo n.º 5
0
        public IHttpActionResult ApplyDeal([FromBody] ApplyDealRequest request)
        {
            var getVoucherById = _voucherService.GetById(request.DealId);

            if (getVoucherById.HasError)
            {
                return(BadRequest());
            }

            _userSessionService.SelectDeal(request.UserToken, VoucherDetailsMapper.Map(
                                               new List <VoucherDetails>
            {
                new VoucherDetails
                {
                    Voucher = getVoucherById.Voucher,
                    AllowedDeliveryTypes = getVoucherById.AllowedDeliveryTypes,
                    AllowedSizes         = getVoucherById.AllowedSizes
                }
            })[0]);

            return(Ok(_userSessionService.GetVoucherForUser(request.UserToken)));
        }