Exemplo n.º 1
0
        /**/

        /*
         * NAME:
         *      CreateUserProject - creates a new project for the user, making him/her an administrator for the project
         * SYNOPSIS:
         *      CreateUserProject(Project project, AppUser user)
         *           project --> the Projectobject representing the project to be added
         *          user --> the object representing the user who is creating the project
         * DESCRIPTION:
         *      Accesses the database context in order to add a new Project entry to the database. It also adds a ProjectUser entry
         *          that describes the relationship of the user the newly created project
         * RETURNS
         *      the Project object that was added
         * AUTHOR
         *      Biplab Thapa Magar
         * DATE
         *      09/21/2020
         * /
         * /**/
        public Project CreateUserProject(Project project, AppUser user)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            //add the date created attribute to the project
            project.TimeCreated = DateTime.Now;

            //create the new project
            _context.Add(project);

            //create a new Project user entry to assign the user to the project as a manager
            ProjectUser projectUser = new ProjectUser {
                Project = project
            };

            projectUser.AppUserId = user.Id;
            projectUser.Role      = "Administrator";
            projectUser.TimeAdded = DateTime.Now;
            //finally, add the ProjectUserEntry
            _context.Add(projectUser);

            //return the created project
            return(project);
        }
Exemplo n.º 2
0
        /**/

        /*
         * NAME:
         *      AddUserToProject - adds a user to a project
         * SYNOPSIS:
         *      AddUserToProject(ProjectUser projectUser)
         *           projectUser --> the ProjectUser object that represents the project-user relationship
         * DESCRIPTION:
         *      Accesses the database context in order to add the ProjectUser entry representing the user's
         *          membership in the project
         * RETURNS
         * AUTHOR
         *      Biplab Thapa Magar
         * DATE
         *      09/10/2020
         * /
         * /**/
        public void AddUserToProject(ProjectUser projectUser)
        {
            if (projectUser == null)
            {
                throw new ArgumentNullException(nameof(projectUser));
            }

            _context.Add(projectUser);
        }
        /**/

        /*
         * NAME:
         *      CreateTaskType - creates a new task type
         * SYNOPSIS:
         *      CreateTaskType(int projectId, string name)
         *           projectId --> the id of the project for which the task type is being created
         *          name --> the name of the task type
         * DESCRIPTION:
         *      Accesses the database context in order to create a new task type
         * RETURNS
         *      The TaskType object that was created
         * AUTHOR
         *      Biplab Thapa Magar
         * DATE
         *      09/02/2020
         * /
         * /**/
        public TaskType CreateTaskType(int projectId, string name)
        {
            TaskType taskType = new TaskType()
            {
                ProjectId = projectId, Name = name
            };

            _context.Add(taskType);
            return(taskType);
        }
Exemplo n.º 4
0
        /**/

        /*
         * NAME:
         *      UpdateTask - updates a task and records the task update too
         * SYNOPSIS:
         *      UpdateTask(Task task, string updaterId)
         *           task --> the task that is to be updated (it must contain the updated values; taskId must stay the same)
         *          updaterId --> the id of the user who made the update
         * DESCRIPTION:
         *      Accesses the database context in order to update the task. Simultaneouslyk this function generates a TaskUpdate
         *      entry from the given information, so that the program can keep track of activity
         * RETURNS
         *      The updated task object
         * AUTHOR
         *      Biplab Thapa Magar
         * DATE
         *      09/06/2020
         * /
         * /**/
        public Task UpdateTask(Task task, string updaterId)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }


            var taskToUpdate = _context.Tasks.Find(task.TaskId);

            //now, for each changed value, store a TaskUpdate record with the updated value

            //time of task update
            var timeStamp = DateTime.Now;

            //for every updateable field in the Task object, if there was a change, then add a TaskUpdate entry
            //if the name of the task was changed
            if (task.Name != taskToUpdate.Name)
            {
                //add the updated name to the taskUpdate object
                var taskNameUpdate = new TaskUpdate {
                    TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId
                };
                taskNameUpdate.Name = task.Name;
                _context.Add(taskNameUpdate);
            }
            //if the taskstatus of the task was changed
            if (task.TaskStatus != taskToUpdate.TaskStatus)
            {
                //add the updated TaskStatus to the taskUpdate object
                var taskStatusUpdate = new TaskUpdate {
                    TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId
                };
                taskStatusUpdate.TaskStatus = task.TaskStatus;
                _context.Add(taskStatusUpdate);
            }
            //if the Urgency of the task was changed
            if (task.Urgency != taskToUpdate.Urgency)
            {
                //add the updated Urgency to the taskUpdate object
                var taskUrgencyUpdate = new TaskUpdate {
                    TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId
                };
                taskUrgencyUpdate.Urgency = task.Urgency;
                _context.Add(taskUrgencyUpdate);
            }
            //if the TaskTypeId of the task was changed
            if (task.TaskTypeId != taskToUpdate.TaskTypeId)
            {
                //add the updated TaskTypeId to the taskUpdate object
                var taskTypeUpdate = new TaskUpdate {
                    TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId
                };
                taskTypeUpdate.TaskTypeId = task.TaskTypeId;
                _context.Add(taskTypeUpdate);
            }

            //update the task
            _context.Entry(taskToUpdate).CurrentValues.SetValues(task);

            return(task);
        }