コード例 #1
0
        public HttpResponseMessage UpdateUserDetails(DAC.User user)
        {
            var usr = DbContext.Users.FirstOrDefault(u => u.Id == user.Id);

            if (usr != null)
            {
                usr.FirstName  = user.FirstName;
                usr.LastName   = user.LastName;
                usr.EmployeeId = user.EmployeeId;
                return(Request.CreateResponse(dbContext.SaveChanges()));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User with id " + user.Id + " not found."));
            }
        }
コード例 #2
0
 public HttpResponseMessage AddUser(DAC.User user)
 {
     if (user == null)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User cannot be null."));
     }
     try
     {
         DbContext.Users.Add(user);
         return(Request.CreateResponse(dbContext.SaveChanges()));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error in adding user : " + ex.Message));
     }
 }