Example #1
0
    public SquareContext square()
    {
        SquareContext _localctx = new SquareContext(Context, State);

        EnterRule(_localctx, 16, RULE_square);
        int _la;

        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 74; square_value();
                State = 75;
                _la   = TokenStream.LA(1);
                if (!(_la == SQUARE_METER || _la == HECTARE))
                {
                    ErrorHandler.RecoverInline(this);
                }
                else
                {
                    ErrorHandler.ReportMatch(this);
                    Consume();
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Example #2
0
        private static void AddArtifactTypes(SquareContext context, SquareType security, SquareType privacy)
        {
            var at1 = new ArtifactType() { Name = "System Architecture Diagram", SquareType = security };
            var at2 = new ArtifactType() { Name = "Use Case Scenarios", SquareType = security };
            var at3 = new ArtifactType() { Name = "Use Case Diagram", SquareType = security };
            var at4 = new ArtifactType() { Name = "Misuse Case Scenarios", SquareType = security };
            var at5 = new ArtifactType() { Name = "Misuse Case Diagrams", SquareType = security };
            var at6 = new ArtifactType() { Name = "Attack Trees", SquareType = security };
            var at7 = new ArtifactType() { Name = "Standardized Templates and Forms", SquareType = security };

            var at8 = new ArtifactType() { Name = "System Architecture Diagram", SquareType = privacy };
            var at9 = new ArtifactType() { Name = "Use Case Scenarios", SquareType = privacy };
            var at10 = new ArtifactType() { Name = "Use Case Diagram", SquareType = privacy };
            var at11 = new ArtifactType() { Name = "Attack Trees", SquareType = privacy };
            var at12 = new ArtifactType() { Name = "User-Role Hierarchies", SquareType = privacy };

            context.ArtifactTypes.Add(at1);
            context.ArtifactTypes.Add(at2);
            context.ArtifactTypes.Add(at3);
            context.ArtifactTypes.Add(at4);
            context.ArtifactTypes.Add(at5);
            context.ArtifactTypes.Add(at6);
            context.ArtifactTypes.Add(at7);
            context.ArtifactTypes.Add(at8);
            context.ArtifactTypes.Add(at9);
            context.ArtifactTypes.Add(at10);
            context.ArtifactTypes.Add(at11);
            context.ArtifactTypes.Add(at12);
        }
        public static ProjectTermPredefinedTermsViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string loginId)
        {
            Check.Require(db != null, "Square Entities is required.");
            Check.Require(projectService != null, "projectService is required.");
            Check.Require(loginId != null, "loginId is required.");

            var viewModel = new ProjectTermPredefinedTermsViewModel()
                                {
                                    ProjectStep = db.ProjectSteps.Include("Step").Include("Step.SquareType").Where(a => a.Id == projectStepId).Single(),
                                    Project = db.Projects.Where(a => a.Id == projectId).Single()
                                };

            // load the project step
            var projectStep = viewModel.ProjectStep;

            // load all terms used in project
            var projectTerms = db.ProjectTerms.Where(a => a.Project.Id == projectId && a.SquareType.Id == projectStep.Step.SquareType.Id).ToList();

            // load all terms
            var pt = projectTerms.Select(a => a.Term).ToList();

            // terms that have not been used
            var predefinedTerms = db.Terms.Include("Definitions").Where(a => !pt.Contains(a.Name) && a.IsActive && a.SquareType.Id == projectStep.Step.SquareType.Id).ToList();

            viewModel.PredefinedTerms = predefinedTerms;

            return viewModel;
        }
Example #4
0
 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
 {
     if (string.IsNullOrEmpty(roleName))
             {
                 throw CreateArgumentNullOrEmptyException("roleName");
             }
             using (SquareContext context = new SquareContext())
             {
                 dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
                 if (role == null)
                 {
                     throw new InvalidOperationException("Role not found");
                 }
                 if (throwOnPopulatedRole)
                 {
                     dynamic usersInRole = role.Users.Any;
                     if (usersInRole)
                     {
                         throw new InvalidOperationException(string.Format("Role populated: {0}", roleName));
                     }
                 }
                 else
                 {
                     foreach (User usr_loopVariable in role.Users)
                     {
                        var usr = usr_loopVariable;
                         context.Users.Remove(usr);
                     }
                 }
                 context.Roles.Remove(role);
                 context.SaveChanges();
                 return true;
             }
 }
Example #5
0
        public static CategoryEditViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId, Category category = null)
        {
            Check.Require(projectService != null, "projectService is required.");

            var viewModel = new CategoryEditViewModel() { Category = category ?? new Category()};
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);

            return viewModel;
        }
