/// <summary>
 /// Creates a user for the organization.
 /// </summary>
 /// <param name="user_info">The user_info is the user object with name and email as mandatory attributes.</param>
 /// <returns>User object.</returns>
 public User Create(User user_info)
 {
     string url = baseAddress ;
     var json = JsonConvert.SerializeObject(user_info);
     var jsonstring = new Dictionary<object, object>();
     jsonstring.Add("JSONString", json);
     var response=ZohoHttpClient.post(url,getQueryParameters(jsonstring));
     return ProjectParser.getUser(response);
 }
示例#2
0
 static void Main(string[] args)
 {
     try
     {
         var service = new ZohoBooks();
         service.initialize("{authtoken}", "{organization id}");
         var usersApi = service.GetUsersApi();
         var parameters = new Dictionary<object, object>();
         parameters.Add("filter_by", "Status.Invited");
         var userslist = usersApi.GetUsers(parameters);
         var users = userslist;
         var userId = users[1].user_id;
         foreach (var user in users)
             Console.WriteLine("user id:{0},\nuser name:{1},\nuser role:{2}.\nstatus:{3}\n", user.user_id, user.name, user.user_role, user.status);
         var user1 = usersApi.Get(userId);
         Console.WriteLine("user id:{0},\nuser name:{1},\nuser role:{2}.\nstatus:{3}\n", user1.user_id, user1.name, user1.user_role, user1.status);
         var emails = user1.email_ids;
         foreach (var email in emails)
             Console.WriteLine("{0},{1}", email.email, email.is_selected);
         var currentUser = usersApi.GetCurrentUser();
         Console.WriteLine("user id:{0},\nuser name:{1},\nuser role:{2}.\nstatus:{3}\n", currentUser.user_id, currentUser.name, currentUser.user_role, currentUser.status);
         var emails1 = currentUser.email_ids;
         foreach (var email in emails1)
             Console.WriteLine("{0},{1}", email.email, email.is_selected);
         var newUserInfo = new User()
         {
             name="hari",
             email="*****@*****.**",
             user_role="timesheetstaff"
         };
         var newUser = usersApi.Create(newUserInfo);
         Console.WriteLine("New user Info: \n user id:{0},\nuser name:{1},\nuser role:{2}.\nstatus:{3}\n", newUser.user_id, newUser.name, newUser.user_role, newUser.status);
         var updateInfo = new User()
         {
             name="user name",
             email="*****@*****.**"
         };
         var updatedUser = usersApi.Update(newUser.user_id, updateInfo);
         Console.WriteLine("user id:{0},\nuser name:{1},\nuser role:{2}.\nstatus:{3}\n", updatedUser.user_id, updatedUser.name, updatedUser.user_role, updatedUser.status);
         var deleteMsg = usersApi.Delete(updatedUser.user_id);
         Console.WriteLine(deleteMsg);
         var inviteMsg = usersApi.InviteUser(userId);
         Console.WriteLine(inviteMsg);
         var activeMsg = usersApi.MarkAsActive(userId);
         Console.WriteLine(activeMsg);
         var inactiveMsg = usersApi.MarkAsInactive(userId);
         Console.WriteLine(inactiveMsg);
     }
     catch(Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey();
 }
 private static User getUserProperties(string json)
 {
     var user = new User();
     var userObj = JObject.Parse(json);
     if(userObj["user_id"]!=null)
     {
         user.user_id = userObj["user_id"].ToString();
     }
     if(userObj["role_id"]!=null)
     {
         user.role_id = userObj["role_id"].ToString();
     }
     if (userObj["name"] != null)
     {
         user.name = userObj["name"].ToString();
     }
     if (userObj["email"] != null)
     {
         user.email = userObj["email"].ToString();
     }
     if (userObj["user_role"] != null)
     {
         user.user_role = userObj["user_role"].ToString();
     }
     if (userObj["status"] != null)
     {
         user.status = userObj["status"].ToString();
     }
     if (userObj["is_current_user"] != null)
     {
         user.is_current_user = (bool)userObj["is_current_user"];
     }
     if (userObj["photo_url"] != null)
     {
         user.photo_url = userObj["photo_url"].ToString();
     }
     return user;
 }
示例#4
0
        static void Main(string[] args)
        {
            try
            {
                var service = new ZohoBooks();
                service.initialize("{authtoken}", "{organization id}");
                var projectsApi = service.GetProjectsApi();
                var parameters = new Dictionary<object, object>();
                 parameters.Add("filter_by", "Status.Active");
                 var projectsList = projectsApi.GetProjects(null);
                 var projects = projectsList;
                 var projectId = projects[0].project_id;
                 foreach (var project in projects)
                     Console.WriteLine("{0},{1},{2}", project.project_name, project.billing_type, project.status);
                 var project1 = projectsApi.Get(projectId);
                 Console.WriteLine("{0},{1},{2}", project1.project_name, project1.tasks.Count, project1.users.Count);
                 var newPrjctInfo = new Project()
                 {
                     project_name="project-test-1",
                     customer_id = project1.customer_id,
                     billing_type = "fixed_cost_for_project",
                     rate=1000,
                 };
                 var newProject = projectsApi.Create(newPrjctInfo);
                 Console.WriteLine("{0},{1},{2}", newProject.project_name, newProject.billing_type, newProject.status);
                 var updateInfo = new Project()
                 {
                     project_name="project-test-updated",
                 };
                 var updatedprjct = projectsApi.Update(newProject.project_id, updateInfo);
                 Console.WriteLine("{0},{1},{2}", updatedprjct.project_name, updatedprjct.billing_type, updatedprjct.status);
                 var delprjct = projectsApi.Delete(updatedprjct.project_id);
                 Console.WriteLine(delprjct);
                 var inAct = projectsApi.Inactivate(projectId);
                 Console.WriteLine(inAct);
                 var act = projectsApi.Activate(projectId);
                 Console.WriteLine(act);
                 var clonePrjctInfo = new Project()
                 {
                     project_name="clone-test",
                     description="cloned for test"
                 };
                 var clonePrjct = projectsApi.Clone(projectId, clonePrjctInfo);
                 Console.WriteLine("{0},{1},{2}", clonePrjct.project_name, clonePrjct.billing_type, clonePrjct.status);
                 var parameters1 = new Dictionary<object, object>();
                 var taskslist = projectsApi.GetTasks(projectId, parameters1);
                 var tasks = taskslist;
                 var taskId = tasks[0].task_id;
                 foreach (var task in tasks)
                     Console.WriteLine("{0},{1}", task.task_name, task.billed_hours);
                 var task1 = projectsApi.GetATask(projectId, taskId);
                 Console.WriteLine("{0},{1}", task1.task_name, task1.rate);
                 var newTaskInfo = new ProjectTask()
                 {
                     task_name = "task new for test",
                     description = "new task to project",

                 };
                 var newTask = projectsApi.AddATask(projectId, newTaskInfo);
                 Console.WriteLine("{0},{1}", newTask.task_name, newTask.rate);
                 var updateInfo1 = new ProjectTask()
                 {
                     task_name = "ta3",

                 };
                 var updatedTask = projectsApi.UpdateTask(projectId, newTask.task_id, updateInfo1);
                 Console.WriteLine("{0},{1}", updatedTask.task_name, updatedTask.task_id);
                 var delTask = projectsApi.DeleteTask(projectId, updatedTask.task_id);
                 Console.WriteLine(delTask);
                 var usersList = projectsApi.GetUsers(projectId);
                 var users = usersList;
                 var userId = users[0].user_id;
                 foreach (var user in users)
                     Console.WriteLine("{0},{1},{2}", user.user_name, user.user_role, user.rate);
                 var user1 = projectsApi.GetAUser(projectId, userId);
                 Console.WriteLine("{0},{1},{2}", user1.user_name, user1.user_role, user1.rate);
                 var userstoAssign = new UsersToAssign()
                 {
                     users = new List<User>()
                     {
                         new User()
                         {
                             user_id=userId
                         }
                     }
                 };
                 var users1 = projectsApi.AssignUsers(projectId, userstoAssign);
                 foreach (var user in users1)
                     Console.WriteLine("{0},{1},{2}", user.user_name, user.user_role, user.rate);
                 var userInfo = new User()
                 {
                     user_name="name-twst",
                     email="*****@*****.**",
                     user_role="staff"
                 };
                 var user2 = projectsApi.InviteUser(projectId, userInfo);
                Console.WriteLine("{0},{1},{2}", user2.user_name, user2.user_role, user2.rate);
                 var updateInfo2 = new User()
                 {
                     user_name="name",
                     user_role = "admin"
                 };
                 var UpdatedUser = projectsApi.UpdateUser(projectId, user2.user_id, updateInfo2);
                 Console.WriteLine("{0},{1},{2}", UpdatedUser.user_name, UpdatedUser.user_role, UpdatedUser.rate);
                 var deleteUser = projectsApi.DeleteUser(projectId, UpdatedUser.user_id);
                 Console.WriteLine(deleteUser);
                 var parameters2 = new Dictionary<object, object>();
                 var timeEntrieslist = projectsApi.GetTimeEnries(parameters2);
                 var timeEntries = timeEntrieslist;
                 var timeEnteryId = timeEntries[0].time_entry_id;
                 foreach (var timeentry in timeEntries)
                      Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n",timeentry.time_entry_id,timeentry.project_name,timeentry.user_name,timeentry.log_time);
                  var timeentry1 = projectsApi.GetATimeEntry(timeEnteryId);
                  Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n", timeentry1.time_entry_id, timeentry1.project_name, timeentry1.user_name, timeentry1.log_time);
                  var newTimeentryInfo = new TimeEntry()
                  {
                      project_id =projectId,
                      task_id = taskId,
                      user_id = userId,
                      log_date="2014-11-13",
                      log_time="06:46"
                  };
                  var newTimeentry = projectsApi.LogTimeEntry(newTimeentryInfo);
                  Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n", newTimeentry.time_entry_id, newTimeentry.project_name, newTimeentry.user_name, newTimeentry.log_time);
                  var updateInfo3 = new TimeEntry()
                  {
                      project_id = projectId,
                      user_id = userId,
                      log_time="02:00",
                  };
                  var updatedTimeEntry = projectsApi.UpdateTimeEntry(newTimeentry.time_entry_id, updateInfo3);
                  Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n", updatedTimeEntry.time_entry_id, updatedTimeEntry.project_name, updatedTimeEntry.user_name, updatedTimeEntry.log_time);
                  var deleteMsg = projectsApi.DeleteTimeEntry(updatedTimeEntry.time_entry_id);
                  Console.WriteLine(deleteMsg);
                  var parameters3 = new Dictionary<object, object>();
                  parameters3.Add("time_entry_ids", timeEnteryId+","+updatedTimeEntry.time_entry_id);
                  var deleteEntries = projectsApi.DeleteTimeEntries(parameters3);
                  Console.WriteLine(deleteEntries);
                  var timer = projectsApi.GetTimer();
                  Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n", timer.time_entry_id, timer.project_name, timer.user_name, timer.log_time);
                 var timerStart = projectsApi.StartTimer(timeEnteryId);
                 Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n", timerStart.time_entry_id, timerStart.project_name, timerStart.user_name, timerStart.log_time);
                 var stopTimer = projectsApi.StopTimer();
                 Console.WriteLine("time entry of id {0} for the project {1} of user {2} of log time:{3}\n", stopTimer.time_entry_id, stopTimer.project_name, stopTimer.user_name, stopTimer.log_time);
                var commentsList = projectsApi.GetComments(projectId);
                var comments = commentsList;
                foreach (var comment in comments)
                    Console.WriteLine("{0},{1},{2}", comment.comment_id, comment.description, comment.commented_by);
                var newCommentInfo = new Comment()
                {
                    description = "manually added comment",
                };
                var newComment = projectsApi.AddComment(projectId, newCommentInfo);
                Console.WriteLine("{0},{1},{2}", newComment.comment_id, newComment.description, newComment.commented_by);
                var deleteComment = projectsApi.DeleteComment(projectId, newComment.comment_id);
                Console.WriteLine(deleteComment);
                var parameters4 = new Dictionary<object, object>();
                var invoicesList = projectsApi.GetInvoices(projectId, null);
                foreach (var invoice in invoicesList)
                    Console.WriteLine("{0},{1},{2}", invoice.invoice_number, invoice.total, invoice.status);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
 internal static UserList getUserList(HttpResponseMessage responce)
 {
     var userList = new UserList();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("users"))
     {
         var usersArray = JsonConvert.DeserializeObject<List<object>>(jsonObj["users"].ToString());
         foreach(var userObj in usersArray)
         {
             var user = new User();
             user = JsonConvert.DeserializeObject<User>(userObj.ToString());
             userList.Add(user);
         }
     }
     if (jsonObj.ContainsKey("page_context"))
     {
         var pageContext = new PageContext();
         pageContext = JsonConvert.DeserializeObject<PageContext>(jsonObj["page_context"].ToString());
         userList.page_context = pageContext;
     }
     return userList;
 }
 internal static User getUser(HttpResponseMessage responce)
 {
     var user = new User();
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObj.ContainsKey("user"))
     {
         user = JsonConvert.DeserializeObject<User>(jsonObj["user"].ToString());
     }
     return user;
 }
 /// <summary>
 /// Updates the details of a user.
 /// </summary>
 /// <param name="project_id">The project_id is the identifier of the project.</param>
 /// <param name="user_id">The user_id is the identifier of the user who is associated with the specified project.</param>
 /// <param name="update_info">The update_info is the User object which contains the updation information.</param>
 /// <returns>User object.</returns>
 public User UpdateUser(string project_id, string user_id, User update_info)
 {
     string url = baseAddress + "/" + project_id + "/users/" + user_id;
     var json = JsonConvert.SerializeObject(update_info);
     var jsonstring = new Dictionary<object, object>();
     jsonstring.Add("JSONString", json);
     var responce = ZohoHttpClient.put(url, getQueryParameters(jsonstring));
     return ProjectParser.getUser(responce);
 }