public Task <IActionResult> CreatePromotion([FromForm] CreatePromotionRequest request) { var command = new CreatePromotionCommand(request.Name, request.ImageUrl, request.Description, request.DescriptionEng, request.MinimumQuantity, request.MinimumBillAmount, request.IsFixedPriceDiscount, request.DiscountAmount, request.DiscountPercentage, request.MaximumDiscount, request.StartDate, request.EndDate); return(HandleActionResultFor(command)); }
public ActionResult Create(FormCollection formCollection, CreatePromotionRequest request, int?authuid) { request.Files = Request.Files; request.AuthUid = authuid.Value; this._promotionDataService.CreatePromotion(request); return(View()); }
public RestfulResult Create(FormCollection formCollection, CreatePromotionRequest request, int?authuid, UserModel authUser) { request.AuthUid = authuid.Value; request.AuthUser = authUser; request.Files = Request.Files; request.Description = UrlDecode(request.Description); request.Name = UrlDecode(request.Name); var result = _promotionDataService.CreatePromotion(request); return(new RestfulResult { Data = result }); }
public async Task <IActionResult> CreatePromotionAsync([FromBody] CreatePromotionRequest request) { var result = await _promotionService.CreatePromotionAsync( request.PromotionalCode, request.Currency.Type.ToEnumeration <CurrencyType>().ToCurrency(request.Currency.Amount), request.Duration.ToTimeSpan(), request.ExpiredAt.ToDateTime()); if (result.IsValid) { return(this.Ok(_mapper.Map <PromotionDto>(result.Response))); } result.AddToModelState(ModelState); return(this.BadRequest(new ValidationProblemDetails(ModelState))); }
public async Task CreatePromotionAsync_ShouldBeOkObjectResult() { // Arrange TestMock.PromotionService .Setup( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>())) .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(GeneratePromotion())) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); var request = new CreatePromotionRequest { Currency = new CurrencyDto { Amount = 50, Type = EnumCurrencyType.Money }, Duration = new Duration(), ExpiredAt = DateTime.UtcNow.ToTimestamp(), PromotionalCode = TestCode }; // Act var result = await controller.CreatePromotionAsync(request); // Assert result.Should().BeOfType <OkObjectResult>(); result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(GeneratePromotion())); TestMock.PromotionService.Verify( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>()), Times.Once); }
public async Task CreatePromotionAsync_ShouldBeBadRequestObjectResult() { // Arrange TestMock.PromotionService .Setup( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>())) .ReturnsAsync(DomainValidationResult <Promotion> .Failure("error message")) .Verifiable(); var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper); var request = new CreatePromotionRequest { Currency = new CurrencyDto { Amount = 50, Type = EnumCurrencyType.Money }, Duration = new Duration(), ExpiredAt = DateTime.UtcNow.ToTimestamp(), PromotionalCode = "code1" }; // Act var result = await controller.CreatePromotionAsync(request); // Assert result.Should().BeOfType <BadRequestObjectResult>(); TestMock.PromotionService.Verify( promotionService => promotionService.CreatePromotionAsync( It.IsAny <string>(), It.IsAny <Currency>(), It.IsAny <TimeSpan>(), It.IsAny <DateTime>()), Times.Once); }
public async Task ShouldBeHttpStatusCodeBadRequest() { var user = TestData.FileStorage.GetUsers().First(); var factory = TestHost.WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, user.ToString())); _httpClient = factory.CreateClient(); var testServer = factory.Server; testServer.CleanupDbContext(); var request = new CreatePromotionRequest { Currency = new CurrencyDto { Amount = new DecimalValue(50) }, Duration = TimeSpan.FromDays(30).ToDuration(), ExpiredAt = DateTime.UtcNow.AddDays(30).ToTimestamp() }; // Act using var response = await this.ExecuteAsync(request); // Assert response.StatusCode.Should().Be(HttpStatusCode.BadRequest); await testServer.UsingScopeAsync( async scope => { var promotionRepository = scope.GetRequiredService <IPromotionRepository>(); var promotion = await promotionRepository.FindPromotionOrNullAsync(TestCode); promotion.Should().BeNull(); }); }
private async Task <HttpResponseMessage> ExecuteAsync(CreatePromotionRequest request) { return(await _httpClient.CustomPostAsJsonAsync("api/promotions", request)); }
/// <summary> /// 创建活动 /// </summary> /// <param name="request"></param> /// <returns></returns> public ExecuteResult <PromotionInfoResponse> CreatePromotion(CreatePromotionRequest request) { var promotionSourceType = request.AuthUser.UserLevel == (int)UserLevel.Daren ? RecommendSourceType.Daren : RecommendSourceType.StoreManager; //如果是达人,需要上传storeId,如果是店长,那么取店长所属的store // promotionSourceType == RecommendSourceType.Daren ? request.StoreId : request.AuthUser.Store_Id; var storeId = request.StoreId < 1 ? request.AuthUser.Store_Id : request.StoreId; int pid = 0; using (var ts = new TransactionScope()) { var promotionEntity = _promotionRepository.Insert(new PromotionEntity { CreatedDate = DateTime.Now, CreatedUser = request.AuthUid, Description = request.Description, EndDate = request.EndDate, FavoriteCount = 0, InvolvedCount = 0, LikeCount = 0, Name = request.Name, RecommendSourceId = request.RecommendUser == null ? request.AuthUid : request.RecommendUser.Value, RecommendSourceType = (int)promotionSourceType, ShareCount = 0, StartDate = request.StartDate, Status = 1, Store_Id = storeId ?? 0, UpdatedDate = DateTime.Now, UpdatedUser = request.AuthUid, RecommendUser = request.RecommendUser == null ? request.AuthUid : request.RecommendUser.Value, Tag_Id = request.TagId ?? 0, IsTop = false }); pid = promotionEntity.Id; //处理 图片 //处理文件上传 if (request.Files != null && request.Files.Count > 0) { _resourceService.Save(request.Files, request.AuthUid, 0, promotionEntity.Id, SourceType.Promotion); } //处理品牌关系 if (request.Brands.Length > 0) { var b = request.Brands.Distinct().Where(v => v > 0).ToList(); var list = new List <PromotionBrandRelationEntity>(b.Count); foreach (var item in b) { list.Add(new PromotionBrandRelationEntity { Brand_Id = item, CreatedDate = DateTime.Now, Promotion_Id = promotionEntity.Id }); } _promotionBrandRelationRepository.BatchInsert(list); } ts.Complete(); } return(GetPromotionInfo(new GetPromotionInfoRequest { Promotionid = pid, CurrentAuthUser = request.AuthUser })); }