Example #6
0
        public static Step4ViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId)
        {
            Check.Require(db != null, "db is required.");

            var viewModel = new Step4ViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);
            viewModel.AssessmentTypes = db.AssessmentTypes.Include("SquareType").Where(a => a.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id);
            return viewModel;
        }
Example #7
0
        public static RequirementViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId, Requirement requirement = null)
        {
            Check.Require(db != null, "db is required.");

            var viewModel = new RequirementViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);
            viewModel.Requirement = requirement ?? new Requirement(){RequirementId = string.Format("R{0}", viewModel.Project.Requirements.Count + 1)};

            return viewModel;
        }
        public static GenericElicitationViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId)
        {
            Check.Require(db != null, "db is required.");

            var viewModel = new GenericElicitationViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);
            viewModel.Requirements = viewModel.Project.Requirements.Where(a => a.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id).ToList();

            return viewModel;
        }
        public static ProjectTermAddNewTermViewModel Create(SquareContext db, int stepId, ProjectTerm projectTerm)
        {
            Check.Require(db != null, "Square Entities is required.");
            Check.Require(projectTerm != null, "projectTerm is required.");

            var projectStep = db.ProjectSteps.Include("Step").Include("Step.SquareType").Where(a => a.Id == stepId).Single();
            projectTerm.SquareType = projectStep.Step.SquareType;
            var viewModel = new ProjectTermAddNewTermViewModel() {Step = projectStep.Step, ProjectTerm = projectTerm};

            return viewModel;
        }
        public static RequirementDefectViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId, Requirement requirement, RequirementDefect requirementDefect = null)
        {
            Check.Require(db != null, "db is required.");
            Check.Require(projectService != null, "projectService is required.");
            Check.Require(requirement != null, "requirement is required.");

            var viewModel = new RequirementDefectViewModel(){Requirement = requirement, RequirementDefect = requirementDefect ?? new RequirementDefect()};
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);

            return viewModel;
        }
Example #11
0
        public static Step8ViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId)
        {
            Check.Require(db != null, "db is required.");
            Check.Require(projectService != null, "projectService is required.");

            var viewModel = new Step8ViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);

            viewModel.Requirements = db.Requirements.Include("SquareType").Include("Category").Where(a => a.Project.Id == projectId && a.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id).ToList();

            return viewModel;
        }
Example #12
0
        public static CategoryViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId)
        {
            Check.Require(projectService != null, "projectService is required.");

            var viewModel = new CategoryViewModel() {};
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);

            // extract the categoriest from the project
            viewModel.Categories = db.Categories.Include("SquareType").Where(a => a.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id && a.Project.Id == projectId).ToList();

            return viewModel;
        }
Example #13
0
        public ProjectStepNote AddNoteToProjectStep(int id, string note, string userId)
        {
            using (var db = new SquareContext())
            {
                var projectStep = db.ProjectSteps.Where(a => a.Id == id).FirstOrDefault();
                var psNote = new ProjectStepNote() { Description = note, ProjectStep = projectStep, UserId = userId };

                db.ProjectStepNotes.Add(psNote);
                db.SaveChanges();

                return psNote;
            }
        }
        public static RequirementCategoryViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId, Requirement requirement)
        {
            Check.Require(db != null, "db is required.");
            Check.Require(projectService != null, "projectService is required.");
            Check.Require(requirement != null, "requirement is required.");

            var viewModel = new RequirementCategoryViewModel() {Requirement = requirement};
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);

            viewModel.Categories = db.Categories.Where(a => a.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id && a.Project.Id == projectId).ToList();

            return viewModel;
        }
