Esempio n. 1
0
        public virtual async Task <ManagerResult> CreateAsync(SaveProjectViewModel spvm, int requestorId, IUserProvider userProvider)
        {
            if (!userProvider.HasRole(requestorId, RoleNames.Administrator))
            {
                return(new ManagerResult(ManagerErrors.Unauthorized));
            }

            IProjectStatus projectStatus = await GetProjectStore().FindProjectStatusByNameAsync(
                (string.IsNullOrEmpty(spvm.ProjectStatusName) ? ProjectStatusNames.Inactive : spvm.ProjectStatusName));

            if (projectStatus == null)
            {
                return(new ManagerResult(TeamTasksMessages.ProjectStatusNotFound));
            }

            TProject newProject = new TProject();

            newProject.CreatorId       = requestorId;
            newProject.DueDate         = spvm.DueDate;
            newProject.Name            = spvm.Name;
            newProject.ProjectStatusId = projectStatus.Id;
            newProject.StartDate       = spvm.StartDate;

            var baseCreateRes = await base.CreateAsync(newProject);

            if (!baseCreateRes.Success)
            {
                return(baseCreateRes);
            }

            spvm.Id = newProject.Id;

            return(new ManagerResult());
        }
Esempio n. 2
0
        public virtual async Task <ManagerResult> UpdateAsync(SaveProjectViewModel spvm, int requestorId, IUserProvider userProvider)
        {
            if (!userProvider.HasRole(requestorId, RoleNames.Administrator))
            {
                return(new ManagerResult(ManagerErrors.Unauthorized));
            }

            if (string.IsNullOrEmpty(spvm.ProjectStatusName))
            {
                return(new ManagerResult(TeamTasksMessages.ProjectStatusNotSpecified));
            }

            IProjectStatus projectStatus = await GetProjectStore().FindProjectStatusByNameAsync(spvm.ProjectStatusName);

            if (projectStatus == null)
            {
                return(new ManagerResult(TeamTasksMessages.ProjectStatusNotFound));
            }

            if (!spvm.Id.HasValue)
            {
                return(new ManagerResult(ManagerErrors.IdNotSpecified));
            }

            TProject project = await FindByIdAsync(spvm.Id.Value);

            if (project == null)
            {
                return(new ManagerResult(ManagerErrors.RecordNotFound));
            }

            project.Name            = spvm.Name;
            project.StartDate       = spvm.StartDate;
            project.DueDate         = spvm.DueDate;
            project.ProjectStatusId = projectStatus.Id;

            return(await base.UpdateAsync(project));
        }