public ActionResult ProjectEventPaymentGenerator(int RepperID, int BudgetID)
        {
            if (RepperID > 0 && BudgetID > 0)
            {
                ReportPeriodListR repper = GetRepper(RepperID, BudgetID);

                ProjectEventService pes = new ProjectEventService();
                ProjectEvent        o   = new ProjectEvent();
                o.CompletedDate    = repper.PaymentDate;
                o.EventDescription = "Payment Request";
                o.ProjectID        = BudgetID;
                //o.EventType = GetPaymentEventType();
                o.EventTypeID    = GetPaymentEventType().EventTypeID;
                o.ReportPeriodID = RepperID;
                o.SSPOrGrantee   = true;
                o.EventStatus    = 0;
                pes.Insert(o);

                EventTemplate   eh = new EventTemplate();
                TemplateService ts = new TemplateService();

                TemplateDocument td1 = null;
                td1 = ts.GetTemplateDocument("Запрос на Оплату");
                if (td1 != null)
                {
                    eh.CreateFromTemplate(td1.TemplateDocsID, BudgetID, o.EventID, RepperID);
                }
            }

            return(RedirectToAction("Reppers", new { id = BudgetID }));
        }
 public ProjectEvent GetProjectEvent(int EventID)
 {
     ProjectEvent result = (from pe in db.ProjectEvents
                  where pe.EventID == EventID
                  select pe).First();
     return result;
 }
Esempio n. 3
0
        /// <summary>
        /// Handles the ItemDataBound event of the gvEvents control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridItemEventArgs"/> instance containing the event data.</param>
        protected void gvEvents_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.EditItem)
            {
                GridDataItem dataItem     = (GridDataItem)e.Item;
                ProjectEvent projectEvent = (ProjectEvent)dataItem.DataItem;
                TextBox      txtEventName = (TextBox)dataItem.FindControl("tbEventName");
                txtEventName.Text = projectEvent.EventName;
            }
            else if (e.Item is GridDataItem)
            {
                GridDataItem dataItem     = (GridDataItem)e.Item;
                ProjectEvent projectEvent = (ProjectEvent)dataItem.DataItem;

                //EventName
                if (ProjectID == 0)
                {
                    dataItem["EventName"].Text = Support.TruncateString(projectEvent.EventName, 20);
                    if (projectEvent.EventName.Length > 20)
                    {
                        dataItem["EventName"].ToolTip = projectEvent.EventName;
                    }
                }
                else
                {
                    dataItem["EventName"].Text = Support.TruncateString(projectEvent.EventName, 80);
                    if (projectEvent.EventName != null && projectEvent.EventName.Length > 80)
                    {
                        dataItem["EventName"].ToolTip = projectEvent.EventName;
                    }
                }
            }
        }
Esempio n. 4
0
 public void AddPossibility(ProjectEvent defaultEvent)
 {
     list.Add(new EventTypeButton(defaultEvent)
     {
         Height = 30,
     });
 }
Esempio n. 5
0
        public void RemoveEvent(ProjectEvent projectEvent)
        {
            if (!(currentEditing.Value is IHasEvents evented))
            {
                return;
            }

            evented.Events.Remove(projectEvent);
        }
Esempio n. 6
0
        public void CreateEvent(ProjectEvent projectEvent)
        {
            if (!(currentEditing.Value is IHasEvents evented))
            {
                return;
            }

            projectEvent.ID = evented.Events.LastOrDefault()?.ID + 1 ?? 1;
            evented.Events.Add(projectEvent);
            eventEditOverlay.ShowEvent(projectEvent);
        }
Esempio n. 7
0
 public CalendarItem(ProjectEvent Event)
 {
     this.Event       = Event;
     this.customEvent = new CustomEvent
     {
         Date = Event.startDate,
         RecurringFrequency      = RecurringFrequencies.Custom,
         EventText               = this.Event.name,
         CustomRecurringFunction = EventDays,
         EndDate    = Event.endDate,
         EventColor = ColorTranslator.FromHtml(Event.color)
     };
 }
Esempio n. 8
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            var form = new AddEventForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                ProjectEvent pe = new ProjectEvent {
                    name = form.text, startDate = form.startDate, endDate = form.endDate, color = ColorTranslator.ToHtml(form.eventColor)
                };
                CalendarItem calendarItem = new CalendarItem(pe);
                calendar1.AddEvent(calendarItem.customEvent);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Handles the ItemDataBound event of the gvEventsRight control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridItemEventArgs"/> instance containing the event data.</param>
        protected void gvEventsRight_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem     = (GridDataItem)e.Item;
                ProjectEvent projectEvent = (ProjectEvent)dataItem.DataItem;

                //Name
                dataItem["EventName"].Text = Support.TruncateString(projectEvent.EventName, 10);
                if (projectEvent.EventName.Length > 10)
                {
                    dataItem["EventName"].ToolTip = projectEvent.EventName;
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds to event grid.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void AddToEventGrid(object sender, EventArgs e)
        {
            if (!PageBase.StopProcessing)
            {
                if (Page.IsValid)
                {
                    ProjectEvent projectEvent = new ProjectEvent();
                    projectEvent.EventName = txtEvent.Text.Trim();

                    if (EventDate.SelectedDate.HasValue)
                    {
                        projectEvent.EventDate = EventDate.SelectedDate;
                    }

                    projectEvent.CreatedByUserId     = UserID;
                    projectEvent.CreatedDate         = Now;
                    projectEvent.LastUpdatedByUserId = UserID;
                    projectEvent.LastUpdatedDate     = Now;

                    if (ProjectID != 0)
                    {
                        #region Project Notification

                        DataContext.Notifications.AddObject(CreateNotification(Support.GetCodeIdByCodeValue("OperationType", "ADD"), string.Format("{0} added a Project Schedule.", Support.UserFullName)));

                        #endregion Project Notification

                        projectEvent.ProjectId = ProjectID;
                        DataContext.ProjectEvents.AddObject(projectEvent);
                        DataContext.SaveChanges();
                    }
                    else
                    {
                        //Will be used from AddNewProject screen.So Saving will not be done.Instead add to the viewState
                        EventList.Add(projectEvent);
                    }
                    LoadData();
                    btnAddKeyDate.Attributes["disabled"] = "disabled";
                    txtEvent.Text = string.Empty;
                    EventDate.Clear();
                    EventDate.DateInput.Clear();
                    gvEvents.DataBind();
                    upnl.Update();
                }

                txtEvent.Focus();
            }
        }
 public bool Insert(ProjectEvent item)
 {
     bool result = true;
     try
     {
         db.ProjectEvents.InsertOnSubmit(item);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         Log.EnsureInitialized();
         Log.Error(typeof(ProjectEventRepository), "----------------------------------------------", ex); 
         result = false;
     }
     return result;
 }
Esempio n. 12
0
        // BaseViewModel (Subscriber pattern ?) with an OnEvent method
        private void OnProjectEvent(ProjectEvent evt)
        {
            var dict = new Dictionary <ProjectEvent.InstructionType, Action>
            {
                { ProjectEvent.InstructionType.New, AddProject },
                { ProjectEvent.InstructionType.Save, SaveCurrentProject },
                { ProjectEvent.InstructionType.Open, OpenProject }
            };

            if (!dict.ContainsKey(evt.Instruction))
            {
                return;
            }

            dict[evt.Instruction]();
        }
        // GET: DashBoard
        public ActionResult SystemBoard()
        {
            var systemeventlist = ProjectEvent.RetrieveEvent(30);

            ViewBag.assignedtasklist = new List <IssueViewModels>();

            var ckdict = CookieUtility.UnpackCookie(this);

            if (ckdict.ContainsKey("logonuser") && !string.IsNullOrEmpty(ckdict["logonuser"]))
            {
                var usernm = ckdict["logonuser"].Split(new char[] { '|' })[0];
                ViewBag.assignedtasklist = IssueViewModels.RetrieveIssueByAssignee(usernm, Resolute.Pending, 60);
            }

            return(View(systemeventlist));
        }
 public bool Update(ProjectEvent item)
 {
     bool result = true;
     try
     {
         /*var oldItem  = (from p in db.ProjectEvents
                        where p.EventID == item.EventID
                        select p).First();*/
         db.ProjectEvents.Attach(item);
         db.Refresh(RefreshMode.KeepCurrentValues,item);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         Log.EnsureInitialized();
         Log.Error(typeof(ProjectEventRepository), "----------------------------------------------", ex); 
         result = false;   
     }
     return result;
 }
        public ActionResult ProjectEventAcceptanceMemoGenerator(int RepperID, int BudgetID)
        {
            if (RepperID > 0 && BudgetID > 0)
            {
                ReportPeriodListR repper = GetRepper(RepperID, BudgetID);

                //Create Event.
                ProjectEventService pes = new ProjectEventService();
                ProjectEvent        o   = new ProjectEvent();
                o.CompletedDate    = repper.PaymentDate;
                o.EventDescription = "Letter to Grantee";
                o.ProjectID        = BudgetID;
                //o.EventType = GetPaymentEventType();
                o.EventTypeID    = GetPaymentEventType().EventTypeID;
                o.ReportPeriodID = RepperID;
                o.SSPOrGrantee   = true;
                o.EventStatus    = 0;

                pes.Insert(o);

                EventTemplate   eh = new EventTemplate();
                TemplateService ts = new TemplateService();

                //Generate Document.
                TemplateDocument td1 = null;
                td1 = ts.GetTemplateDocument("письмо о принятии отчета");
                if (td1 != null)
                {
                    eh.CreateFromTemplate(td1.TemplateDocsID, BudgetID, o.EventID, RepperID);
                }
            }

            return(RedirectToAction("Index", "Events", null));

            // return RedirectToAction("Reppers", new { id = BudgetID });
        }
Esempio n. 16
0
 public EventTypeButton(ProjectEvent type)
 {
     this.type = type;
 }
 public bool Update(ProjectEvent item)
 {
     return(_rep.Update(item));
 }
Esempio n. 18
0
 public ProjectObjectEventContainer(ProjectEvent projectEvent)
 {
     Event = projectEvent;
 }
Esempio n. 19
0
 public EventDescriptor(ProjectEvent model)
 {
     this.model = model;
 }
 private void updateLoadedProjectItem(ProjectEvent projectEvent)
 {
     updateProjectItems(isEnabled: true);
 }
        public ICollection<ProjectEvent> GetUserProjectEvents(string memberUId)
        {
            List<ProjectEvent> events = new List<ProjectEvent>();

            using (var context = new ScrumFactoryEntities(this.connectionString)) {

                System.DateTime limitDate = System.DateTime.Today.AddDays(4);

                ICollection<Project> projects = context.Projects.Include("Sprints").Where(p =>
                    (p.Status == (short) ProjectStatus.PROJECT_STARTED || p.Status == (short) ProjectStatus.PROPOSAL_APPROVED)
                    && p.ProjectType != (short) ProjectTypes.SUPPORT_PROJECT
                    && p.Memberships.Any(ms => ms.MemberUId == memberUId && ms.IsActive==true)
                    && p.Sprints.Any(s =>
                        (s.StartDate < limitDate && s.StartDate >= System.DateTime.Today) ||    // sprints que vão começar
                        (s.EndDate < limitDate && s.EndDate >= System.DateTime.Today)))         // sprints que vão acabar
                        .ToList();

                foreach (Project p in projects) {
                    ProjectEvent e = new ProjectEvent() { ProjectUId = p.ProjectUId, ProjectName = p.ProjectName, ProjectNumber = p.ProjectNumber, EventType = (short)ProjectEventTypes.SPRINT_END };
                    Sprint sprintThatWillStart = p.Sprints.OrderBy(s => s.SprintNumber).FirstOrDefault(s => s.StartDate < limitDate && s.StartDate >= System.DateTime.Today);
                    Sprint sprintThatWillEnd = p.Sprints.OrderBy(s => s.SprintNumber).FirstOrDefault(s => s.EndDate < limitDate && s.EndDate >= System.DateTime.Today);

                    if (sprintThatWillEnd != null) {
                        if(sprintThatWillEnd==p.LastSprint)
                            e.EventType = (short)ProjectEventTypes.PROJECT_END;
                        e.When = sprintThatWillEnd.EndDate;
                        e.SprintNumber = sprintThatWillEnd.SprintNumber;
                    }

                    if(sprintThatWillStart!=null) {
                        e.When = sprintThatWillStart.StartDate;
                        e.SprintNumber = sprintThatWillStart.SprintNumber;
                        if(e.SprintNumber==1)
                            e.EventType = (short)ProjectEventTypes.PROJECT_START;
                    }

                    events.Add(e);

                }

            }

            return events;
        }
Esempio n. 22
0
        /// <summary>
        /// Handles the UpdateCommand event of the gvEvents control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Web.UI.GridCommandEventArgs"/> instance containing the event data.</param>
        protected void gvEvents_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (!PageBase.StopProcessing)
            {
                if (Page.IsValid)
                {
                    //Get the GridEditableItem of the RadGrid
                    GridEditableItem editedItem  = e.Item as GridEditableItem;
                    TextBox          tbEventName = (TextBox)editedItem.FindControl("tbEventName");
                    RadDatePicker    tbEventDate = (RadDatePicker)editedItem.FindControl("tbEventDate");

                    if (ProjectID == 0) //Update viewState
                    {
                        ProjectEvent projectEvent = EventList[editedItem.ItemIndex];
                        projectEvent.EventName           = tbEventName.Text.Trim();
                        projectEvent.LastUpdatedByUserId = UserID;
                        projectEvent.LastUpdatedDate     = Now;
                        projectEvent.EventDate           = tbEventDate.SelectedDate;
                    }
                    else
                    {
                        //Get the primary key value using the DataKeyValue.
                        int      projectEventId          = (int)editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ProjectEventId"];
                        DateTime originalLastUpdatedDate = (DateTime)editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["LastUpdatedDate"];

                        ProjectEvent projectEvent = (from pe in DataContext.ProjectEvents
                                                     where pe.ProjectEventId == projectEventId && pe.LastUpdatedDate == originalLastUpdatedDate
                                                     select pe).FirstOrDefault();

                        if (projectEvent == null)
                        {
                            StageBitzException.ThrowException(new ConcurrencyException(ExceptionOrigin.ProjectDetails, ProjectID));
                        }

                        //Create Notification for edit project events

                        #region Project Notification

                        if (projectEvent.EventName != tbEventName.Text || projectEvent.EventDate != tbEventDate.SelectedDate)
                        {
                            #region Project Notification

                            DataContext.Notifications.AddObject(CreateNotification(Support.GetCodeIdByCodeValue("OperationType", "EDIT"), string.Format("{0} edited a Project Schedule.", Support.UserFullName)));

                            #endregion Project Notification
                        }

                        #endregion Project Notification

                        projectEvent.EventName           = tbEventName.Text;
                        projectEvent.EventDate           = tbEventDate.SelectedDate;
                        projectEvent.LastUpdatedByUserId = UserID;
                        projectEvent.LastUpdatedDate     = Now;

                        DataContext.SaveChanges();
                    }
                    gvEvents.EditIndexes.Clear();
                    gvEvents.MasterTableView.IsItemInserted = false;
                    gvEvents.Rebind();
                }
            }
        }
