Exemplo n.º 1
0
        public async Task <ActionResult <Speaker> > UpdateSpeaker(int id, int speakerid, [FromBody] Speaker speakerdata)
        {
            // Is the requester authorized?
            if (GetAuthorizedOwnershipLevel(id) < OwnershipLevel.Moderator)
            {
                return(Forbidden());
            }

            Speaker speaker = await Db.Speakers.Where(s => s.ID == speakerid).FirstOrDefaultAsync();

            if (speaker == null)
            {
                return(NotFound("Speaker not found"));
            }

            if (speaker.EventID != id)
            {
                return(BadRequest());
            }

            speaker.CopyFromRequest(speakerdata);
            Db.Speakers.Update(speaker);

            await Db.SaveChangesAsync();

            return(speaker);
        }