public async Task CreateShop_ShouldFail_WithNameAlreadyExist_Test() { var command = new CreateShopCommand { Name = Guid.NewGuid().ToString(), Location = new LocationDto { Street = "Place Doyen Gosse", PostCode = "38000", Country = "France", City = "Grenoble", Address = "2", Region = "Rhone Alpes" }, Contact = new ContactDto { Phone = "test", Email = "*****@*****.**" } }; var result = await Mediator.Send(command); result.Status.Should().Be(ResultStatus.Ok); var failed = await Mediator.Send(command); failed.Status.Should().Be(ResultStatus.BadRequest); }
public async Task CreateShop_ShouldFail_WithInvalidLocation_Test() { var command = new CreateShopCommand { Name = Guid.NewGuid().ToString(), Location = new LocationDto { Street = "FakeStreet", PostCode = "FakeCode", Country = "FakeCountry", City = "FakeCity", Address = "FakeAddress", Region = "FakeRegion" }, Contact = new ContactDto { Phone = "test", Email = "*****@*****.**" } }; var result = await Mediator.Send(command); result.Status.Should().Be(ResultStatus.BadRequest); }
public async Task CreateShop_ShouldSucceed_WithValidLocation_Test() { var command = new CreateShopCommand { Name = Guid.NewGuid().ToString(), Location = new LocationDto { Street = "Place Doyen Gosse", PostCode = "38000", Country = "France", City = "Grenoble", Address = "2", Region = "Isère" }, Contact = new ContactDto { Phone = "test", Email = "*****@*****.**" } }; var result = await Mediator.Send(command); result.Status.Should().Be(ResultStatus.Ok); }
public async Task UpdateShop_ShouldSucceed_WithOldNameEqualNewName_Test() { var shop = new CreateShopCommand { Name = Guid.NewGuid().ToString(), Location = new LocationDto { Street = "Place Doyen Gosse", PostCode = "38000", Country = "France", City = "Grenoble", Address = "2", Region = "Rhone Alpes" }, Contact = new ContactDto { Phone = "test", Email = "*****@*****.**" } }; var createShopResult = await Mediator.Send(shop); createShopResult.Status.Should().Be(ResultStatus.Ok); var command = new UpdateShopCommand { NewName = shop.Name, OldName = shop.Name, ShopId = createShopResult.TypedEntity, }; var result = await Mediator.Send(command); result.Status.Should().Be(ResultStatus.Ok); }
public async Task <IActionResult> AddShop([FromBody] CreateShop command) { var createShopCommand = new CreateShopCommand(command); await _mediator.Send(createShopCommand); return(Created($"shops/{createShopCommand.Id}", null)); }
public async Task <Response <int> > Handle(CreateShopCommand request, CancellationToken cancellationToken) { var imagePath = _fileService.UploadFile(request.ImageFile); var vendor = _mapper.Map <Shop>(request); vendor.ImagePath = imagePath; await _shopRepository.CreateAsync(vendor); return(new Response <int>(vendor.Id)); }
public async Task <ActionResult <Shop> > CreateShop([FromBody] CreateShopCommand shop) { int num = await _mediator.Send(shop); if (num == 0) { return(BadRequest()); } return(CreatedAtAction(nameof(GetShopByName), new { name = shop.Name }, shop)); }
public async Task <IHttpActionResult> Post(CreateShopCommand command) { //command.UserId = UserId; var commandResponse = await Bus.Send <CreateShopCommand, CreateShopPersonCommandResponse>(command); var response = new ResponseModel { Message = "ثبت نام با موفقیت انجام شد", Success = true, ResponseData = commandResponse }; return(Ok(response)); }
public async Task <CreateShopCommandResponse> Handle(CreateShopCommand command) { var shopNumber = _seqRepository.GetNextSequenceValue(SqNames.ShopNumberSequence); var marketer = await _marketerRepository.AsQuery().SingleOrDefaultAsync(p => p.BarcodeId == command.BarcodeId); if (marketer == null) { throw new DomainException("بازاریاب یافت نشد"); } _marketerDomainService.CheckMarketerActive(marketer); _marketerDomainService.CheckMaxMarketerAllowedIsEnough(marketer); _personDomainService.CheckShopIsExist(command.UserId); var city = _cityRepository.Find(command.Address.CityId); if (city == null) { throw new DomainException("شهر وارد شده یافت نشد"); } var appSetting = await _applicationSettingRepository.AsQuery().SingleOrDefaultAsync(); if (appSetting == null) { throw new DomainException("تنظیمات برنامه یافت نشد"); } if (command.DefaultDiscount < appSetting.MinimumDiscount || command.DefaultDiscount > appSetting.MaximumDiscount) { throw new DomainException("تخفیف پیش فرض در بازه تخفیفات معتبر نمی باشد"); } var address = new ShopAddress(city.Id, city.Code, city.CityName, command.Address.AddressText, command.Address.PhoneNumber, command.Address.Position.ToDbGeography(), command.Address.ShopMobileNumber, command.Address.ZoneId, city.Province.Id, city.Province.Code, city.Province.Name); var accountBank = new BankAccount(command.BankAccount.Iban, command.BankAccount.AccountOwnerName, command.BankAccount.AccountNumber); var imageDocument = new ImageDocuments(command.ImageDocuments.FaceImage, command.ImageDocuments.NationalCardImage); var shop = new Shop(Guid.NewGuid(), command.Name, command.FirstName, command.LastName, command.EmailAddress, command.UserId, command.Description, command.NationalCode, address, accountBank, imageDocument, command.MobileNumber, command.AreaRadius, command.Metrage, command.DefaultDiscount, marketer.Id, shopNumber) { AppInfos = new List <AppInfo>(), CustomerSubsets = new List <ShopCustomerSubset>() }; _repository.Add(shop); DomainEventDispatcher.Raise(new AssignmentShopMarketersHistoryEvent(shop, marketer, new UserInfo(command.UserId, command.MobileNumber, "کاربر موبایل"))); DomainEventDispatcher.Raise(new AddPanelNotificationEvent(Guid.NewGuid(), command.Name, "فروشگاه ایجاد شد", PanelNotificationType.ShopCreated, shop.Id.ToString())); return(new CreateShopCommandResponse()); }
public async Task <CoreResult> Create([FromBody] CreateShopRequestDto dto) { CoreResult result = new CoreResult(); CreateShopCommand command = new CreateShopCommand(dto); var res = await _bus.SendCommandAsync(command); if (res) { result.Success("添加成功"); } else { result.Failed("添加失败"); } return(result); }
public async Task UpdateShop_ShouldFail_WithShopNull_Test() { var shop = new CreateShopCommand { Name = null, Location = new LocationDto { Street = null, PostCode = null, Country = null, City = null, Address = null, Region = null }, Contact = new ContactDto { Phone = null, Email = null } }; var createShopResult = await Mediator.Send(shop); createShopResult.Status.Should().Be(ResultStatus.BadRequest); var id = new Random(); var command = new UpdateShopCommand { NewName = Guid.NewGuid().ToString(), OldName = Guid.NewGuid().ToString(), ShopId = id.Next() }; var result = await Mediator.Send(command); result.Status.Should().Be(ResultStatus.NotFound); }
public async Task <IActionResult> Create([FromBody] CreateShopCommand command) { return(Ok(await mediator.Send(command))); }
public async Task <long> CreateShop([FromBody] CreateShopCommand command) { var entityId = await _mediator.Send(command); return(entityId); }