Ejemplo n.º 1
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            ISpaceService service = testServer.Host.Services.GetService(typeof(ISpaceService)) as ISpaceService;
            var           model   = new ApiSpaceServerRequestModel();

            model.SetProperties("B", "B");
            CreateResponse <ApiSpaceServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.SpaceDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiSpaceServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Ejemplo n.º 2
0
        protected async override Task <Either <CommandResult, Error> > ExecuteCommand(SpaceCreateCommand command)
        {
            if (!(await service.DoesSpaceExist(command.Data.Name)))
            {
                return(new NotFoundError(""));
            }

            Space s = await service.Create(command.Data, command.User);

            return(Insert(s.Id));
        }
Ejemplo n.º 3
0
        public IActionResult Create([FromBody] CreateSpaceModel model)
        {
            var space   = _mapper.Map <Space>(model);
            var context = HttpContext.User.Identity;
            int id      = int.Parse(context.Name);

            try
            {
                _spaceService.Create(space, id);
                return(Ok(new { message = "✓ Space Creation Success" }));
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Space> > Create(SpaceViewModel spaceIn)
        {
            if (ModelState.IsValid)
            {
                var space = new Space
                {
                    Capacity    = spaceIn.Capacity,
                    Name        = spaceIn.Name,
                    SpaceTypeId = spaceIn.SpaceTypeId,
                    Tags        = spaceIn.Tags
                };
                try
                {
                    if (spaceIn.assets.Any())
                    {
                        var assets = await _assetService.Get(spaceIn.assets);

                        space.assests = assets;
                    }
                    var result = await _spaceService.Create(space);
                }
                catch (RessourceTypeRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (SpaceRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (AssetRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                return(CreatedAtRoute("GetSpace", new { id = space.Id.ToString() }, space));
            }
            return(BadRequest(new ValidationProblemDetails(ModelState)));
        }