public static ApplicationCreateDto ToApplicationCreateDto(this ApplicationCreateModel applicationCreateModel) { return(ObjectMapperManager .DefaultInstance .GetMapper <ApplicationCreateModel, ApplicationCreateDto>() .Map(applicationCreateModel)); }
public async Task WhenRegisteringExistingApplicationThenErrorShouldBeRaised() { using (IDependencyResolver resolver = DependencyResolverFactory.CreateDependencyResolver()) { LoggerController controller = new LoggerController(resolver.Resolve <IApplicationService>(), resolver.Resolve <ILogService>()); string displayName = GenerateDisplayName(); ApplicationCreateModel applicationCreateModel = new ApplicationCreateModel() { DisplayName = displayName, Password = "******" }; OkNegotiatedContentResult <int> result = await controller.RegisterAsync(applicationCreateModel) as OkNegotiatedContentResult <int>; Assert.IsNotNull(result); BadRequestErrorMessageResult newResult = await controller.RegisterAsync(applicationCreateModel) as BadRequestErrorMessageResult; Assert.IsNotNull(newResult); Assert.AreEqual(newResult.Message, $"Application with DisplayName {displayName} already exists."); } }
public async Task WhenRegisteringApplicationThenApplicationIsRegistered() { using (IDependencyResolver resolver = DependencyResolverFactory.CreateDependencyResolver()) { LoggerController controller = new LoggerController(resolver.Resolve <IApplicationService>(), resolver.Resolve <ILogService>()); ApplicationCreateModel applicationCreateModel = new ApplicationCreateModel() { DisplayName = GenerateDisplayName(), Password = "******" }; OkNegotiatedContentResult <int> result = await controller.RegisterAsync(applicationCreateModel) as OkNegotiatedContentResult <int>; Assert.IsNotNull(result); } }
public async Task <IHttpActionResult> RegisterAsync(ApplicationCreateModel applicationCreateModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { ApplicationCreateDto applicationCreateDto = applicationCreateModel.ToApplicationCreateDto(); int applicationId = await _applicationService.AddApplicationAsync(applicationCreateDto); return(Ok(applicationId)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult CreateApplication(ApplicationCreateModel app) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationDTO newApp = new ApplicationDTO() { ApplicationName = app.ApplicationName, UserOwnerId = app.UserOwnerId }; try { ApplicationsService.Create(newApp); } catch (Exception exception) { return(BadRequest(exception.Message)); } return(CreatedAtRoute("DefaultApi", new { id = newApp.Id }, newApp)); }