public IEnumerable <Promotion> GetPromotion(PromotionQueryRequest <dynamic> request) { var promotion = GetPromotion(); if (request.PromotionID != null) { promotion = promotion.Where(p => p.PromotionID == request.PromotionID); } if (request.PromotionCode != null) { promotion = promotion.Where(p => p.PromotionCode == request.PromotionCode); } //if (request.AvailableOnly) //{ // if (membership == null) // throw ApiException.Get(false, "Thiếu thông tin thành viên", ResultEnum.CustomerNotFound, HttpStatusCode.BadRequest); // promotion = promotion.Where(p => // (!p.IsVoucher.Value && p.IsForMember && // CheckMembership(p, GetPromotionDetailsByPromotion(p.PromotionCode), membership).Success) // || (p.IsVoucher.Value && p.VoucherQuantity > 1 && p.VoucherUsedQuantity < p.VoucherQuantity) // || (p.VoucherQuantity == 1 && // GetVoucher(v => v.PromotionID == p.PromotionID).FirstOrDefault().MembershipId == membership.Id) // ); //} //else if (request.UsedOnly) //{ // if (membership == null) // throw ApiException.Get(false, "Thiếu thông tin thành viên", ResultEnum.CustomerNotFound, HttpStatusCode.BadRequest); // promotion = promotion.Where(p => // p.Vouchers.Where(v => v.MembershipId == membership.Id && v.isUsed.Value).Any() // ); //} return(promotion); }
//[Route("{PromotionID?}")] //[HttpGet] public HttpResponseMessage GetPromotion(PromotionQueryRequest <dynamic> request) { var response = new BaseResponse <dynamic>(); var claimPrincipal = (ClaimsPrincipal)RequestContext.Principal; var customerId = claimPrincipal.Claims.Where(c => c.Type == "CustomerId").Select(c => c.Value).SingleOrDefault(); var cDomain = new CustomerDomain(); var id = Int32.Parse(customerId); var customer = cDomain.GetCustomerById(id); var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; var pDomain = new PromotionDomain(); Membership member = customer.MembershipVM.ToEntity(); request.Membership = member; var promotion = pDomain.GetPromotion(request).ToList(); if (promotion.Count == 0) { var res = BaseResponse <dynamic> .Get(false, "Không tìm thấy khuyến mãi nào", null, ResultEnum.PromotionNotFound); resp.Content = new JsonContent(res); resp.StatusCode = HttpStatusCode.NotFound; return(resp); } try { response = BaseResponse <dynamic> .Get(false, "Thành công", null, ResultEnum.Success); if (promotion.Count == 1) { response.Data = promotion.FirstOrDefault(); } else { response.Data = promotion; } } catch (ApiException e) { resp.StatusCode = e.StatusCode; response = BaseResponse <dynamic> .Get(e.Success, e.ErrorMessage, null, e.ErrorStatus); } catch (Exception e) { response = BaseResponse <dynamic> .Get(false, e.Message, null, ResultEnum.InternalError); resp.StatusCode = HttpStatusCode.InternalServerError; } resp.Content = new JsonContent(response); return(resp); }