public OutgoingJsonData AddNewBugReport([FromBody] IncomingNewBugReport report)
        {
            var result = new OutgoingJsonData();

            using (var context = new OutboundDetailsContext(Context, Configuration))
            {
                var title = $"{Guid.NewGuid()}";
                context.AddNewBugReport(report, title);
            }
            return(result);
        }
Пример #2
0
        internal void AddNewBugReport(IncomingNewBugReport report, string title)
        {
            var currentItem = new WorkItem();

            currentItem.FoundInBuild = 0;
            // currentItem.ResolvedInBuild = 0;

            var databaseItem = new WorkItem();

            databaseItem.Title          = title;
            databaseItem.WorkItemTypeId = 1;
            databaseItem.StateId        = 1;
            databaseItem.Reason         = 1;
            var projectActiveIteration = Context.AssociatedProjectIterations.Include(x => x.Iteration).FirstOrDefault(x => x.ProjectId == report.ProjectId);

            databaseItem.Iteration         = projectActiveIteration.Iteration.Id;
            databaseItem.AreaId            = 1;
            databaseItem.PriorityId        = 1;
            databaseItem.Activity          = 1;
            databaseItem.RepoSteps         = report.BugDescription;
            databaseItem.SystemInfo        = "-";
            databaseItem.FoundInBuild      = 0;
            databaseItem.IntegratedInBuild = 0;
            databaseItem.Compleated        = "0";
            databaseItem.Remaining         = "0";
            databaseItem.OriginEstitame    = "0";
            databaseItem.Severity          = 1;
            databaseItem.IsPublic          = 1;
//                databaseItem.ParentId = relationshipId;



            databaseItem.StartDate = DateTime.Now;
            databaseItem.EndDate   = DateTime.Now.AddMonths(1);
            databaseItem.DueDate   = DateTime.Now.AddMonths(1);
            var item = Context.WorkItem.Add(databaseItem);

            Context.SaveChanges();


            var pBoard = Context.AssociatedProjectBoards.Include(x => x.Board).FirstOrDefault(x => x.ProjectId == report.ProjectId && x.Board.BoardName == "Open");

            if (pBoard != null)
            {
                Context.AssociatedBoardWorkItems.Add(new AssociatedBoardWorkItems {
                    BoardId    = pBoard.BoardId.Value,
                    WorkItemId = item.Entity.Id,
                    ProjectId  = report.ProjectId
                });
                Context.SaveChanges();
            }


            var currentUser = "******";

            var notification = Context.Notifications.Add(new Notifications {
                DateOfMessage    = DateTime.Now,
                Content          = $"Work Item  Title:{item.Entity.Title} ID:{item.Entity.Id}- Has been created and assigned to {currentUser}, the item has been automatically generated by the bug reporting tool",
                NotificationType = 3,
            });

            Context.SaveChanges();
            var projectUsers = Context.AssociatedProjectMembers.Where(x => x.ProjectId == report.ProjectId).ToList();

            //Todo: Thows duplicate error, database mapping should be reworked to allow cross project notification based on user view
            projectUsers.ForEach(x => {
                Context.AssociatedProjectNotifications.Add(new AssociatedProjectNotifications {
                    NotificationId  = notification.Entity.Id,
                    ProjectId       = report.ProjectId,
                    NewNotification = 1,
                    IsRead          = 0,
                    UserAccountId   = x.UserAccountId
                });
                Context.SaveChanges();
            });
            if (string.IsNullOrEmpty(report.ImagePath))
            {
                return;
            }
            var file = Context.SystemFiles.Add(new SystemFiles {
                FileType      = 1,
                FileLocation  = report.ImagePath,
                SenderName    = report.SenderName,
                DateOfMessage = DateTime.Now
            });

            Context.SaveChanges();
            Context.AssociatedWorkItemFiles.Add(new AssociatedWorkItemFiles {
                FileId     = file.Entity.Id,
                WorkItemId = databaseItem.Id
            });
            Context.SaveChanges();
        }