Example #15
0
        // Seeds the database with the necessary values
        public static void Initilize(SquareContext context = null, bool caseStudy = false)
        {
            // if it's null, then it's not being called from the initializer
            if (context == null)
            {
                // instantiate a new square context
                context =  new SquareContext();

                // wipe the database
                WipeDatabase(context);
            }

            // square types
            var security = new SquareType() { Name = "Security" };
            var privacy = new SquareType() { Name = "Privacy" };

            context.SquareTypes.Add(security);
            context.SquareTypes.Add(privacy);

            AddSecuritySteps(context, security);
            AddPrivacySteps(context, privacy);

            AddArtifactTypes(context, security, privacy);

            AddAssessmentTypes(context, security, privacy);

            AddElicitationTypes(context, security, privacy);

            AddGoalTypes(context, security, privacy);

            AddRiskLevels(context);

            AddSecurityTerms(context, security);

            AddPrivacyTerms(context, privacy);

            AddProjectRoles(context);

            AddPRET(context);

            try
            {
                context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                throw;
            }

            if (caseStudy) InsertCaseStudy(context);
        }
Example #16
0
        public ProjectStepFile AddFileToProjectStep(int id, string note, string filename, string contenttype, byte[] contents, string userId)
        {
            using (var db = new SquareContext())
            {
                var projectStep = db.ProjectSteps.Where(a => a.Id == id).FirstOrDefault();
                var psFile = new ProjectStepFile() { Notes = note, ContentType = contenttype, FileName = filename, ProjectStep = projectStep};
                psFile.Contents = contents;

                db.ProjectStepFiles.Add(psFile);
                db.SaveChanges();

                return psFile;
            }
        }
Example #17
0
        public static PRAUCEditViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string userId, Risk risk = null)
        {
            var viewModel = new PRAUCEditViewModel()
                                {
                                    ProjectStep = projectService.GetProjectStep(projectStepId, userId),
                                    Project = projectService.GetProject(projectId, userId),
                                    RiskLevels = db.RiskLevels.OrderBy(a=>a.Order).ToList(),
                                    Risk = risk ?? new Risk()
                                };

            Check.Ensure(viewModel.Risk.Project.Id == viewModel.Project.Id, "Risk does not belong to the intended project.");

            return viewModel;
        }
