コード例 #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;

            IVenueService service = testServer.Host.Services.GetService(typeof(IVenueService)) as IVenueService;
            var           model   = new ApiVenueServerRequestModel();

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

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

            ActionResponse deleteResult = await client.VenueDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] VenueModel model)
        {
            var result = await _venueService.Create(model);

            return(CreatedAtAction(nameof(GetById), new
            {
                id = result.Result
            }, result.Result));
        }
コード例 #3
0
        public ActionResult Post([FromBody] VenueModel body)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            VenueModel item = _service.Create(body);

            return(CreatedAtAction("Get", new { id = item.Id }, item));
        }
コード例 #4
0
        public async Task <int> Create(Venue entity)
        {
            try
            {
                var add = VenueParser.ToVenueDto(entity);
                await _venueService.Create(add);

                return(add.Id);
            }
            catch (VenueException exception)
            {
                var fault = new ServiceValidationFaultDetails {
                    Message = "Create venue error"
                };
                throw new FaultException <ServiceValidationFaultDetails>(fault, exception.Message);
            }
        }
コード例 #5
0
        public IHttpActionResult Post([FromBody] Venue venue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid input(s)."));
            }
            if (venue.Id > 0)
            {
                return(BadRequest("This venue cannot be created."));
            }

            try
            {
                _venueService.Create(venue);
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }

            return(Created <Venue>("/api/venues", venue));
        }