Пример #1
0
        //
        // Summary:
        //     Finds and modifies a task with new data.
        //
        // Parameters:
        //   task:
        //     The Task with the new data (and the task Id).
        //
        //   userId:
        //     The userId of the user associated with task to modify.
        //
        // Returns:
        //     The new modified task.
        //
        public Models.Task ModifyTask(Models.Task task, string userId)
        {
            try
            {
                long longUserId;
                if (!(long.TryParse(userId, out longUserId)))
                {
                    throw new Exception("Token not valid");
                }

                if (!IsUserTaskExist(longUserId, task.TaskId))
                {
                    throw new Exception("User is not permitted to modify task");
                }

                _context.Entry(task).State = EntityState.Modified;
                _context.SaveChanges();

                return(task);
            }
            catch (Exception err)
            {
                throw err;
            }
        }