public async Task <IActionResult> Add([FromBody] CreateSupplierCommand createSupplierCommand) { ResultWrapper <RegisterOutput> result = new ResultWrapper <RegisterOutput>(); createSupplierCommand.Role = AppEnums.RoleEnum.Supplier; RegisterCommand registerCommand = new RegisterCommand() { Gender = createSupplierCommand.Gender, Username = createSupplierCommand.Email, Password = createSupplierCommand.Password, Role = createSupplierCommand.Role }; result = await _mediator.Send(registerCommand); if (!result.Status) { return(Ok(result)); } AdminRegisterEvent opEvent = new AdminRegisterEvent() { Request = registerCommand, Response = result.Result }; await _mediator.Publish(opEvent); createSupplierCommand.FireBaseId = result.Result.LocalId; ResultWrapper <CreateSupplierOutput> createSupplierResult = await _mediator.Send(createSupplierCommand); return(Ok(createSupplierResult)); }
public async Task <IActionResult> CreateSupplier(CreateSupplierCommand command) { CultureInfo ci = new CultureInfo("es-PE"); TextInfo textInfo = ci.TextInfo; var ggg = "caja de herramientaS, hola a mundo"; var dddd = textInfo.ToTitleCase(ggg); var textResult = Core.GetNameFormat(ggg); var result = await Task.FromResult(command); return(CreatedAtAction(nameof(CreateSupplier), command)); }
public async Task <IActionResult> Create([FromBody, Required] CreateSupplierCommand model) { try { return(await _mediator.Send(model)); } catch (Exception ex) { _logger.LogError(ex, "Error in {0}", HttpContext.Request.Path); return(BadRequest(ErrorMessages.InternalExceptionModel)); } }
public async Task CreateSupplierValidation() { var validator = new CreateSupplierCommandValidator(); var cmdValid = new CreateSupplierCommand { Name = "Sali", Email = "*****@*****.**", Phone = "+41 79 456 45 45", }; var resultValid = await validator.ValidateAsync(cmdValid); Assert.True(resultValid.IsValid); var cmdInvalidMail = new CreateSupplierCommand { Email = "not valid mail", Name = "some name", Phone = "+41 79 456 45 45", }; var resultInvalidMail = await validator.ValidateAsync(cmdInvalidMail); Assert.False(resultInvalidMail.IsValid); Assert.NotEmpty(resultInvalidMail.Errors); Assert.Contains(resultInvalidMail.Errors, e => e.PropertyName == nameof(cmdInvalidMail.Email)); Assert.DoesNotContain(resultInvalidMail.Errors, e => e.PropertyName == nameof(cmdInvalidMail.Name)); Assert.DoesNotContain(resultInvalidMail.Errors, e => e.PropertyName == nameof(cmdInvalidMail.Phone)); var cmdMissingName = new CreateSupplierCommand { Email = "*****@*****.**", Phone = "+41 79 456 45 45", }; var resultMissingName = await validator.ValidateAsync(cmdMissingName); Assert.False(resultMissingName.IsValid); Assert.Contains(resultMissingName.Errors, e => e.PropertyName == nameof(cmdMissingName.Name)); Assert.DoesNotContain(resultMissingName.Errors, e => e.PropertyName == nameof(cmdMissingName.Email)); Assert.DoesNotContain(resultMissingName.Errors, e => e.PropertyName == nameof(cmdMissingName.Phone)); }
public async Task <ActionResult <SupplierDto> > Create(CreateSupplierViewModel createSupplierViewModel) { var command = new CreateSupplierCommand { Name = createSupplierViewModel.Name, Email = createSupplierViewModel.Email, Phone = createSupplierViewModel.Phone }; var result = await mediator.Send(command); if (!result.Success) { return(BadRequest(result.ErrorMessages)); } var query = new GetSupplierByIdQuery { Id = result.Data }; var resultData = await mediator.Send(query); return(CreatedAtAction(nameof(Get), new { supplierId = result.Data }, SupplierDto.FromCoreSupplierDTO(resultData.Data))); }
public async Task TestCreateSuccess() { var cmd = new CreateSupplierCommand { Email = "*****@*****.**", Name = "Pascal", Phone = "+41 79 456 45 45" }; await using var context = DatabaseHelper.CreateInMemoryDatabaseContext(nameof(TestCreateSuccess)); var cmdHandler = new CreateSupplierCommandHandler(context); var cmdResponse = await cmdHandler.Handle(cmd, CancellationToken.None); var supplierId = cmdResponse.Data; Assert.True(cmdResponse.Success); var queryOneHandler = new GetSupplierByIdQueryHandler(context); var queryOne = new GetSupplierByIdQuery { Id = supplierId }; var queryOneResponse = await queryOneHandler.Handle(queryOne, CancellationToken.None); Assert.True(queryOneResponse.Success); Assert.Equal(supplierId, queryOneResponse.Data.Id); Assert.Equal(cmd.Email, queryOneResponse.Data.Email); Assert.Equal(cmd.Name, queryOneResponse.Data.Name); Assert.Equal(cmd.Phone, queryOneResponse.Data.Phone); var queryAll = new GetAllSuppliersQuery(); var queryAllHandler = new GetAllSuppliersQueryHandler(context); var queryAllResponse = await queryAllHandler.Handle(queryAll, CancellationToken.None); Assert.True(queryAllResponse.Success); Assert.NotEmpty(queryAllResponse.Data); Assert.Contains(queryAllResponse.Data, s => s.Id.Equals(supplierId)); }
public async Task ValidateEmail(string email) { var createSupplierCommand = new CreateSupplierCommand { Name = "Pascal", Phone = "+41 79 456 45 45", Email = email, }; var createSupplierCommandValidator = new CreateSupplierCommandValidator(); var result = await createSupplierCommandValidator.ValidateAsync(createSupplierCommand); Assert.False(result.IsValid); Assert.NotEmpty(result.Errors); Assert.Contains(result.Errors, e => e.PropertyName == nameof(createSupplierCommand.Email)); Assert.DoesNotContain(result.Errors, e => e.PropertyName == nameof(createSupplierCommand.Name)); Assert.DoesNotContain(result.Errors, e => e.PropertyName == nameof(createSupplierCommand.Phone)); var updateSupplierCommand = new UpdateSupplierCommand { Id = 1, Name = "Pascal", Phone = "+41 79 456 45 45", Email = email, }; var updateSupplierCommandValidator = new UpdateSupplierCommandValidator(); result = await updateSupplierCommandValidator.ValidateAsync(updateSupplierCommand); Assert.False(result.IsValid); Assert.NotEmpty(result.Errors); Assert.Contains(result.Errors, e => e.PropertyName == nameof(updateSupplierCommand.Email)); Assert.DoesNotContain(result.Errors, e => e.PropertyName == nameof(updateSupplierCommand.Id)); Assert.DoesNotContain(result.Errors, e => e.PropertyName == nameof(updateSupplierCommand.Name)); Assert.DoesNotContain(result.Errors, e => e.PropertyName == nameof(updateSupplierCommand.Phone)); }
public async Task <ResultWrapper <CreateSupplierOutput> > Handle(CreateSupplierCommand request, CancellationToken cancellationToken) { ResultWrapper <CreateSupplierOutput> createUserResult = new ResultWrapper <CreateSupplierOutput>(); try { GenderEnum GenderEn = GenderEnum.NULL; if (!Enum.TryParse <GenderEnum>(request.Gender.ToString(), true, out GenderEn)) { createUserResult.Status = false; createUserResult.Message = "Gender value is invalid!"; return(createUserResult); } TUser tUser = _dbContext.TUser.FirstOrDefault(x => x.Email == request.Email); if (tUser == null) { tUser = new TUser() { Email = request.Email, FireBaseId = request.FireBaseId, Enabled = true, Gender = request.Gender, Role = request.Role, FirstName = request.FirstName, LastName = request.LastName, Address = request.Address, PostalCode = request.PostalCode, Phone = request.Phone, TRegionCityId = request.RegionCityId, RestaurantName = request.RestaurantName, ShareAccount = request.ShareAccount, SharePercent = request.SharePercent, Lat = request.Lat, Lng = request.Lng }; _dbContext.TUser.Add(tUser); } else { tUser.FireBaseId = request.FireBaseId; tUser.Gender = request.Gender; tUser.FirstName = request.FirstName; tUser.LastName = request.LastName; tUser.Address = request.Address; tUser.PostalCode = request.PostalCode; tUser.Phone = request.Phone; tUser.TRegionCityId = request.RegionCityId; tUser.RestaurantName = request.RestaurantName; tUser.ShareAccount = request.ShareAccount; tUser.SharePercent = request.SharePercent; tUser.Lat = request.Lat; tUser.Lng = request.Lng; } await _dbContext.SaveChangesAsync(); createUserResult.Status = true; createUserResult.Result = new CreateSupplierOutput() { Id = tUser.Id, Email = tUser.Email, FireBaseId = tUser.FireBaseId }; } catch (Exception ex) { createUserResult.Status = false; createUserResult.Message = ex.Message; } return(createUserResult); }
public void CreateDimension <TResult>(TResult obj) where TResult : class { var resultType = typeof(TResult); if (resultType == typeof(Customer)) { var command = new CreateCustomerCommand { Customer = obj as Customer }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Supplier)) { var command = new CreateSupplierCommand { Supplier = obj as Supplier }; _processXml.Process(command.ToXml()); } if (resultType == typeof(BalanceSheet)) { var command = new CreateGeneralLedgerCommand { GeneralLedger = obj as BalanceSheet }; _processXml.Process(command.ToXml()); } if (resultType == typeof(ProfitLoss)) { var command = new CreateGeneralLedgerCommand { GeneralLedger = obj as ProfitLoss }; _processXml.Process(command.ToXml()); } if (resultType == typeof(CostCenter)) { var command = new CreateCostCenterCommand { CostCenter = obj as CostCenter }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Article)) { var command = new CreateArticleCommand { Article = obj as Article }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Data.SalesInvoice.SalesInvoice)) { var command = new CreateSalesInvoiceCommand { SalesInvoice = obj as Data.SalesInvoice.SalesInvoice }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Vat)) { var command = new CreateVatCommand { Vat = obj as Vat }; _processXml.Process(command.ToXml()); } if (resultType == typeof(Currency)) { var command = new CreateCurrencyCommand { Currency = obj as Currency }; _processXml.Process(command.ToXml()); } if (resultType == typeof(DimensionType)) { var command = new UpdateDimensionTypeCommand { DimensionType = obj as DimensionType }; _processXml.Process(command.ToXml()); } }
public async Task <IActionResult> Create([FromBody] CreateSupplierCommand command) { var result = await _mediator.Send(command); return(Ok(result)); }
public async Task <ActionResult> CreateAsync([FromBody] CreateSupplierCommand command) { await _mediator.Send(command, HttpContext.RequestAborted); return(Ok()); }
public async Task <ActionResult <int> > Create(CreateSupplierCommand command) { return(await Mediator.Send(command)); }