Example #1
0
 // PATCH tables/User/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task PatchUser(string id, Delta <UserEditRequest> patch)
 {
     try
     {
         //Admins can also modify user.
         ValidationUtilities.ValidateEditUserRequest(id, patch.GetEntity(), patch.GetChangedPropertyNames().ToList());
         string requesterEmail = HttpUtilities.GetUserNameFromToken(this.Request);
         var    user           = context.Users.FirstOrDefault(i => i.Email == requesterEmail);
         if (string.IsNullOrEmpty(requesterEmail) || user == null)
         {
             var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, Common.Utilities.ErrorCodes.INVALID_TOKEN, string.Empty);
             throw new HttpResponseException(response);
         }
         Delta <User> deltaDest = new Delta <User>();
         foreach (var item in patch.GetChangedPropertyNames())
         {
             object result;
             patch.TryGetPropertyValue(item, out result);
             deltaDest.TrySetPropertyValue(item, result);
         }
         deltaDest.TrySetPropertyValue("ModifiedBy", requesterEmail);
         deltaDest.TrySetPropertyValue("UpdatedAt", DateTimeOffset.UtcNow);
         return(UpdateAsync(id, deltaDest));
     }
     catch (HttpResponseException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         HttpUtilities.ServerError(ex, Request);
         return(null);
     }
 }