Example #18
0
        /// <summary>
        /// Add a term to a project
        /// </summary>
        /// <remarks>Does not validate access</remarks>
        /// <param name="id">Project Id</param>
        /// <param name="squareTypeId">Square Type Id</param>
        /// <param name="term"></param>
        /// <param name="definition"></param>
        /// <param name="source"></param>
        /// <param name="termId"></param>
        /// <param name="definitionId"></param>
        public ProjectTerm AddTermToProject(int id, int squareTypeId, string term, string definition, string source, int termId, int definitionId)
        {
            using (var db = new SquareContext())
            {
                var project = db.Projects.Where(a => a.Id == id).Single();
                var squareType = db.SquareTypes.Where(a => a.Id == squareTypeId).Single();

                // update the parameters with the values from the database
                if (termId > 0 && definitionId > 0)
                {
                    var termObj = db.Terms.Where(a => a.Id == termId).Single();
                    var definitionObj = db.Definitions.Where(a => a.Id == definitionId).Single();

                    // make sure def matches term
                    if (definitionObj.Term.Id != termObj.Id) throw new ArgumentException("Term/Definition mismatch.");

                    // set the parameters, so it can be generated
                    term = termObj.Name;
                    definition = definitionObj.Description;
                    source = definitionObj.Source;
                }

                // add the term to the project
                if (!string.IsNullOrWhiteSpace(term) && !string.IsNullOrWhiteSpace(definition) && !string.IsNullOrWhiteSpace(source))
                {
                    // not project or square type, wtf?
                    // shouldn't happen if null, would have thrown exception in .single() above.
                    if (project == null || squareType == null)
                    {
                        throw new ArgumentException("Project or Square Type Id are invalid");
                    }

                    // create the new term
                    var projectTerm = new ProjectTerm();
                    projectTerm.Term = term;
                    projectTerm.Definition = definition;
                    projectTerm.Source = source;
                    projectTerm.Project = project;
                    projectTerm.SquareType = squareType;

                    // add the project term to the db
                    db.ProjectTerms.Add(projectTerm);
                    db.SaveChanges();

                    return projectTerm;
                }
            }

            return null;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var urlHelper = new UrlHelper(filterContext.RequestContext);

            // if these are null, then the model binder will throw error anyways
            var projectId = Convert.ToInt32(filterContext.RequestContext.HttpContext.Request.Params["projectId"]);
            var id = Convert.ToInt32(filterContext.RouteData.Values["id"]); // project step id
            var logon = filterContext.RequestContext.HttpContext.User.Identity.Name;

            var db = new SquareContext();

            // load pstep
            var pStep = db.ProjectSteps.Include("Project").Include("Project.ProjectWorkers")
                                       .Include("Project.ProjectWorkers.User")
                                       .Include("Project.ProjectWorkers.Role")
                                       .Include("Step").Include("Step.SquareType")
                                       .Where(a => a.Project.Id == projectId && a.Id == id).Single();

            // figure out if the current user has access

            // validate their step access

            Check.Require(pStep != null, "pstep is required.");

            var project = pStep.Project;

            if (!_projectService.IsStepWorking(pStep.Id))
            {
                // this project is not valid for working
                // admin needs to change status
                if (project.ProjectWorkers.Where(a => a.User.Username == logon
                    && a.Role.Name == RoleNames.RoleProjectManager).Any())
                {
                    filterContext.Controller.TempData["ErrorMessage"] = string.Format(Messages.Manager_NotValidForWork,
                                                                                      pStep.Step.Order,
                                                                                      pStep.Step.SquareType.Name);
                    filterContext.Result = new RedirectResult(urlHelper.Action("ChangeStatus", "Project", new { id = pStep.Project.Id }));
                }
                else
                {
                    // regular user, can't access step
                    filterContext.Controller.TempData["ErrorMessage"] = string.Format(Messages.NotValidForWork,
                                                                                      pStep.Step.Order,
                                                                                      pStep.Step.SquareType.Name);
                    filterContext.Result = new RedirectResult(urlHelper.Action("Details", "Project", new { id = projectId }));
                }
            }

            base.OnActionExecuting(filterContext);
        }
Example #20
0
        public static ProjectDetailsViewModel Create(SquareContext db, IProjectService projectService, int id, string loginId)
        {
            Check.Require(db != null, "SquareContext is required.");
            Check.Require(projectService != null, "Project service is required.");
            Check.Require(!string.IsNullOrEmpty(loginId), "login id is required.");

            var viewModel = new ProjectDetailsViewModel()
                                {
                                    Project = projectService.GetProject(id, loginId),
                                    SquareTypes = db.SquareTypes.ToList()
                                    //ProjectSteps = SquareContext.ProjectSteps.Where(a=>a.Project.id == id).ToList()
                                };

            return viewModel;
        }
Example #21
0
        public static ArtifactViewModel Create(SquareContext db, IProjectService projectService, Artifact artifact, int projectStepId, string loginId)
        {
            Check.Require(db != null, "Repository is required.");

            var projectStep = projectService.GetProjectStep(projectStepId, loginId);

            var viewModel = new ArtifactViewModel()
                                {
                                    ArtifactTypes = db.ArtifactTypes.Where(a=>a.SquareType.Id == projectStep.Step.SquareType.Id).ToList(),
                                    ProjectStep = projectStep,
                                    Artifact = artifact ?? new Artifact()
                                };

            return viewModel;
        }
