Exemple #1
0
        /// <summary>
        /// Called when the <see cref="AddPRButton"/> is clicked. Adds the PR with the number in <see cref="AddPRNumericUpDown"/> to <see cref="PullRequestListBox"/> or shows an error prompt if it doesn't/already exists
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The <see cref="EventArgs"/></param>
        async void AddPRButton_Click(object sender, EventArgs e)
        {
            Enabled       = false;
            UseWaitCursor = true;
            try
            {
                IList <PullRequestInfo> pulls = null;
                string error           = null;
                var    mergedPullsTask = WrapServerOp(() => pulls = currentInterface.GetComponent <ITGRepository>().MergedPullRequests(out error));

                int PRNumber;
                try
                {
                    PRNumber = Convert.ToInt32(AddPRNumericUpDown.Value);
                }
                catch
                {
                    MessageBox.Show("Invalid PR number!");
                    return;
                }
                var found    = false;
                var asString = PRNumber.ToString();
                foreach (var I in PullRequestListBox.Items)
                {
                    if (((string)I).Split(' ')[0].Substring(1) == asString)
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    MessageBox.Show("That PR is already in the list!");
                    return;
                }

                await mergedPullsTask;
                if (pulls == null)
                {
                    MessageBox.Show(String.Format(MergedPullsError, error));
                }
                //get the PR in question
                var PR = await client.Issue.Get(repoName, repoOwner, PRNumber);

                if (PR == null || PR.PullRequest == null)
                {
                    MessageBox.Show("That doesn't seem to be a valid PR!");
                    return;
                }
                InsertPullRequest(PR, true, pulls == null || pulls.Any(x => x.Number == PRNumber));
            }
            finally
            {
                UseWaitCursor = false;
                Enabled       = true;
            }
        }
Exemple #2
0
        protected override void onBeforeSaving(PurchaseRequest entity, BaseEntity parent = null, OPERATION_MODE mode = OPERATION_MODE.NONE)
        {
            if (mode == OPERATION_MODE.ADD)
            {
                var ctx = context as POContext;
                if (entity.GeneralManager != null)
                {
                    ctx.Entry(entity.GeneralManager).State = EntityState.Unchanged;
                }
                if (entity.Requisitor != null)
                {
                    ctx.Entry(entity.Requisitor).State = EntityState.Unchanged;
                }
                if (entity.DepartmentAssigned != null)
                {
                    ctx.Entry(entity.DepartmentAssigned).State = EntityState.Unchanged;
                }
                if (entity.DepartmentManager != null)
                {
                    ctx.Entry(entity.DepartmentManager).State = EntityState.Unchanged;
                }

                //if (string.IsNullOrWhiteSpace(entity.FriendlyIdentifier))
                //{
                //    throw new KnownError("Friendly identifier is a required field");
                //}


                #region PR Number Generation

                DateTimeOffset date = DateTimeOffset.Now;

                int sequence = 0;
                var last     = ctx.PRNumbers.Where(n => n.CreatedAt.Year == date.Year &&
                                                   n.CreatedAt.Month == date.Month && n.CreatedAt.Day == date.Day).OrderByDescending(n => n.Sequence)
                               .FirstOrDefault();

                if (last != null)
                {
                    sequence = last.Sequence + 1;
                }

                string generated = date.Year.ToString().Substring(2) + date.Month.ToString("D2") + date.Day.ToString("D2") + sequence.ToString("D3");


                PRNumber cqaNumber = ctx.PRNumbers.Add(new PRNumber()
                {
                    CreatedAt       = date,
                    Sequence        = sequence,
                    GeneratedNumber = generated,
                    Revision        = "A"
                });

                ctx.SaveChanges();

                entity.PRNumberKey = cqaNumber.PRNumberKey;

                #endregion

                #region
                var comment = new Comment();
                comment.CommentByUserKey = LoggedUser.LocalUser.UserKey;
                ctx.Comments.Add(comment);
                ctx.SaveChanges();
                entity.CommentKey = comment.CommentKey;
                #endregion

                entity.RequisitorKey = LoggedUser.LocalUser.UserKey;
            }


            #region Attachments
            string baseAttachmentsPath = ConfigurationManager.AppSettings["PR_Attachments"];
            if (entity != null && entity.Attachments != null)
            {
                foreach (var file in entity.Attachments)
                {
                    if (file.ToDelete)
                    {
                        string filePath = baseAttachmentsPath + "\\" + file.Directory + "\\" + file.FileName;
                        AttachmentsIO.DeleteFile(filePath);
                    }
                }
            }

            #endregion
        }