Exemplo n.º 1
0
        /// <summary>
        /// Adding Point to context
        /// </summary>
        /// <param name="point">Point object</param>
        /// <returns>Returns inserted Point identifier</returns>
        public int Add(Point point)
        {
            context.Add(point);
            context.SaveChanges();

            return(point.Id);
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        public string SquareOf(Square square)
        {
            int a = square.a;
            int h = square.h;

            square.count(a, h);
            double s1 = square.s1;

            square.Date = DateTime.Now;
            sqdb.Squares.Add(square);
            sqdb.SaveChanges();

            return("<h2>Площадь треугольника с основанием " + a +
                   " и высотой " + h + " равна " + s1 + "</h2>" +
                   "<td><a href = \"/Home/SquareOf\"> Еще раз</a></td>" +
                   "<br><td><a href = \"/Home/Index\"> Главная</a></td></br>");
        }
Exemplo n.º 5
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();
             }
 }
Exemplo n.º 6
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();
             }
 }
Exemplo n.º 7
0
        public void SaveDefect(int projectId, int requirementId, string defectText, string loginId)
        {
            var project = GetProject(projectId, loginId);

            using (var db = new SquareContext())
            {
                var requirement = db.Requirements.Where(a => a.Id == requirementId).Single();

                var defect = new RequirementDefect() {Description = defectText, Requirement = requirement};

                db.RequirementDefects.Add(defect);
                db.SaveChanges();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Save an artifact
        /// </summary>
        /// <param name="id">Project Step Id</param>
        /// <param name="artifact"></param>
        /// <param name="loginId"></param>
        /// <returns></returns>
        public Artifact SaveArtifact(int id, Artifact artifact, int? artifactId, int? artifactTypeId)
        {
            using (var db = new SquareContext())
            {
                // load the project step
                var projectStep = db.ProjectSteps
                                    .Include("Step").Include("Step.SquareType")
                                    .Include("Project")
                                    .Where(a => a.Id == id).Single();

                // list of artifact types for this square type
                var artifactTypes = db.ArtifactTypes.Where(a => a.SquareType.Id == projectStep.Step.SquareType.Id).Select(a => a.Id).ToList();

                var artifactType = artifact.ArtifactType ?? db.ArtifactTypes.Include("SquareType").Where(a => a.Id == artifactTypeId).Single();

                // wrong artifact type for the project step
                if (!artifactTypes.Contains(artifactType.Id)) return null;

                // update an existing artifact
                if (artifactId.HasValue)
                {
                    var artifactToSave = db.Artifacts.Where(a => a.Id == artifactId).Single();

                    artifactToSave.Name = artifact.Name;
                    artifactToSave.Description = artifact.Description;
                    artifactToSave.ArtifactType = artifactType;

                    // only update file contents if there is a new file, otherwise keep old contents
                    if (artifact.ContentType != null && artifact.Data != null)
                    {
                        artifactToSave.ContentType = artifact.ContentType;
                        artifactToSave.Data = artifact.Data;
                    }
                }
                // fill in the new artifact
                else
                {
                    artifact.ArtifactType = artifactType;
                    artifact.Project = projectStep.Project;

                    db.Artifacts.Add(artifact);
                }

                db.SaveChanges();

                return artifact;
            }
        }
Exemplo n.º 9
0
        public void SaveCategory(int id, Category category, int? categoryId)
        {
            using (var db = new SquareContext())
            {
                var projectStep = db.ProjectSteps.Include("Project")
                                                 .Include("Step")
                                                 .Include("Step.SquareType")
                                                 .Where(a => a.Id == id).Single();

                // update existing category
                if (categoryId.HasValue)
                {
                    var categoryToSave = db.Categories.Where(a => a.Id == categoryId).Single();

                    categoryToSave.Name = category.Name;
                }
                // setting an existing one
                else
                {
                    category.Project = projectStep.Project;
                    category.SquareType = projectStep.Step.SquareType;

                    db.Categories.Add(category);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 10
0
 public override string ExtendedValidateUser(string userNameOrEmail, string password)
 {
     if (string.IsNullOrEmpty(userNameOrEmail))
             {
                 throw CreateArgumentNullOrEmptyException("userNameOrEmail");
             }
             if (string.IsNullOrEmpty(password))
             {
                 throw CreateArgumentNullOrEmptyException("password");
             }
             using (SquareContext context = new SquareContext())
             {
                 User user = null;
                 user = context.Users.FirstOrDefault(Usr => Usr.Username == userNameOrEmail);
                 if (user == null)
                 {
                     user = context.Users.FirstOrDefault(Usr => Usr.Email == userNameOrEmail);
                 }
                 if (user == null)
                 {
                     return string.Empty;
                 }
                 if (!user.IsConfirmed)
                 {
                     return string.Empty;
                 }
                 dynamic hashedPassword = user.Password;
                 bool verificationSucceeded = (hashedPassword != null && CodeFirstCrypto.VerifyHashedPassword(hashedPassword, password));
                 if (verificationSucceeded)
                 {
                     user.PasswordFailuresSinceLastSuccess = 0;
                 }
                 else
                 {
                     int failures = user.PasswordFailuresSinceLastSuccess;
                     if (failures != -1)
                     {
                         user.PasswordFailuresSinceLastSuccess += 1;
                         user.LastPasswordFailureDate = DateTime.UtcNow;
                     }
                 }
                 context.SaveChanges();
                 if (verificationSucceeded)
                 {
                     return user.Username;
                 }
                 else
                 {
                     return string.Empty;
                 }
             }
 }
Exemplo n.º 11
0
 public override bool ResetPasswordWithToken(string token, string newPassword)
 {
     if (string.IsNullOrEmpty(newPassword))
             {
                 throw CreateArgumentNullOrEmptyException("newPassword");
             }
             using (SquareContext context = new SquareContext())
             {
                 dynamic user = context.Users.FirstOrDefault(Usr => Usr.PasswordVerificationToken == token && Usr.PasswordVerificationTokenExpirationDate > DateTime.UtcNow);
                 if (user != null)
                 {
                     dynamic newhashedPassword = CodeFirstCrypto.HashPassword(newPassword);
                     if (newhashedPassword.Length > 128)
                     {
                         throw new ArgumentException("Password too long");
                     }
                     user.Password = newhashedPassword;
                     user.PasswordChangedDate = DateTime.UtcNow;
                     user.PasswordVerificationToken = null;
                     user.PasswordVerificationTokenExpirationDate = null;
                     context.SaveChanges();
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Save a Requirement
        /// </summary>
        /// <param name="id">Project Id</param>
        /// <param name="squareType">Square Type Id</param>
        /// <param name="requirement"></param>
        /// <param name="modelState"></param>
        public void SaveRequirement(int id, int squareTypeId, Requirement requirement, int? requirementId = null)
        {
            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();

                // adding a new one
                if (!requirementId.HasValue)
                {
                    requirement.Project = project;
                    requirement.SquareType = squareType;

                    db.Requirements.Add(requirement);
                }
                // updating an existing one
                else
                {
                    // load the existing one
                    var existingReq = db.Requirements.Where(a => a.Id == requirementId.Value).Single();

                    // update the values
                    existingReq.RequirementId = requirement.RequirementId;
                    existingReq.Name = requirement.Name;
                    existingReq.RequirementText = requirement.RequirementText;
                    existingReq.Source = requirement.Source;

                    existingReq.Project = project;
                    existingReq.SquareType = squareType;
                }

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {

                    throw;
                }

            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Set the requirements elicitation type
        /// </summary>
        /// <param name="id">Project Id</param>
        /// <param name="elicitationTypeId">Elicitation Type Id</param>
        /// <param name="rationale">Rationale for selecting elicitation type</param>
        /// <param name="userId">User login id</param>
        public void SetElicitationType(int id, int elicitationTypeId, string rationale, string userId)
        {
            if (!HasAccess(id, userId)) throw new SecurityException("Not authorzied for project.");

            using (var db = new SquareContext())
            {

                // load the objects
                var project = db.Projects.Where(a => a.Id == id).Single();
                var elicitationType = db.ElicitationTypes.Include("SquareType").Where(a => a.Id == elicitationTypeId).Single();

                // set the elicitation type
                if (elicitationType.SquareType.Name == SquareTypes.Security)
                {
                    project.SecurityElicitationType = elicitationType;
                    project.SecurityElicitationRationale = rationale;
                }
                else
                {
                    project.PrivacyElicitationType = elicitationType;
                    project.PrivacyElicitationRationale = rationale;
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 14
0
        public void DeleteCategory(int id, int categoryId, string loginId)
        {
            var project = GetProject(id, loginId);

            using (var db = new SquareContext())
            {

                var category = db.Categories.Where(a => a.Id == categoryId).Single();

                db.Categories.Remove(category);
                db.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public void DeleteGoal(int id)
        {
            using (var db = new SquareContext())
            {
                var goal = db.Goals.Where(a => a.Id == id).SingleOrDefault();

                if (goal != null)
                {
                    db.Goals.Remove(goal);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Delete artifact
        /// </summary>
        /// <param name="id"></param>
        public void DeleteArtifact(int id)
        {
            using (var db = new SquareContext())
            {
                var artifact = db.Artifacts.Where(a => a.Id == id).SingleOrDefault();

                if (artifact != null)
                {
                    db.Artifacts.Remove(artifact);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 17
0
 public override bool DeleteAccount(string userName)
 {
     if (string.IsNullOrEmpty(userName))
             {
                 throw CreateArgumentNullOrEmptyException("userName");
             }
             using (SquareContext context = new SquareContext())
             {
                 dynamic user = context.Users.FirstOrDefault(Usr => Usr.Username == userName);
                 if (user == null)
                 {
                     return false;
                 }
                 context.Users.Remove(user);
                 context.SaveChanges();
                 return true;
             }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Create a risk
        /// </summary>
        /// <param name="id">Project Id</param>
        /// <param name="userId"></param>
        /// <param name="name"></param>
        /// <param name="source"></param>
        /// <param name="vulnerability"></param>
        /// <param name="riskLevelId"></param>
        public void CreateRisk(int id, int squareTypeId, string userId, string name, string source, string vulnerability, string riskLevelId)
        {
            using(var db = new SquareContext())
            {
                var project = db.Projects.Include("SecurityAssessmentType").Include("PrivacyAssessmentType").Where(a => a.Id == id).Single();
                var riskLevel = db.RiskLevels.Where(a => a.Id == riskLevelId).Single();
                var squareType = db.SquareTypes.Where(a => a.Id == squareTypeId).Single();

                var risk = new Risk() { Name = name, Source = source, Vulnerability = vulnerability, Project = project, RiskLevel = riskLevel, SquareType = squareType};

                if (squareType.Name == SquareTypes.Security) risk.AssessmentType = project.SecurityAssessmentType;
                else if (squareType.Name == SquareTypes.Privacy) risk.AssessmentType = project.PrivacyAssessmentType;

                db.Risks.Add(risk);
                db.SaveChanges();
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Create the project
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="login"></param>
        /// <returns></returns>
        public Project CreateProject(string name, string description, string login)
        {
            using (var db = new SquareContext())
            {
                // load objects
                var user = db.Users.Where(a => a.Username == login).Single();
                var role = db.ProjectRoles.Where(a => a.Id == ProjectRoles.ProjectManager).Single();
                var steps = db.Steps;
                var squareTypes = db.SquareTypes;

                var project = new Project() { Name = name, Description = description };

                // create the worker for current user
                var worker = new ProjectWorker() { Project = project, Role = role, User = user };
                project.ProjectWorkers.Add(worker);

                // fill in all the project steps
                foreach (var squareTypeId in squareTypes.Select(a => a.Id).ToList())
                {
                    foreach (var step in steps.Where(a => a.SquareType.Id == squareTypeId))
                    {
                        var pstep = new ProjectStep() { Project = project, Step = step };
                        project.ProjectSteps.Add(pstep);
                    }
                }

                // save the project
                db.Projects.Add(project);
                db.SaveChanges();

                return project;
            }
        }
Exemplo n.º 20
0
        public void CategorizeRequirement(int id, int categoryId, int requirementId, bool essential, string loginId)
        {
            var project = GetProject(id, loginId);

            using (var db = new SquareContext())
            {
                // load objects
                var category = db.Categories.Where(a => a.Id == categoryId).Single();
                var requirement = db.Requirements.Include("Project").Include("SquareType").Where(a => a.Id == requirementId).Single();

                requirement.Category = category;
                requirement.Essential = essential;

                db.SaveChanges();
            }
        }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Delete the requirement
        /// </summary>
        /// <param name="id">Project Id</param>
        /// <param name="requirementId">Requirement Id</param>
        /// <param name="login">Login Id</param>
        public void DeleteRequirement(int id, int requirementId, string login)
        {
            var project = GetProject(id, login);

            using (var db = new SquareContext())
            {

                // load the requirement
                var requirement = db.Requirements.Where(a => a.Id == requirementId && a.Project.Id == project.Id).Single();

                // delete the requirement
                db.Requirements.Remove(requirement);

                // save
                db.SaveChanges();
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Save a goal
        /// </summary>
        /// <param name="id">Project Step Id</param>
        /// <param name="goal">Goal (Description and GoalType should be populated)</param>
        /// <param name="goalId">Goal Id for exisitng</param>
        /// <returns></returns>
        public Goal SaveGoal(int id, Goal goal, int? goalId = null, string goalTypeId = null)
        {
            using (var db = new SquareContext())
            {
                // load the project step
                var projectStep = db.ProjectSteps
                                    .Include("Step").Include("Step.SquareType")
                                    .Include("Project")
                                    .Where(a => a.Id == id).Single();

                // list of goal types for this square type
                var goalTypes = db.GoalTypes.Where(a => a.SquareType.Id == projectStep.Step.SquareType.Id).Select(a => a.Id).ToList();

                var goalType = goal.GoalType ?? db.GoalTypes.Where(a => a.Id == goalTypeId).Single();

                // wrong goal type for the project step
                if (!goalTypes.Contains(goalType.Id) && (goalType.Id != GoalTypes.Business)) return null;

                // updating an existing goal
                if (goalId.HasValue)
                {
                    var goalToSave = db.Goals.Include("SquareType").Include("Project").Include("GoalType")
                                   .Where(a => a.Id == goalId.Value).Single();

                    goalToSave.Name = goal.Name;
                    goalToSave.Description = goal.Description;
                    goalToSave.GoalType = goalType;
                    goal = goalToSave;
                }
                else
                {
                    goal.Name = goal.Name;
                    goal.Description = goal.Description;
                    goal.SquareType = projectStep.Step.SquareType;
                    goal.Project = projectStep.Project;
                    goal.GoalType = goalType;

                    db.Goals.Add(goal);
                }

                db.SaveChanges();

                return goal;
            }
        }
Exemplo n.º 24
0
        public void UpdateRequirementOrder(int id, int squareTypeId, int[] requirementIds, string loginId)
        {
            var project = GetProject(id, loginId);

            using (var db = new SquareContext())
            {

                for (int i = 0; i < requirementIds.Length; i++ )
                {
                    var reqId = requirementIds.ElementAt(i);
                    // load the requirement
                    var req = db.Requirements.Include("Project").Include("SquareType").Where(a => a.Id == reqId).Single();

                    // validate that we have a valid project and square type for this requirment
                    if (req.Project.Id != id && req.SquareType.Id != req.SquareType.Id)
                    {
                        throw new Exception("Invalid requirement for project and square type.");
                    }

                    // update the order field
                    req.Order = i;

                }

                db.SaveChanges();
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Set the assessment type on the project
        /// </summary>
        /// <param name="id">Project Id</param>
        /// <param name="assessmentType">Assessment Type</param>
        /// <param name="userId">User Login</param>
        public void SetAssessmentType(int id, int assessmentTypeId, string userId)
        {
            using (var db = new SquareContext())
            {

                var project = db.Projects.Where(a => a.Id == id).Single();
                var assessmentType = db.AssessmentTypes.Include("SquareType").Where(a => a.Id == assessmentTypeId).Single();

                if (assessmentType.SquareType.Name == SquareTypes.Security)
                {
                    project.SecurityAssessmentType = assessmentType;
                }
                else if (assessmentType.SquareType.Name == SquareTypes.Privacy)
                {
                    project.PrivacyAssessmentType = assessmentType;
                }
                else
                {
                    // incorrect assessment type
                    throw new Exception("Something funny with the assessment type.");
                }

                db.SaveChanges();

            }
        }
Exemplo n.º 26
0
        public ProjectStep UpdateStatus(int id, ProjectStepStatus projectStepStatus, string login)
        {
            using (var db = new SquareContext())
            {
                var step = db.ProjectSteps.Include("Project").Include("Step").Where(a => a.Id == id).Single();

                // validate that the step can be changed
                switch (projectStepStatus)
                {
                    case ProjectStepStatus.Pending:
                        step.DateStarted = null;
                        step.Complete = false;
                        break;
                    case ProjectStepStatus.Working:
                        step.DateStarted = DateTime.Now;
                        step.Complete = false;
                        break;
                    case ProjectStepStatus.Complete:
                        step.DateStarted = step.DateStarted.HasValue ? step.DateStarted : DateTime.Now;
                        step.DateCompleted = DateTime.Now;
                        step.Complete = true;
                        break;
                }

                db.SaveChanges();

                return step;
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Updates a project's temr
        /// </summary>
        /// <param name="id">project term Id</param>
        /// <param name="projectId">Project Id</param>
        /// <param name="term"></param>
        /// <param name="definition"></param>
        /// <param name="source"></param>
        /// <param name="definitionId"></param>
        /// <returns></returns>
        public ProjectTerm UpdateProjectTerm(int id, int projectId, ModelStateDictionary modelState, string term = null, string definition = null, string source = null, int? definitionId = null)
        {
            using (var db = new SquareContext())
            {
                var projectTerm = db.ProjectTerms.Include("Project").Include("SquareType").Where(a => a.Id == id).Single();

                if (definitionId.HasValue)
                {
                    // load the definition
                    var def = db.Definitions.Include("Term").Where(a => a.Id == definitionId.Value).Single();

                    if (def.Term.Name != projectTerm.Term)
                    {
                        modelState.AddModelError("", "Definition/Term mismatch.");
                    }
                    else
                    {
                        // update the values
                        projectTerm.Definition = def.Description;
                        projectTerm.Source = def.Source;
                    }

                }
                else
                {
                    if (string.IsNullOrWhiteSpace(term) || string.IsNullOrWhiteSpace(definition) || string.IsNullOrWhiteSpace(source))
                    {
                        modelState.AddModelError("", "Term/Definition/Source is empty.");
                    }
                    else
                    {
                        projectTerm.Term = term;
                        projectTerm.Definition = definition;
                        projectTerm.Source = source;
                    }
                }

                if (modelState.IsValid)
                {
                    db.SaveChanges();
                }
            }

            return null;
        }
Exemplo n.º 28
0
 public override bool ChangePassword(string userName, string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(userName))
             {
                 throw CreateArgumentNullOrEmptyException("userName");
             }
             if (string.IsNullOrEmpty(oldPassword))
             {
                 throw CreateArgumentNullOrEmptyException("oldPassword");
             }
             if (string.IsNullOrEmpty(newPassword))
             {
                 throw CreateArgumentNullOrEmptyException("newPassword");
             }
             using (SquareContext context = new SquareContext())
             {
                 dynamic user = context.Users.FirstOrDefault(Usr => Usr.Username == userName);
                 if (user == null)
                 {
                     return false;
                 }
                 dynamic hashedPassword = user.Password;
                 bool verificationSucceeded = (hashedPassword != null && CodeFirstCrypto.VerifyHashedPassword(hashedPassword, oldPassword));
                 if (verificationSucceeded)
                 {
                     user.PasswordFailuresSinceLastSuccess = 0;
                 }
                 else
                 {
                     int failures = user.PasswordFailuresSinceLastSuccess;
                     if (failures != -1)
                     {
                         user.PasswordFailuresSinceLastSuccess += 1;
                         user.LastPasswordFailureDate = DateTime.UtcNow;
                     }
                     context.SaveChanges();
                     return false;
                 }
                 dynamic newhashedPassword = CodeFirstCrypto.HashPassword(newPassword);
                 if (newhashedPassword.Length > 128)
                 {
                     throw new ArgumentException("Password too long");
                 }
                 user.Password = newhashedPassword;
                 user.PasswordChangedDate = DateTime.UtcNow;
                 context.SaveChanges();
                 return true;
             }
 }
Exemplo n.º 29
0
        public void UpdateRequirementPriority(int id, int? priority, string loginId)
        {
            using (var db = new SquareContext())
            {
                var requirement = db.Requirements.Include("Project").Include("SquareType").Where(a => a.Id == id).Single();

                requirement.Priority = priority;

                db.SaveChanges();
            }
        }
Exemplo n.º 30
0
        public void RemoveRisk(int id)
        {
            using (var db = new SquareContext())
            {
                var risk = db.Risks.Where(a => a.Id == id).SingleOrDefault();

                if (risk != null)
                {
                    db.Risks.Remove(risk);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 31
0
        public void ResolveDefect(int projectId, int defectId, string loginId)
        {
            var project = GetProject(projectId, loginId);

            using (var db = new SquareContext())
            {
                var defect = db.RequirementDefects.Include("Requirement").Where(a => a.Id == defectId).Single();

                defect.Solved = true;

                db.SaveChanges();
            }
        }
Exemplo n.º 32
0
 public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
 {
     if (string.IsNullOrEmpty(userName))
             {
                 throw CreateArgumentNullOrEmptyException("userName");
             }
             using (SquareContext context = new SquareContext())
             {
                 dynamic user = context.Users.FirstOrDefault(Usr => Usr.Username == userName);
                 if (user == null)
                 {
                     throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                 }
                 if (!user.IsConfirmed)
                 {
                     throw new InvalidOperationException(string.Format("User not found: {0}", userName));
                 }
                 string token = null;
                 if (user.PasswordVerificationTokenExpirationDate > DateTime.UtcNow)
                 {
                     token = user.PasswordVerificationToken;
                 }
                 else
                 {
                     token = CodeFirstCrypto.GenerateToken();
                 }
                 user.PasswordVerificationToken = token;
                 user.PasswordVerificationTokenExpirationDate = DateTime.UtcNow.AddMinutes(tokenExpirationInMinutesFromNow);
                 context.SaveChanges();
                 return token;
             }
 }