Example #22
0
        public static PRETResultViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string userId, int[] laws)
        {
            Check.Require(db != null, "db is required.");
            Check.Require(projectService != null, "projectService is required.");

            laws = laws ?? new int[0];

            var viewModel = new PRETResultViewModel()
                                {
                                    PretLaws = db.PRETLaws.Where(a=>laws.Contains(a.Id)).ToList(),
                                    PretRequirements = db.PretRequirements.Where(a=>laws.Contains(a.Law.Id)).ToList()
                                };

            viewModel.SetProjectInfo(projectService, projectId, projectStepId, userId);
            return viewModel;
        }
Example #23
0
        public static PRETViewModel Create(SquareContext db, IProjectService projectService, int projectId, int projectStepId, string currentUserId, bool loadQuestions= false, IList<PRETQuestionAnswer> questionAnswers = null)
        {
            Check.Require(projectService != null, "projectService is required.");

            var viewModel = new PRETViewModel() {QuestionAnswers = questionAnswers ?? new List<PRETQuestionAnswer>()} ;
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, currentUserId);

            if (loadQuestions)
            {
                viewModel.PretQuestions = db.PretQuestions.Include("PretAnswers").Include("ParentQuestion").Include("Children").Include("Children.PretAnswers");
            }

            Check.Ensure(viewModel.ProjectStep.Step.SquareType.Name == SquareTypes.Privacy, "PRET only works with privacy.");

            return viewModel;
        }
Example #24
0
        public static Step3ViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string currentUserId)
        {
            Check.Require(db != null, "db is required.");

            var viewModel = new Step3ViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, currentUserId);

            viewModel.Artifacts = db.Artifacts
                                    .Include("ArtifactType")
                                    .Where(
                                        a =>
                                        a.Project.Id == projectId &&
                                        a.ArtifactType.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id)
                                    .OrderBy(a => a.ArtifactType.Name).ThenByDescending(a => a.DateCreated).ToList();

            return viewModel;
        }
Example #25
0
        public static Step1ViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string loginId)
        {
            Check.Require(db != null, "Square Entities is required.");

            var viewModel = new Step1ViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, loginId);

            var projectTerms = db.ProjectTerms.Where(a => a.Project.Id == projectId && a.SquareType.Id == viewModel.ProjectStep.Step.SquareType.Id).ToList();
            viewModel.ProjectTerms = projectTerms;

            var roles = projectService.UserRoles(projectId, loginId);
            viewModel.ProjectManager = roles.Contains(RoleNames.RoleProjectManager);
            viewModel.Stakeholder = roles.Contains(RoleNames.RoleStakeholder);
            viewModel.RequirementsEngineer = roles.Contains(RoleNames.RoleRequirementsEngineer);

            return viewModel;
        }
Example #26
0
        public static RiskAssessmentViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string userId)
        {
            Check.Require(db != null, "db is required.");

            var projectStep = projectService.GetProjectStep(projectStepId, userId);

            var viewModel = new RiskAssessmentViewModel()
            {
                ProjectStep = projectStep,
                Project = projectService.GetProject(projectId, userId),
                Risks = db.Risks.Include("Likelihood").Include("Impact").Include("Magnitude").Include("RiskLevel").Include("RiskRecommendations").Include("Damage")
                                .Where(a => a.Project.Id == projectStep.Project.Id
                                            && a.SquareType.Id == projectStep.Step.SquareType.Id)
                                            .OrderByDescending(a=>a.RiskLevel.Order).ToList()
            };

            return viewModel;
        }
