// GET: /Comment/Create/4
        public ActionResult Create(int? id)
        {
            string user = User.Identity.Name;
            if (hasActiveStandardSubscription(user) || hasActiveUltimateSubscription(user))
            {
                if (id == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                Comment comment = new Comment
                {
                    WorkObjectID = id.GetValueOrDefault()
                };

                WorkObject workobject = db.WorkObjects.Find(id);
                // improves mvc security
                if ((workobject.TeamQueue == TeamQueueType.Claims && User.IsInRole("claims")) ||
                     (workobject.TeamQueue == TeamQueueType.Servicing && User.IsInRole("servicing")) ||
                     (workobject.TeamQueue == TeamQueueType.New_Business && User.IsInRole("new_business")))
                {
                    if ((workobject.isLocked == true && workobject.LockedBy == User.Identity.Name) || workobject.isLocked == false)
                    {
                        return View(comment);
                    }
                    else
                    {
                        return RedirectToAction("Details", "WorkObject", new { id = comment.WorkObjectID });
                    }
                }
                else
                {
                    return RedirectToAction("Index", "WorkObject");
                }
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }
        // change status and record it as a new comment
        void changeStatus(WorkObject workObjectToUpdate, StatusType before)
        {
            if (workObjectToUpdate.Status != before)
            {
                StatusType after = workObjectToUpdate.Status;
                int id_ = workObjectToUpdate.WorkObjectID;

                if (before == StatusType.Open && after == StatusType.Process) // open -> process
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Open to Process ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Open && after == StatusType.Delay) // open -> delay
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Open to Delay ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Open && after == StatusType.End) // open -> end
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Open to End ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Open && after == StatusType.Processed) // open -> processed
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Open to Processed ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Process && after == StatusType.Open) // process -> open
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Process to Open ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Process && after == StatusType.Processed) // process -> processed
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Process to Processed ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Process && after == StatusType.Delay) // process -> delay
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Process to Delay ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Process && after == StatusType.End) // process -> end
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Process to Delay ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Process && after == StatusType.End) // process -> end
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Process to Delay ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Delay && after == StatusType.Processed) // delay -> processed
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Delay to Processed ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Delay && after == StatusType.Open) // delay -> open
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Delay to Open ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Delay && after == StatusType.End) // delay -> end
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Delay to End ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == StatusType.Delay && after == StatusType.Process) // delay -> process
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Status changed: Delay to Process ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                } // processed and end status mean a workobject is in history queue and cannot be edited
            }
        }
        // check and change the priority level based on time elapsed - triggered on index and details views
        void checkPriority()
        {
            var workObjects = from s in db.WorkObjects select s;
            try
            {
                foreach (var w in workObjects)
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    DateTime dateToCheck = currentTime;

                     // 4 up days range
                    if (w.StartDate.AddDays(4) <= dateToCheck && w.Priority <= PriorityType.High)
                    {
                        w.Priority = PriorityType.Urgent;
                        Comment newComment = new Comment { WorkObjectID = w.WorkObjectID, Content = "*** Priority changed to Urgent (+4 days) ***", Timestamp = currentTime, User = "******" };
                        db.Comments.Add(newComment);
                    }
                    // 3 to 4 days range
                    else if (w.StartDate.AddDays(3) <= dateToCheck && dateToCheck < w.StartDate.AddDays(4) && w.Priority <= PriorityType.Normal)
                    {
                        w.Priority = PriorityType.High;
                        Comment newComment = new Comment { WorkObjectID = w.WorkObjectID, Content = "*** Priority changed to High (+3 days) ***", Timestamp = currentTime, User = "******" };
                        db.Comments.Add(newComment);
                    }
                     // 2 to 3 days range
                    else if (w.StartDate.AddDays(2) <= dateToCheck && dateToCheck < w.StartDate.AddDays(3) && w.Priority <= PriorityType.Low)
                    {
                        w.Priority = PriorityType.Normal;
                        Comment newComment = new Comment { WorkObjectID = w.WorkObjectID, Content = "*** Priority changed to Normal (+2 days) ***", Timestamp = currentTime, User = "******" };
                        db.Comments.Add(newComment);
                    }
                    // 1 to 2 days range
                    else if (w.StartDate.AddDays(1) <= dateToCheck && dateToCheck < w.StartDate.AddDays(2) && w.Priority == PriorityType.Lowest)
                    {
                        w.Priority = PriorityType.Low;
                        Comment newComment = new Comment { WorkObjectID = w.WorkObjectID, Content = "*** Priority changed to Low (+1 day) ***", Timestamp = currentTime, User = "******" };
                        db.Comments.Add(newComment);
                    }
                }
                db.SaveChanges();
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }
        }
        void changePriority(WorkObject workObjectToUpdate, PriorityType before)
        {
            if (workObjectToUpdate.Priority != before)
            {
                PriorityType after = workObjectToUpdate.Priority;
                int id_ = workObjectToUpdate.WorkObjectID;

                if (before == PriorityType.Lowest && after == PriorityType.Low) // lowest -> low
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Lowest to Low ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Lowest && after == PriorityType.Normal) // lowest -> normal
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Lowest to Normal ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Lowest && after == PriorityType.High) // lowest -> high
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Lowest to High ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Lowest && after == PriorityType.High) // lowest -> urgent
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Lowest to Urgent ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Low && after == PriorityType.Lowest) // low -> lowest
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Low to Lowest ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Low && after == PriorityType.Normal) // low -> normal
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Low to Normal ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Low && after == PriorityType.High) // low -> high
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Low to High ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Low && after == PriorityType.High) // low -> urgent
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Low to Urgent ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Normal && after == PriorityType.Lowest) // normal -> lowest
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Normal to Lowest ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Normal && after == PriorityType.Low) // normal -> low
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Normal to Low ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Normal && after == PriorityType.High) // normal -> high
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Normal to High ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Normal && after == PriorityType.High) // normal -> urgent
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Normal to Urgent ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.High && after == PriorityType.Lowest) // high -> lowest
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: High to Lowest ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.High && after == PriorityType.Low) // high -> low
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: High to Low ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.High && after == PriorityType.Low) // high -> normal
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: High to Normal ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.High && after == PriorityType.Low) // high -> urgent
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: High to Urgent ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Urgent && after == PriorityType.Lowest) // urgent -> lowest
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Urgent to Lowest ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Urgent && after == PriorityType.Low) // urgent -> low
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Urgent to Low ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Urgent && after == PriorityType.Normal) // urgent -> normal
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Urgent to Normal ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
                else if (before == PriorityType.Urgent && after == PriorityType.High) // urgent -> high
                {
                    // converts time to Greenwich Mean Time
                    DateTime currentTime = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");

                    Comment newComment = new Comment { WorkObjectID = id_, Content = "*** Priority changed: Urgent to High ***", Timestamp = currentTime, User = User.Identity.Name };
                    db.Comments.Add(newComment);
                }
            }
        }