コード例 #1
0
        public IHttpActionResult CreateProjectStory(int projectId, UserStory model)
        {
            if (projectId != model.ProjectId)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                var transaction = _repoFactory.BeginTransaction();
                try
                {
                    var newStoryId = _repoFactory.ProjectStories.CreateProjectStory(model, transaction);
                    if (newStoryId.HasValue)
                    {
                        model.StoryId = newStoryId.Value;
                        if (!string.IsNullOrWhiteSpace(model.SprintIds))
                        {
                            var sprintIds = model.SprintIds.Split(',');
                            foreach (var s in sprintIds)
                            {
                                if (int.TryParse(s, out var sprintId))
                                {
                                    _repoFactory.Sprints.AddStoryToSprint(sprintId, model.StoryId, transaction);
                                }
                            }
                        }
                        _repoFactory.CommitTransaction();

                        if (!string.IsNullOrWhiteSpace(model.AssignedToUserId) &&
                            !string.Equals(model.AssignedToUserId, UserId, System.StringComparison.OrdinalIgnoreCase))
                        {
                            var receipientName = _cacheService.GetUserName(model.AssignedToUserId);
                            if (!string.IsNullOrWhiteSpace(receipientName))
                            {
                                var receipient    = new MailUser(model.AssignedToUserId, receipientName);
                                var actor         = new MailUser(UserId, DisplayName);
                                var userStoryLink = UrlFactory.GetUserStoryPageUrl(projectId, model.StoryId);
                                _emailService.SendMail(receipient, Core.Enumerations.EmailType.UserStoryAssigned, actor, userStoryLink);
                            }
                        }

                        return(Created($"/api/{projectId}/projectstories/{model.StoryId}", model));
                    }
                }
                catch (System.Exception ex)
                {
                    _repoFactory.RollbackTransaction();
                    _logger.Error(ex, Request.RequestUri.ToString());
                    return(InternalServerError(ex));
                }
            }
            return(BadRequest(ModelState));
        }
コード例 #2
0
        public async Task <IHttpActionResult> UploadFilesToRecord(FileType fileType, int recordId)
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            try
            {
                if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/ProjectFiles")))
                {
                    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/ProjectFiles"));
                }
                string root     = HttpContext.Current.Server.MapPath("~/ProjectFiles");
                var    provider = new CustomMultipartFormDataStreamProvider(root);
                // Read the form data  ( and saves the files in the providers root location)
                await Request.Content.ReadAsMultipartAsync(provider);

                var fileNameKey = provider.FormData.AllKeys.FirstOrDefault(k => k.Equals("filename", StringComparison.OrdinalIgnoreCase));
                var fileName    = provider.FormData.GetValues(fileNameKey)?.FirstOrDefault();
                if (string.IsNullOrWhiteSpace(fileNameKey) || string.IsNullOrWhiteSpace(fileName))
                {
                    return(BadRequest("File Name is required."));
                }

                var transaction = _repoFactory.BeginTransaction();
                try
                {
                    // Get the file names.
                    foreach (MultipartFileData file in provider.FileData)
                    {
                        //Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                        //Trace.WriteLine("Server file path: " + file.LocalFileName);
                        var savedFileName = System.IO.Path.GetFileName(file.LocalFileName);

                        var f = new ProjectFile
                        {
                            AssociatedRecordId = recordId,
                            FileTypeId         = (int)fileType,
                            CreatedByUserId    = base.UserId,
                            FileName           = fileName,
                            FileLocation       = $"/ProjectFiles/{savedFileName}"
                        };
                        _repoFactory.Files.CreateFile(f, transaction);
                    }
                    _repoFactory.CommitTransaction();
                    return(Ok());
                }
                catch (Exception)
                {
                    _repoFactory.RollbackTransaction();
                    throw;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, Request.RequestUri.ToString());
                return(InternalServerError(ex));
            }
        }
コード例 #3
0
 public IHttpActionResult AddStoriesToSprint(int sprintId, IEnumerable <int> storyIds)
 {
     if (storyIds?.Any() == true)
     {
         var dbSprint = _repoFactory.Sprints.GetSprints(sprintId)?.FirstOrDefault();
         if (dbSprint != null)
         {
             var transaction = _repoFactory.BeginTransaction();
             try
             {
                 foreach (var storyId in storyIds)
                 {
                     _repoFactory.Sprints.AddStoryToSprint(sprintId, storyId, transaction);
                 }
                 _repoFactory.CommitTransaction();
                 return(Ok());
             }
             catch (Exception ex)
             {
                 _repoFactory.RollbackTransaction();
                 _logger.Error(ex, Request.RequestUri.ToString());
                 return(InternalServerError(ex));
             }
         }
         return(NotFound());
     }
     return(BadRequest("StoryIds are required."));
 }
