public async Task <IActionResult> PostAsync([FromBody] CouponRequest model, CancellationToken token) { var userId = _userManager.GetLongUserId(User); try { var command = new CreateCouponCommand(model.Code, model.CouponType, userId, model.Value, model.Expiration); await _commandBus.DispatchAsync(command, token); } catch (DuplicateRowException) { return(BadRequest("This coupon already exists")); } catch (SqlConstraintViolationException) { return(BadRequest("User need to be a tutor")); } catch (ArgumentOutOfRangeException) { return(BadRequest("Inavlid Value")); } catch (ArgumentException) { return(BadRequest("Value can not be more then 100%")); } return(Ok()); }
public CouponResponse Create(CouponRequest coupon) { IRestRequest request = this.CreateRequest(this.Resource, Method.POST); request.AddBody(coupon); return(this.ExecuteRequest <CouponResponse>(request).Data); }
public virtual async Task <IHttpActionResult> RemoveCouponAsync(CouponRequest request) { if (request == null) { return(BadRequest("No request found.")); } var checkoutUrl = GetCheckoutUrl(); var homepageUrl = GetHomepageUrl(); var vm = await CouponViewService.RemoveCouponAsync(new CouponParam { CartName = CartConfiguration.ShoppingCartName, Scope = ComposerContext.Scope, CouponCode = request.CouponCode, CultureInfo = ComposerContext.CultureInfo, CustomerId = ComposerContext.CustomerId, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString() }); SetCheckoutUrl(vm, checkoutUrl); SetHomepageUrl(vm, homepageUrl); SetEditCartUrl(vm); return(Ok(vm)); }
/// <summary> /// 分页获取奖学金列表 /// <para>作 者:郭伟佳</para> /// <para>创建时间:2018-12-20</para> /// </summary> /// <param name="schoolId">校区Id</param> /// <param name="request">奖学金请求对象</param> /// <returns>奖学金分页列表</returns> public PageResult <TblDctCoupon> GetCouponList(string schoolId, CouponRequest request) { var result = base.LoadQueryable() .Where(x => x.SchoolId == schoolId && x.StudentId == request.StudentId && x.Status != (int)AMS.Dto.Enum.CouponStatus.Invalid) .OrderBy(x => x.Status).ThenByDescending(x => x.CreateTime); return(result.ToPagerSource(request.PageIndex, request.PageSize)); }
public HttpResponseMessage CreateOrUpdate(CouponRequest couponRequest) { string apiName = "CreateOrUpdate(CouponRequest couponRequest=\n{" + couponRequest + "})"; var guid = Guid.NewGuid(); logger.Info("Guid: \"{0}\" api/{1}/{2} was invoked", guid, controllerName, apiName); ICouponRepository couponRepository = new CouponRepository(); try { var couponToUpdate = couponRepository.GetByNameAndCompanyId(couponRequest.Name, couponRequest.CompanyId); if (couponToUpdate == null) {//Create logger.Info("Guid: \"{0}\" Start Creating new Coupon", guid); var newCoupon = new Coupons.DAL.Coupons { Name = couponRequest.Name, CompanyId = couponRequest.CompanyId, Start_Date = couponRequest.Start_date, End_Date = couponRequest.End_date, Amount = couponRequest.Amount, Type = couponRequest.Type, Message = couponRequest.Message, Price = couponRequest.Price, Image = couponRequest.Image }; couponRepository.Create(newCoupon); return(CreateResponseMessage(newCoupon)); } else {//Update logger.Info("Guid: \"{0}\" Start Updating Coupon", guid); couponToUpdate.Name = couponRequest.Name; couponToUpdate.CompanyId = couponRequest.CompanyId; couponToUpdate.Start_Date = couponRequest.Start_date; couponToUpdate.End_Date = couponRequest.End_date; couponToUpdate.Amount = couponRequest.Amount; couponToUpdate.Type = couponRequest.Type; couponToUpdate.Message = couponRequest.Message; couponToUpdate.Price = couponRequest.Price; couponToUpdate.Image = couponRequest.Image; couponRepository.SaveChanges(); return(CreateResponseMessage(couponToUpdate)); } } catch (Exception ex) { logger.Error("Guid: \"{0}\" General Error: {1}", guid, ex); return(CreateGeneralResultMessage(ex.ToString(), false, ApiStatusCodes.InternalServerError)); } }
public async Task Teste() { var body = new CouponRequest { Coupon = new Coupon { Code = "coupon-0001" } }; var resulta = await WC.Signature.ConsultCoupon("coupon-0001"); var result = await WC.Signature.AssociateCouponForExistingSignature(body, "assinatura01"); }
public CouponServiceResponse <Coupon> GetCoupons(CouponRequest req, List <ServiceLogRecord> logRecords = null) { var response = new CouponServiceResponse <Coupon>(); var Coupons = new List <Coupon>(); #region [ Envelope settings ] // Create the including fields according to the envelope var includes = new List <string>(); #endregion #region [ Filters ] // Check for filters Expression <Func <Coupon, bool> > filterPredicate = PredicateBuilder.New <Coupon>(true); // Add the filters if (req.CouponIDs.Any()) { filterPredicate = filterPredicate.And(r => req.CouponIDs.Contains(r.CouponID)); } if (req.OwnerIDs.Any()) { filterPredicate = filterPredicate.And(m => req.OwnerIDs.Contains(m.OwnerID)); } if (req.CampaignIDs.Any()) { filterPredicate = filterPredicate.And(m => req.CampaignIDs.Contains(m.CampaignID)); } #endregion // Make the query if (filterPredicate.Parameters.Count > 0) { Coupons = _couponServiceBase.GetIncluding(filterPredicate, includes.ToArray()).Result; } else { Coupons = _couponServiceBase.GetAllIncluding(includes.ToArray()).Result; } response.Type = Headstone.Common.ServiceResponseTypes.Success; response.Result = Coupons; return(response); }
public async Task <HttpResponseMessage> GetCouponDiscount(CouponRequest couponRequest) { httpResponseMessage = new HttpResponseMessage(); if (couponRequest != null && ModelState.IsValid) { var couponDiscountResponse = await _ICommonService.GetCouponDiscount(couponRequest); httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, couponDiscountResponse); } else { httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, new { Message = CustomErrorMessages.INVALID_INPUTS, Success = false }); } return(httpResponseMessage); }
/// <summary> /// 获取奖学金券列表 /// <para>作 者:郭伟佳</para> /// <para>创建时间:2018-11-06</para> /// </summary> /// <param name="request">奖学金查询条件</param> /// <returns>获取奖学金券分页列表</returns> public PageResult <CouponInfoListResponse> GetCouponList(CouponRequest request) { var result = new PageResult <CouponInfoListResponse>() { Data = new List <CouponInfoListResponse>() }; var couponList = _tblDctCouponRepository.Value.GetCouponList(this._schoolId, request); if (couponList != null && couponList.Data != null && couponList.Data.Count > 0) { result.Data = Mapper.Map <List <CouponInfoListResponse> >(couponList.Data); result.CurrentPage = couponList.CurrentPage; result.PageSize = couponList.PageSize; result.TotalData = couponList.TotalData; } return(result); }
/// <summary> /// Associar Cupom para Nova Assinatura - Associate Coupon For New Signature /// </summary> /// <param name="body"></param> /// <param name="true_or_false">Caso queira criar um novo Assinante o valor desse ser "true", caso contrário "false".</param> /// <returns></returns> public async Task <CouponResponse> AssociateCouponForNewSignature(CouponRequest body, string true_or_false) { string json; try { json = JsonConvert.SerializeObject(body); JObject jObject = JObject.Parse(json); if (jObject["customer"]["address"] != null) { if (jObject["customer"]["address"]["streetNumber"] != null) { jObject["customer"]["address"]["streetNumber"].Rename("number"); } if (jObject["customer"]["address"]["zipCode"] != null) { jObject["customer"]["address"]["zipCode"].Rename("zipcode"); } } json = jObject.ToString(); } catch (System.Exception ex) { throw ex; } StringContent stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); HttpResponseMessage response = await Http_Client.HttpClient.PostAsync($"assinaturas/v1/subscriptions?new_customer={true_or_false}", stringContent); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <CouponResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
public async Task <CouponResponse> GetCouponDiscount(CouponRequest couponRequest) { try { couponResponse = new CouponResponse(); using (FacepinpointDBEntities db = new FacepinpointDBEntities()) { var SearchResultsJson = await db.Database.SqlQuery <JsonRespone>("select \"public\".\"fn_get_coupon_detail\"('" + couponRequest.UserEmail + "', '" + couponRequest.CouponCode + "')as \"json\"").FirstOrDefaultAsync(); CoupanDetails couponDetail = Newtonsoft.Json.JsonConvert.DeserializeObject <CoupanDetails>(SearchResultsJson.json); if (couponDetail != null) { if (couponDetail.CouponDetails.Discount > 0) { var totalDiscount = (couponRequest.TotalAmount * couponDetail.CouponDetails.Discount) / 100; if (totalDiscount > couponDetail.CouponDetails.MaxDiscount) { couponResponse.DiscountPrice = (float)couponDetail.CouponDetails.MaxDiscount; } else { couponResponse.DiscountPrice = (float)totalDiscount; } } else { couponResponse.DiscountPrice = (float)couponDetail.CouponDetails.MaxDiscount; } } else { couponResponse.Message = "Coupon not valid"; couponResponse.Success = false; } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); couponResponse.Success = false; couponResponse.Message = CustomErrorMessages.INTERNAL_ERROR; } return(couponResponse); }
public virtual async Task <IHttpActionResult> AddCouponAsync([FromBody] CouponRequest request) { if (request == null) { return(BadRequest("No request found.")); } var vm = await CouponViewService.AddCouponAsync(new CouponParam { CartName = CartConfiguration.ShoppingCartName, Scope = ComposerContext.Scope, CouponCode = request.CouponCode, CultureInfo = ComposerContext.CultureInfo, CustomerId = ComposerContext.CustomerId, BaseUrl = RequestUtils.GetBaseUrl(Request).ToString() }); return(Ok(vm)); }
/// <summary> /// Associar Cupom para Assinatura Existente - Associate Coupon For Existing Signature /// </summary> /// <returns></returns> public async Task <CouponResponse> AssociateCouponForExistingSignature(CouponRequest body, string code) { StringContent stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); HttpResponseMessage response = await Http_Client.HttpClient.PutAsync($"assinaturas/v1/subscriptions/{code}", stringContent); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <CouponResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Criar cupom - Create Coupon /// </summary> /// <returns></returns> public async Task <CouponResponse> CreateCoupon(CouponRequest body) { StringContent stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"); HttpResponseMessage response = await ClientInstance.PostAsync("assinaturas/v1/coupons", stringContent); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <CouponResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
public async Task <IActionResult> Post([FromBody] CouponRequest model, CancellationToken token) { try { var command = new CreateCouponCommand(model.Code, model.CouponType, model.TutorId, model.Value, model.Expiration, model.Description, model.Owner, null, //model.Amount, 1 ); await _commandBus.DispatchAsync(command, token); } catch (DuplicateRowException) { return(BadRequest("This coupon already exists")); } return(Ok()); }
public PageResult <CouponInfoListResponse> GetCouponList([FromQuery] CouponRequest seacher) { return(new CouponService(base.SchoolId).GetCouponList(seacher)); }