public override async Task <UseCaseResult <User> > Create(User userToCreate) { var validationResponse = new PersistenceResponse <User>(); if (userToCreate.BirthDate == DateTime.MinValue) { validationResponse.Success = false; validationResponse.Message = "BirthDate is Required"; return(UseCasesResponses.GetUseCaseResult(validationResponse)); } var alreadyHasLogin = await _persistenceGateway.First(user => user.Login == userToCreate.Login); if (alreadyHasLogin.Success) { validationResponse.Success = false; validationResponse.Message = "AlreadyHasLogin"; return(UseCasesResponses.GetUseCaseResult(validationResponse)); } var alreadyHasEmail = await _persistenceGateway.First(user => string.Equals(user.Email, userToCreate.Email, StringComparison.CurrentCultureIgnoreCase)); if (alreadyHasEmail.Success) { validationResponse.Success = false; validationResponse.Message = "AlreadyHasEmail"; return(UseCasesResponses.GetUseCaseResult(validationResponse)); } var persistenceResponse = await _persistenceGateway.Create(userToCreate); return(UseCasesResponses.GetUseCaseResult(persistenceResponse)); }
public void TestServiceStackREST() { client = new JsonServiceClient(Environment.ServiceUrl); Environment.Log.Info("TestServiceStackREST"); ProductDTO product1 = new ProductDTO(); product1.RefCode = ProductRef1; product1.Caption = ProductCaption1; ProductRequest prq1 = new ProductRequest(); prq1.ProductDTO = product1; ProductResponse prr1 = client.Post <ProductResponse>("/ProductService", prq1); Assert.IsFalse(prr1.CommitResult.HasError, prr1.CommitResult.Message); product1 = prr1.ProductDTO; Assert.AreNotEqual(0, product1.Id, "Invalid Id"); Environment.Log.InfoFormat("1: product1.Id: {0}", product1.Id); ProductResponse prr2 = client.Delete <ProductResponse>(String.Format("/ProductService/Id/{0}", product1.Id)); Assert.IsFalse(prr2.CommitResult.HasError, prr2.CommitResult.Message); ProductDTO product2 = new ProductDTO(); product2.RefCode = ProductRef2; product2.Caption = ProductCaption2; UnitOfWorkDTO uow = new UnitOfWorkDTO(); uow.Save(product2); Environment.Log.InfoFormat("1: product2.Id: {0}", product2.Id); PersistenceRequest pr2 = new PersistenceRequest(); pr2.UnitOfWork = uow; PersistenceResponse ps2 = client.Post <PersistenceResponse>("/Persistence", pr2); Assert.IsFalse(ps2.CommitResult.HasError, ps2.CommitResult.Message); ps2.UpdatedObjects.Update <ProductDTO>(ref product2); Assert.AreNotEqual(0, product2.Id, "Invalid Id"); ProductResponse prr3 = client.Get <ProductResponse>("/ProductService/Id/" + product2.Id); Assert.IsNotNull(prr3.ProductDTO); ProductListResponse prodList = client.Get <ProductListResponse>("/ProductService"); foreach (ProductDTO prod in prodList.ProductDTOList) { if (prod.RefCode == ProductRef1 || prod.RefCode == ProductRef2) { client.Delete <ProductResponse>(String.Format("/ProductService/Id/{0}", prod.Id)); } } client.Dispose(); }
public static UseCaseResult <TResult> GetUseCaseResult <TResult>(PersistenceResponse <TResult> persistenceResponse) { var wasSuccessfullyExecuted = persistenceResponse.Success; return(wasSuccessfullyExecuted ? Success(persistenceResponse.Response) : PersistenceErrorResponse(persistenceResponse.Response, persistenceResponse.Message)); }
public async Task <UseCaseResult <RentRequirementValidationResult> > ValidateForForecast(RentRequirement requirement) { var isTryingToRentWithoutProducts = requirement.ProductsIds == null; if (isTryingToRentWithoutProducts) { return(UseCasesResponses.Failure <RentRequirementValidationResult>("Trying to Rent without products")); } var productsToRent = await _products.GetByIds(requirement.ProductsIds.ToList()); if (!productsToRent.Success) { return(UseCasesResponses.Failure <RentRequirementValidationResult>(productsToRent.Message)); } var renter = new PersistenceResponse <Renter> { Success = true, Response = new Renter( id: Guid.NewGuid(), name: "Forecast", code: "123", creatorId: Guid.NewGuid(), new GovernmentRegistrationDocumentCode("99999999999"), new Email("*****@*****.**"), new Phone("041", "999999999"), new BirthDate(DateTime.Now.AddYears(-20)), personImage: new byte[] {} ) }; var rentPeriod = DateRangeProvider.GetDateRange(requirement.StartDate, requirement.EndDate); if (!rentPeriod.Success) { return(UseCasesResponses.Failure <RentRequirementValidationResult>(rentPeriod.Message)); } var validationResult = new RentRequirementValidationResult { Products = productsToRent.Response, RentPeriod = rentPeriod.Result, Renter = renter.Response }; return(UseCasesResponses.Success(validationResult)); }