コード例 #4
0
        private IHttpActionResult SaveProject(ProjectCreateDto dto)
        {
            var projectModel = new Project
            {
                CompletedDate   = dto.CompletedDate,
                MeetingSchedule = dto.MeetingSchedule,
                PriorityRanking = dto.PriorityRanking,
                ProjectId       = dto.ProjectId,
                ProjectName     = dto.ProjectName,
                ProjectStatus   = dto.ProjectStatusId,
                ProjectType     = dto.ProjectType,
                RequestDate     = dto.RequestDate,
                RequestedByDate = dto.RequestedByDate,
                StartDate       = dto.StartDate,
                TeamID          = dto.TeamID
            };

            Validate(projectModel);
            if (ModelState.IsValid)
            {
                var transaction = _repoFactory.BeginTransaction();
                try
                {
                    var isProjectSaved = false;
                    if (projectModel.ProjectId > 0)
                    {
                        isProjectSaved = _repoFactory.Projects.UpdateProject(projectModel, transaction) > 0;
                        _repoFactory.Projects.DeleteProjectRoleAssignment(projectModel.ProjectId, transaction);
                    }
                    else
                    {
                        var newProjectId = _repoFactory.Projects.CreateProject(projectModel, transaction);
                        isProjectSaved = newProjectId.HasValue && newProjectId.Value > 0;
                        if (isProjectSaved)
                        {
                            projectModel.ProjectId = newProjectId.Value;
                        }
                    }
                    if (isProjectSaved)
                    {
                        var projectRoleAssignments = GetProjectRoleAssignmentsFromDto(projectModel.ProjectId, dto);
                        if (projectRoleAssignments?.Any() == true)
                        {
                            _repoFactory.Projects.CreateProjectRoleAssignments(projectRoleAssignments, transaction);
                        }
                        if (dto.ProjectId == 0)
                        {
                            var notifications = new List <ProjectNotification>();
                            if (!string.IsNullOrWhiteSpace(dto.BusinessAnalystId))
                            {
                                notifications.Add(new ProjectNotification
                                {
                                    Text      = $"<strong>{base.DisplayName}</strong> has created a new project <strong>{dto.ProjectName}</strong> and added you as a <strong>Business Analyst</strong>",
                                    Hyperlink = $"/Projects/{projectModel.ProjectId}",
                                    UserId    = dto.BusinessAnalystId,
                                });
                            }
                            if (!string.IsNullOrWhiteSpace(dto.LeadDeveloperId))
                            {
                                notifications.Add(new ProjectNotification
                                {
                                    Text      = $"<strong>{base.DisplayName}</strong> has created a new project <strong>{dto.ProjectName}</strong> and added you as a <strong>Lead Developer</strong>",
                                    Hyperlink = $"/Projects/{projectModel.ProjectId}",
                                    UserId    = dto.LeadDeveloperId,
                                });
                            }
                            if (!string.IsNullOrWhiteSpace(dto.ProductOwnerId))
                            {
                                notifications.Add(new ProjectNotification
                                {
                                    Text      = $"<strong>{base.DisplayName}</strong> has created a new project <strong>{dto.ProjectName}</strong> and added you as a <strong>Product Owner</strong>",
                                    Hyperlink = $"/Projects/{projectModel.ProjectId}",
                                    UserId    = dto.ProductOwnerId,
                                });
                            }
                            if (!string.IsNullOrWhiteSpace(dto.ProjectManagerId))
                            {
                                notifications.Add(new ProjectNotification
                                {
                                    Text      = $"<strong>{base.DisplayName}</strong> has created a new project <strong>{dto.ProjectName}</strong> and added you as a <strong>Project Manager</strong>",
                                    Hyperlink = $"/Projects/{projectModel.ProjectId}",
                                    UserId    = dto.ProjectManagerId,
                                });
                            }
                            if (!string.IsNullOrWhiteSpace(dto.StakeHolderIds))
                            {
                                notifications.AddRange(
                                    dto.StakeHolderIds?.Split(',').Select(userId => new ProjectNotification
                                {
                                    Text      = $"<strong>{base.DisplayName}</strong> has created a new project <strong>{dto.ProjectName}</strong> and added you as a <strong>Stakeholder</strong>",
                                    Hyperlink = $"/Projects/{projectModel.ProjectId}",
                                    UserId    = UserId,
                                })
                                    );
                            }
                            if (notifications.Any())
                            {
                                notifications = notifications.Where(n => !n.UserId.Equals(base.UserId, System.StringComparison.OrdinalIgnoreCase)).ToList();
                                if (notifications.Any())
                                {
                                    _repoFactory.Notifications.CreateNotifications(notifications, transaction);
                                }
                            }
                        }
                        _repoFactory.CommitTransaction();
                        _cacheService.PurgeProjectNames();
                    }
                    if (dto.ProjectId == 0)
                    {
                        return(Created($"/api/projects/{projectModel.ProjectId}", projectModel));
                    }
                    return(Ok());
                }
                catch (System.Exception ex)
                {
                    _repoFactory.RollbackTransaction();
                    _logger.Error(ex, Request.RequestUri.ToString());
                    return(InternalServerError(ex));
                }
            }
            return(BadRequest(ModelState));
        }