Example #1
0
        public HttpResponseMessage Put(string id, [FromBody] AspNetUser user)
        {
            try
            {
                using (ZB_Profile_DBEntities entities = new ZB_Profile_DBEntities())
                {
                    var entity = entities.AspNetUsers.FirstOrDefault(c => c.Id == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User with ID: " + id.ToString() + "not found"));
                    }
                    else
                    {
                        entity.UserName = user.UserName;

                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Example #2
0
 public HttpResponseMessage Post([FromBody] AspNetUser user)
 {
     try
     {
         using (ZB_Profile_DBEntities entities = new ZB_Profile_DBEntities())
         {
             entities.AspNetUsers.Add(user);
             entities.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, user);
             message.Headers.Location = new Uri(Request.RequestUri + user.Id.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }