Beispiel #1
0
        public async Task <IHttpActionResult> Put(PrivateUserViewModel user)
        {
            if (user.UserId != LoggedInUserId)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            var profile = await db.Profiles.FirstOrDefaultAsync(p => p.UserId == user.UserId);

            if (profile == null)
            {
                return(NotFound());
            }

            profile.Gender     = user.Gender;
            profile.FamilyName = user.FamilyName;
            profile.GivenName  = user.GivenName;
            profile.NickName   = user.NickName;
            profile.Picture    = user.Picture;
            profile.Brief      = user.Brief;
            profile.UpdatedAt  = DateTime.Now;

            db.Entry(profile).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PutComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.Id)
            {
                return(BadRequest());
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public async Task <IHttpActionResult> PutMeetup(Meetup meetup)
        {
            // Ensure it's post by sponser
            if (meetup.Sponsor != User.Identity.GetUserId())
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            // Ensure valid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Ensure existing
            var old = await db.Meetups.FirstOrDefaultAsync(m => m.Id == meetup.Id);

            if (old == null)
            {
                return(NotFound());
            }

            // Update and save
            old.Description     = meetup.Description;
            old.Title           = meetup.Title;
            old.When            = meetup.When;
            old.Where           = meetup.Where;
            meetup.UpdatedAt    = DateTime.Now;
            db.Entry(old).State = EntityState.Modified;
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }