コード例 #1
0
        public async Task <ActionResult <Event> > PostEvent(PublicApi.v1.DTO.Event @event)
        {
            @event.AppUserId = User.GetUserId();

            await _bll.Events.AddAsync(PublicApi.v1.Mappers.EventMapper.MapFromExternal(@event));

            await _bll.SaveChangesAsync();

            // get the new id into the object
            return(CreatedAtAction("GetEvent", new { id = @event.Id }, @event));
        }
コード例 #2
0
        public async Task <IActionResult> PutEvent(int id, PublicApi.v1.DTO.Event @event)
        {
            if (id != @event.Id)
            {
                return(BadRequest());
            }

            // check for the ownership - is this Person record really belonging to logged in user.
            if (!await _bll.Events.BelongsToUserAsync(id, User.GetUserId()))
            {
                return(NotFound());
            }

            @event.AppUserId = User.GetUserId();

            _bll.Events.Update(PublicApi.v1.Mappers.EventMapper.MapFromExternal(@event));
            await _bll.SaveChangesAsync();

            return(NoContent());
        }