Exemplo 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;

            IFamilyService service = testServer.Host.Services.GetService(typeof(IFamilyService)) as IFamilyService;
            var            model   = new ApiFamilyServerRequestModel();

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

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

            ActionResponse deleteResult = await client.FamilyDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Exemplo n.º 2
0
        public ActionResult <int> AddFamily(
            [FromBody] FamilyModel obj
            )
        {
            if (ModelState.IsValid)
            {
                Family family = new Family(obj.Name, User.Identity.Name);
                return(_service.Create(family));
            }

            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult Create([FromBody] FamilyViewModel family)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _familyService.Create(_mapper.Map <Family>(family));

            return(Ok(new
            {
                name = family.Name,
                familyId = family.FamilyId,
                description = family.Description,
                goal = family.Goal
            }));
        }