Esempio n. 23
0
 private void updateLoadedProjectItem(ProjectEvent projectEvent)
 {
     updateProjectItems(isEnabled: true, observedDataEnabled: compoundsAvailableIn(projectEvent.Project));
 }
 public bool Insert(ProjectEvent item)
 {
     return(_rep.Insert(item));
 }
        public ActionResult UserAction(string useraction, ProjectEvent o, string SSPOrGrantee)
        {
            if (Session["ProposalID"] == null)
            {
                return(RedirectToAction("Search", "ProposalInfo"));
            }

            ProjectEventService pes = new ProjectEventService();

            switch (useraction.ToLower())
            {
            case "generate file from template":
                if (o.EventID > 0)
                {
                    pes.Update(o);
                }
                return(RedirectToAction("SelectTemplate", new { ProjectID = o.ProjectID, EventID = o.EventID, EventTypeID = o.EventTypeID, ReportPeriodID = o.ReportPeriodID }));

            case "insert":
                // if (o.EventID > 0)
                pes.Insert(o);
                break;
                return(RedirectToAction("SelectTemplate", new { ProjectID = o.ProjectID, EventID = o.EventID, o.ReportPeriodID }));

            case "update":
                if (o.EventID > 0)       //there must be eventID and user must be logged in.
                {
                    pes.Update(o);
                    if (Request.Files.Count != 0)
                    {
                        for (int i = 0; i < Request.Files.Count; i++)
                        {
                            if (!String.IsNullOrEmpty(Request.Files[i].FileName))
                            {
                                string FileKey;
                                FileKey = Request.Files.GetKey(i);
                                string FileID;
                                FileID = FileKey.Replace("files_", "");

                                string dir = ConfigurationManager.AppSettings["PhysicalPath"];

                                //string MyString="";
                                //int FileLen;
                                //System.IO.Stream MyStream;

                                //FileLen = Request.Files[i].ContentLength;
                                //byte[] input = new byte[FileLen];

                                //// Initialize the stream.
                                //MyStream = Request.Files[i].InputStream;

                                //// Read the file into the byte array.
                                //MyStream.Read(input, 0, FileLen);

                                //// Copy the byte array into a string.
                                //for (int Loop1 = 0; Loop1 < FileLen; Loop1++)
                                //    MyString = MyString + input[Loop1].ToString();
                                string fileOriginalName = Request.Files[i].FileName;
                                string ExtenSion        = Path.GetExtension(fileOriginalName);

                                if (FileID == "0")
                                {
                                    #region InsertNewDocument


                                    ProjectEventDocument myDoc = new ProjectEventDocument();
                                    string virtdir             = "files/" + o.ProjectID.ToString() + "/";//"files/A" + DateTime.Now.Year.ToString().Substring(2) + o.ProjectID.ToString() + "/";
                                    dir += virtdir.Replace("/", "\\");
                                    if (!(Directory.Exists(dir)))
                                    {
                                        Directory.CreateDirectory(dir);
                                    }
                                    string fileformat = o.EventID.ToString() + "_" + o.ProjectID.ToString() + "_";
                                    int    fi;
                                    //checking other file names to come up with new file number.
                                    for (fi = 1; System.IO.File.Exists(dir + fileformat + fi.ToString() + ExtenSion); fi++)
                                    {
                                    }



                                    Request.Files[i].SaveAs(dir + fileformat + fi.ToString() + ExtenSion);

                                    myDoc.Author               = session.CurrentUser.FirstName + " " + session.CurrentUser.LastName + " " + session.CurrentUser.MiddleName;
                                    myDoc.CreatedDate          = DateTime.Now;
                                    myDoc.fileextension        = ExtenSion.Replace(".", ""); //needs "doc"
                                    myDoc.FileName             = fileformat + fi.ToString() + ExtenSion;
                                    myDoc.PhysicalAbsolutePath = dir + fileformat + fi.ToString() + ExtenSion;
                                    myDoc.PhysicalVirtualPath  = "\\" + virtdir.Replace("/", "\\") + fileformat + fi.ToString() + ExtenSion;
                                    myDoc.UpdatedDate          = myDoc.CreatedDate;
                                    myDoc.WebVirtualPath       = "/" + virtdir + fileformat + fi.ToString() + ExtenSion;
                                    pes.InsertDocument(myDoc, o.EventID);
                                    #endregion
                                }
                                else
                                {
                                    #region Update Document      //with different file extension it won't work.
                                    //get object by fileid
                                    //update object

                                    ProjectEventDocument myDoc = pes.GetProjectEventDocument(int.Parse(FileID));
                                    //System.IO.File.WriteAllText(dir + myDoc.PhysicalVirtualPath, MyString);

                                    if (myDoc.fileextension == ExtenSion.Replace(".", ""))      //if extensions are the same then Update allowed.
                                    {
                                        Request.Files[i].SaveAs(dir + myDoc.PhysicalVirtualPath);
                                        myDoc.Author      = session.CurrentUser.FirstName + " " + session.CurrentUser.LastName + " " + session.CurrentUser.MiddleName;;
                                        myDoc.UpdatedDate = DateTime.Now;
                                        pes.UpdateProjectEventDocument(myDoc);
                                    }
                                    //get object by fileid
                                    //update object
                                    #endregion
                                }
                            }
                        }
                    }
                }
                break;

            case "delete":
                string mydir = Request.MapPath("~");
                foreach (var item in o.ProjectEventDocs)
                {
                    try
                    {
                        System.IO.File.Delete(mydir + item.ProjectEventDocument.PhysicalVirtualPath);
                    }
                    catch (Exception ex) { }
                    DeleteMyFile(item.ProjectEventDocumentID, o.EventID);
                }
                pes.Delete(o.EventID);
                break;
            }

            return(RedirectToAction("Index", new { id = o.EventID }));
        }
