コード例 #1
0
        public HttpResponseMessage UpdateUserSettings(HttpRequestMessage request, UserModel model)
        {
            if (!ModelState.IsValid) return request.CreateResponse(HttpStatusCode.BadRequest, "error");
            try
            {
                var repo = Repository();
                var currentUser = repo.FindBy<User>(1);

                currentUser.FirstName = model.FirstName;
                currentUser.LastName = model.LastName;
                currentUser.Address1 = model.Address1;
                currentUser.Address2 = model.Address2;
                currentUser.Email = model.Email;
                currentUser.UserName = model.UserName;
                currentUser.PhoneNumber = model.PhoneNumber;

                repo.Update(currentUser);
                UoW.Commit();
                UoW.Dispose();

                return request.CreateResponse(HttpStatusCode.OK, "updated settings");
            }
            catch (Exception)
            {
                return request.CreateResponse(HttpStatusCode.InternalServerError, "not updated ");
            }
        }
コード例 #2
0
 public HttpResponseMessage GetAccountSettings(HttpRequestMessage request)
 {
     try
     {
         var result = Repository().First<User>(u => u.Id == 1);
         UoW.Dispose();
         var user = new UserModel
         {
             FirstName = result.FirstName,
             LastName = result.LastName,
             Address1 = result.Address1,
             Address2 = result.Address2,
             PhoneNumber = result.PhoneNumber,
             UserName = result.UserName,
             Email = result.Email,
             FullName = result.FirstName + " " + result.LastName
         };
         return request.CreateResponse(HttpStatusCode.OK, user);
     }
     catch (Exception)
     {
         return request.CreateResponse(HttpStatusCode.InternalServerError, "error getting info from db");
     }
 }