Example #27
0
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     using (SquareContext context = new SquareContext())
             {
                 var users = context.Users.Where(usr => usernames.Contains(usr.Username)).ToList();
                 var roles = context.Roles.Where(rl => roleNames.Contains(rl.RoleName)).ToList();
                 foreach (User user_loopVariable in users)
                 {
                    var user = user_loopVariable;
                     foreach (Role role_loopVariable in roles)
                     {
                       var  role = role_loopVariable;
                         if (!user.Roles.Contains(role))
                         {
                             user.Roles.Add(role);
                         }
                     }
                 }
                 context.SaveChanges();
             }
 }
Example #28
0
 public override void CreateRole(string roleName)
 {
     if (string.IsNullOrEmpty(roleName))
             {
                 throw CreateArgumentNullOrEmptyException("roleName");
             }
             using (SquareContext context = new SquareContext())
             {
                 dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName);
                 if (role != null)
                 {
                     throw new InvalidOperationException(string.Format("Role exists: {0}", roleName));
                 }
                 Role NewRole = new Role
                 {
                     RoleId = Guid.NewGuid(),
                     RoleName = roleName
                 };
                 context.Roles.Add(NewRole);
                 context.SaveChanges();
             }
 }
Example #29
0
        public static Step2ViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string loginId)
        {
            Check.Require(db != null, "Repository is required.");

            var viewModel = new Step2ViewModel();
            viewModel.SetProjectInfo(projectService, projectId, projectStepId, loginId);

            if (viewModel.ProjectStep.Step.SquareType.Name == SquareTypes.Security)
            {
                // load the business goal
                viewModel.BusinessGoal = viewModel.Project.Goals.Where(a => a.GoalType.Id == GoalTypes.Business).SingleOrDefault();

                // load the security goals
                viewModel.SecurityGoals = viewModel.Project.Goals.Where(a => a.GoalType.Id == GoalTypes.Security).ToList();
            }
            else if (viewModel.ProjectStep.Step.SquareType.Name == SquareTypes.Privacy)
            {
                viewModel.PrivacyGoals = viewModel.Project.Goals.Where(a => a.GoalType.Id == GoalTypes.Privacy).ToList();
                viewModel.Assets = viewModel.Project.Goals.Where(a => a.GoalType.Id == GoalTypes.Asset).ToList();
            }

            return viewModel;
        }
Example #30
0
        public static NIST800_30EditViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, int projectId, string userId, Risk risk = null)
        {
            Check.Require(db != null, "db is required.");

            var viewModel = new NIST800_30EditViewModel()
                                {
                                    ProjectStep = projectService.GetProjectStep(projectStepId, userId),
                                    Project = projectService.GetProject(projectId, userId),
                                    RiskLevels = db.RiskLevels.OrderBy(a=>a.Order).ToList(),
                                    Impacts = db.Impacts.ToList(),
                                    Risk = risk ?? new Risk(),
                                    RiskLevelColor = string.Empty
                                };

            // figure out the risk level color, if not null
            if (risk != null)
            {
                viewModel.RiskLevelColor = risk.RiskLevel != null ? risk.RiskLevel.Color : string.Empty;
            }

            Check.Ensure(viewModel.Risk.Project.Id == viewModel.Project.Id, "Risk does not belong to the intended project.");

            return viewModel;
        }
Example #31
0
        public static GoalViewModel Create(SquareContext db, IProjectService projectService, int projectStepId, string login, Goal goal = null)
        {
            Check.Require(db != null, "db is required.");

            var projectStep = projectService.GetProjectStep(projectStepId, login);

            if (goal == null)
            {
                goal = new Goal()
                           {
                               Project = projectStep.Project,
                               SquareType = projectStep.Step.SquareType
                           };
            }

            var viewModel = new GoalViewModel()
                                {
                                    ProjectStep = projectStep,
                                    Goal = goal,
                                    GoalTypes = db.GoalTypes.Include("SquareType").Where(a=>a.SquareType.Id == projectStep.Step.SquareType.Id).ToList()
                                };

            return viewModel;
        }
Example #32
0
 public PointService(SquareContext context)
 {
     this.context = context;
 }