public bool Create(User User) { IRestRequest request = new RestRequest("/api/user", Method.POST); request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(User), ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; IRestResponse response = Client.Post<bool>(request); bool success = false; if (response.StatusCode == System.Net.HttpStatusCode.OK) { success = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiObjectId>(response.Content).Id == User.UserName; } else { this.setError(response); } return success; }
static void UpdateUser(string username, string programGuid = "") { ServiceFactory factory = new ServiceFactory(); IUserService uService = factory.CreateUserService(); var user = new User(); // the following are required fields. user.UserName = username; user.Password = "******"; user.FirstName = "Sample"; user.LastName = "User"; user.Email = "*****@*****.**";//e-mail must be unique user.Types = UserType.User.GetHashCode(); // the following are optional. user.MobilePhone = "+905327775544"; user.Comment = "This user is created by Alms API."; user.Culture = "tr-TR"; user.HomeTown = "My hometown"; user.City = "Istanbul"; user.Country = "Türkiye"; user.Occupation = "Software Engineer"; user.Gender = "Male"; // OR Female // website url is optional but if you set it, it must be a valid URL. user.WebsiteURL = "http://www.alms.com.tr"; user.CitizenshipIdentifier = "2433452456"; user.Title = "Dr."; user.BirthDate = DateTime.Now.AddYears(-35); user.ProgramGuids = ""; user.CustomProperty1 = "Custom prop 1"; user.CustomProperty2 = "Custom prop 2"; user.CustomProperty3 = "Custom prop 3"; user.CustomProperty4 = "Custom prop 4"; user.CustomProperty5 = "Custom prop 5"; user.CustomProperty6 = "Custom prop 6"; user.CustomProperty7 = "Custom prop 7"; user.CustomProperty8 = "Custom prop 8"; user.CustomProperty9 = "Custom prop 9"; user.CustomProperty10 = "Custom prop 10"; user.CustomProperty11 = "Custom prop 11"; user.CustomProperty12 = "Custom prop 12"; user.CustomProperty13 = "Custom prop 13"; user.CustomProperty14 = "Custom prop 14"; user.CustomProperty15 = "Custom prop 15"; user.CustomProperty16 = "Custom prop 16"; user.CustomProperty17 = "Custom prop 17"; user.CustomProperty18 = "Custom prop 18"; user.CustomProperty19 = "Custom prop 19"; user.CustomProperty20 = "Custom prop 20"; bool success = uService.Update(user); if (!success) { printError(uService.LastError); } else { Console.WriteLine(string.Format("User {0} was updated.", user.UserName)); } }
public bool Update(User User) { IRestRequest request = new RestRequest("/api/user", Method.PUT); request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(User), ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; IRestResponse response = Client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) return true; else { this.setError(response); return false; } }