Esempio n. 26
0
        private object ConvertPayload()
        {
            switch (Event)
            {
            case PingEvent.EventString:
                return(PingEvent.FromJson(PayloadText));

            case CommitCommentEvent.EventString:
                return(CommitCommentEvent.FromJson(PayloadText));

            case CreateEvent.EventString:
                return(CreateEvent.FromJson(PayloadText));

            case DeleteEvent.EventString:
                return(DeleteEvent.FromJson(PayloadText));

            case DeploymentEvent.EventString:
                return(DeploymentEvent.FromJson(PayloadText));

            case DeploymentStatusEvent.EventString:
                return(DeploymentStatusEvent.FromJson(PayloadText));

            case ForkEvent.EventString:
                return(ForkEvent.FromJson(PayloadText));

            case GollumEvent.EventString:
                return(GollumEvent.FromJson(PayloadText));

            case InstallationEvent.EventString:
                return(InstallationEvent.FromJson(PayloadText));

            case InstallationRepositoriesEvent.EventString:
                return(InstallationRepositoriesEvent.FromJson(PayloadText));

            case IssueCommentEvent.EventString:
                return(IssueCommentEvent.FromJson(PayloadText));

            case IssuesEvent.EventString:
                return(IssuesEvent.FromJson(PayloadText));

            case LabelEvent.EventString:
                return(LabelEvent.FromJson(PayloadText));

            case MemberEvent.EventString:
                return(MemberEvent.FromJson(PayloadText));

            case MembershipEvent.EventString:
                return(MembershipEvent.FromJson(PayloadText));

            case MilestoneEvent.EventString:
                return(MilestoneEvent.FromJson(PayloadText));

            case OrganizationEvent.EventString:
                return(OrganizationEvent.FromJson(PayloadText));

            case OrgBlockEvent.EventString:
                return(OrgBlockEvent.FromJson(PayloadText));

            case PageBuildEvent.EventString:
                return(PageBuildEvent.FromJson(PayloadText));

            case ProjectCardEvent.EventString:
                return(ProjectCardEvent.FromJson(PayloadText));

            case ProjectColumnEvent.EventString:
                return(ProjectColumnEvent.FromJson(PayloadText));

            case ProjectEvent.EventString:
                return(ProjectEvent.FromJson(PayloadText));

            case PublicEvent.EventString:
                return(PublicEvent.FromJson(PayloadText));

            case PullRequestEvent.EventString:
                return(PullRequestEvent.FromJson(PayloadText));

            case PullRequestReviewEvent.EventString:
                return(PullRequestReviewEvent.FromJson(PayloadText));

            case PullRequestReviewCommentEvent.EventString:
                return(PullRequestReviewCommentEvent.FromJson(PayloadText));

            case PushEvent.EventString:
                return(PushEvent.FromJson(PayloadText));

            case ReleaseEvent.EventString:
                return(ReleaseEvent.FromJson(PayloadText));

            case RepositoryEvent.EventString:
                return(RepositoryEvent.FromJson(PayloadText));

            case StatusEvent.EventString:
                return(StatusEvent.FromJson(PayloadText));

            case WatchEvent.EventString:
                return(WatchEvent.FromJson(PayloadText));

            default:
                throw new NotImplementedException(
                          $"Event Type: `{Event}` is not implemented. Want it added? Open an issue at https://github.com/promofaux/GithubWebhooks");
            }
        }
        public ICollection <ProjectEvent> GetUserProjectEvents(string memberUId)
        {
            List <ProjectEvent> events = new List <ProjectEvent>();

            using (var context = new ScrumFactoryEntities(this.connectionString)) {
                System.DateTime limitDate = System.DateTime.Today.AddDays(4);

                ICollection <Project> projects = context.Projects.Include("Sprints").Where(p =>
                                                                                           (p.Status == (short)ProjectStatus.PROJECT_STARTED || p.Status == (short)ProjectStatus.PROPOSAL_APPROVED) &&
                                                                                           p.ProjectType != (short)ProjectTypes.SUPPORT_PROJECT &&
                                                                                           p.Memberships.Any(ms => ms.MemberUId == memberUId && ms.IsActive == true) &&
                                                                                           p.Sprints.Any(s =>
                                                                                                         (s.StartDate < limitDate && s.StartDate >= System.DateTime.Today) || // sprints que vão começar
                                                                                                         (s.EndDate < limitDate && s.EndDate >= System.DateTime.Today)))      // sprints que vão acabar
                                                 .ToList();


                foreach (Project p in projects)
                {
                    ProjectEvent e = new ProjectEvent()
                    {
                        ProjectUId = p.ProjectUId, ProjectName = p.ProjectName, ProjectNumber = p.ProjectNumber, EventType = (short)ProjectEventTypes.SPRINT_END
                    };
                    Sprint sprintThatWillStart = p.Sprints.OrderBy(s => s.SprintNumber).FirstOrDefault(s => s.StartDate.Date < limitDate && s.StartDate.Date >= System.DateTime.Today);
                    Sprint sprintThatWillEnd   = p.Sprints.OrderBy(s => s.SprintNumber).FirstOrDefault(s => s.EndDate.Date < limitDate && s.EndDate.Date >= System.DateTime.Today);

                    if (sprintThatWillEnd != null)
                    {
                        if (sprintThatWillEnd == p.LastSprint)
                        {
                            e.EventType = (short)ProjectEventTypes.PROJECT_END;
                        }
                        e.When         = sprintThatWillEnd.EndDate;
                        e.SprintNumber = sprintThatWillEnd.SprintNumber;
                    }
                    else
                    {
                        if (sprintThatWillStart != null)
                        {
                            e.When         = sprintThatWillStart.StartDate;
                            e.SprintNumber = sprintThatWillStart.SprintNumber;
                            if (e.SprintNumber == 1)
                            {
                                e.EventType = (short)ProjectEventTypes.PROJECT_START;
                            }
                            else
                            {
                                e.EventType = (short)ProjectEventTypes.SPRINT_START;
                            }
                        }
                    }

                    events.Add(e);
                }

                // late projects
                try
                {
                    var today = System.DateTime.Today;
                    ICollection <Project> lateProjects = context.Projects.Include("Sprints").Where(p =>
                                                                                                   (p.Status == (short)ProjectStatus.PROJECT_STARTED || p.Status == (short)ProjectStatus.PROPOSAL_APPROVED) &&
                                                                                                   p.ProjectType != (short)ProjectTypes.SUPPORT_PROJECT &&
                                                                                                   p.IsSuspended == false &&
                                                                                                   p.Memberships.Any(ms => ms.MemberUId == memberUId && ms.IsActive == true && ms.Role.PermissionSet == (short)PermissionSets.SCRUM_MASTER) &&
                                                                                                   p.Sprints.Max(s => s.EndDate) < today).ToList();

                    foreach (var p in lateProjects)
                    {
                        var e2 = new ProjectEvent()
                        {
                            ProjectUId = p.ProjectUId, ProjectName = p.ProjectName, ProjectNumber = p.ProjectNumber, EventType = (short)ProjectEventTypes.PROJECT_LATE
                        };
                        e2.When = p.LastSprint.EndDate.Date;
                        events.Add(e2);
                    }
                }
                catch (System.Exception) { }
            }

            return(events);
        }