public ActionResult DoAddBug(Bug bug)
        {
            var errors = GetBugValidationErrors(bug);
            if (errors.Count > 0)
            {
                return View("InvalidBug", errors);
            }

            bug.DateFound = DateTime.Now;
            bug.Status = BugStatus.New;
            bug.TesterId = WebSecurity.CurrentUserId;

            context.Bugs.Add(bug);
            var tester = context.Testers
                .Where(t => t.TesterId == WebSecurity.CurrentUserId)
                .FirstOrDefault();

            tester.LastAction = "Added new bug";
            tester.LastActionDate = DateTime.Now;

            var project = context.Projects.Where(p => p.ProjectId == bug.ProjectId)
                .FirstOrDefault();

            if(!tester.Projects.Any(p => p.ProjectId == project.ProjectId))
            {
                tester.Projects.Add(project);
            }

            context.SaveChanges();

            return View("BugAdded");
        }
        private List<string> GetBugValidationErrors(Bug bug)
        {
            List<string> errors = new List<string>();

            if (string.IsNullOrEmpty(bug.Description) || string.IsNullOrWhiteSpace(bug.Description))
            {
                errors.Add("The description should not be empty");
            }

            return errors;
        }
        public ActionResult DoEditBug(Bug bug)
        {
            var errors = GetBugValidationErrors(bug);
            if (errors.Count > 0)
            {
                return View("InvalidBug", errors);
            }

            var entity = context.Bugs
                .Where(b => b.BugId == bug.BugId).FirstOrDefault();

            entity.Description = bug.Description;
            entity.Priority = bug.Priority;
            entity.Status = bug.Status;

            var tester = context.Testers
                .Where(t => t.TesterId == WebSecurity.CurrentUserId)
                .FirstOrDefault();

            tester.LastAction = string.Format("Edited bug #{0}", bug.BugId);
            tester.LastActionDate = DateTime.Now;
            context.SaveChanges();

            return View("BugEdited");
        }