public Contributor Add(Contributor contributor)
        {
            contributor.Password = PasswordManager.HashPassword(contributor.Password);
            contributor.Department = _context.Departments.Find(contributor.Department.Id);

            contributor = _context.Contributors.Add(contributor);
            _context.SaveChanges();

            return contributor;
        }
        public void An_existant_contributor_can_login()
        {
            var existanContributor = new Contributor()
            {
                Email = "*****@*****.**",
                Password = "******"
            };

            string bagToken = _contributorManager.Login(existanContributor.Email, existanContributor.Password);

            Assert.IsNotNull(bagToken);
        }
        public void An_nonexistant_contributor_cannot_login()
        {
            var nonexistanContributor = new Contributor()
            {
                Email = "*****@*****.**",
                Password = "******"
            };

            try
            {
                _contributorManager.Login(nonexistanContributor.Email, nonexistanContributor.Password);
            }
            catch (ContributorNotFoundException) { }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
        public Contributor Update(Contributor contributor)
        {
            try
            {
                Contributor contributorToUpdate = _context.Contributors.Include(item => item.Department)
                                                                       .Where(item => item.Id == contributor.Id)
                                                                       .FirstOrDefault();

                contributorToUpdate.Email = contributor.Email;

                if (!string.IsNullOrEmpty(contributor.Password))
                {
                    contributorToUpdate.Password = PasswordManager.HashPassword(contributor.Password);
                }
                contributorToUpdate.Department = _context.Departments.Find(contributor.Department.Id);

                _context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return contributor;
        }
        public string Signup(string email, string password, string passwordRepeat, string companyName)
        {
            // Validations
            if (string.IsNullOrEmpty(email)) { throw new ParameterException("email"); }
            if (string.IsNullOrEmpty(password)) { throw new ParameterException("password"); }
            if (string.IsNullOrEmpty(passwordRepeat)) { throw new ParameterException("passwordRepeat"); }
            if (string.IsNullOrEmpty(companyName)) { throw new ParameterException("companyName"); }
            if (password != passwordRepeat) { throw new PasswordsDoNotMatchException(); }

            string bagToken = null;

            using (DocuFlowContext context = new DocuFlowContext())
            {
                var contributor = new Contributor()
                {
                    Email = email,
                    Password = PasswordManager.HashPassword(password),  // Hash password before storing it
                    Department = new Department()
                    {
                        Name = "Default",
                        Company = new Company()
                                        {
                                            Name = companyName
                                        }
                    }
                };

                context.Contributors.Add(contributor);
                context.SaveChanges();

                // Store current contributor in session
                bagToken = _sessionManager.StoreFirst("CurrentContributor", contributor);
            }
            return bagToken;
        }
示例#6
0
        public static void Seed(DocuFlowContext context)
        {
            Contributor johnLegend = new Contributor()
            {
                Email = "*****@*****.**",
                Password = PasswordManager.HashPassword("123456")
            };

            Contributor paulVanDyk = new Contributor()
            {
                Email = "*****@*****.**",
                Password = PasswordManager.HashPassword("123456"),
            };

            Contributor arminVanBuuren = new Contributor()
            {
                Email = "*****@*****.**",
                Password = PasswordManager.HashPassword("123456"),
            };

            Company company = context.Companies.Add(new Company()
            {
                Name = "ACME",
                Departments = new List<Department>
                {
                    new Department()
                    {
                        Name = "Research and development",
                        Description = "Researchs and starts project whose aim s the innovation inside the company",
                        Contributors = new List<Contributor>{
                            johnLegend,
                            paulVanDyk
                        },
                        Projects = new List<Project>(){
                            new Project()
                            {
                                Title = "Electric car",
                                Description = "Research for the car of the future, similar to the one Tesla Motors has developed",
                                Documents = new List<Document>(){
                                    new Document(){
                                        Title = "Electric energy Analysis",
                                        Description = "How to get engine propulsion out of electricity",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Electricity",
                                                Description = "Explains the way electricity works",
                                                Content = GetLipsum(4)
                                            },
                                            new DocumentSection(){
                                                Title = "Combustion engines",
                                                Description = "Analyses currently used engines",
                                                Content = GetLipsum(5)
                                            },
                                            new DocumentSection(){
                                                Title = "Efficiency",
                                                Description = "Marks the minumun for considering an engine efficient",
                                                Content = GetLipsum(2)
                                            },
                                            new DocumentSection(){
                                                Title = "Conclussions",
                                                Description = "Concludes the comparation between combustion and electricity as sources",
                                                Content = GetLipsum(2)
                                            }
                                        }
                                    },
                                    new Document(){
                                        Title = "Energy sources",
                                        Description = "Analyses different sources for energy",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Petrolium",
                                                Description = "Describes petrolium as energy source",
                                                Content = GetLipsum(3)
                                            },
                                            new DocumentSection(){
                                                Title = "Littium batteries",
                                                Description = "Describes littium batteries as energy source",
                                                Content = GetLipsum(5)
                                            },
                                            new DocumentSection(){
                                                Title = "Solar energy",
                                                Description = "Describes solar energy as energy source",
                                                Content = GetLipsum(2)
                                            },
                                            new DocumentSection(){
                                                Title = "Wind energy",
                                                Description = "Describes wind energy as energy source",
                                                Content = GetLipsum(5)
                                            }
                                        }
                                    },
                                    new Document(){
                                        Title = "Project timeline",
                                        Description = "Schedules the project",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Analysis",
                                                Description = "Set of analysis done for the project",
                                                Content = GetLipsum(3)
                                            },
                                            new DocumentSection(){
                                                Title = "Execution",
                                                Description = "Execution of the plan",
                                                Content = GetLipsum(5)
                                            }
                                        }
                                    }
                                }
                            },
                            new Project()
                            {
                                Title = "Fly to mars",
                                Description = "Development of rockets for moving people and resources to Mars",
                                Documents = new List<Document>(){
                                    new Document(){
                                        Title = "Curriculum Vitae Analysis",
                                        Description = "Tools for analysing a curiculum vitae that reaches the company",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Explanations",
                                                Description = "Explains the process",
                                                Content = GetLipsum(4)
                                            }
                                        }
                                    },
                                    new Document(){
                                        Title = "Candidates Questionnarie",
                                        Description = "Questions for new candidates",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Knowledge questions",
                                                Description = "Set of questions to identify knowledge",
                                                Content = GetLipsum(3)
                                            },
                                            new DocumentSection(){
                                                Title = "Aptitude questions",
                                                Description = "Set of questions to identify aptitude",
                                                Content = GetLipsum(4)
                                            },
                                            new DocumentSection(){
                                                Title = "Ability questions",
                                                Description = "Set of questions to identify ability",
                                                Content = GetLipsum(2)
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new Department()
                    {
                        Name = "Human resources",
                        Description = "Looks for new talents to incorporate to the company",
                        Contributors = new List<Contributor>{
                            arminVanBuuren
                        },
                        Projects = new List<Project>(){
                            new Project()
                            {
                                Title = "Talent search",
                                Description = "Project for looking for the next brilliant minds of the world",
                                Documents = new List<Document>(){
                                    new Document(){
                                        Title = "Curriculum Vitae Analysis",
                                        Description = "Tools for analysing a curiculum vitae that reaches the company",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Explanations",
                                                Description = "Explains the process",
                                                Content = GetLipsum(4)
                                            }
                                        }
                                    },
                                    new Document(){
                                        Title = "Candidates Questionnarie",
                                        Description = "Questions for new candidates",
                                        CreatedBy = arminVanBuuren,
                                        DocumentSections = new List<DocumentSection>(){
                                            new DocumentSection(){
                                                Title = "Introduction",
                                                Description = "Introduces the document",
                                                Content = GetLipsum(1)
                                            },
                                            new DocumentSection(){
                                                Title = "Knowledge questions",
                                                Description = "Set of questions to identify knowledge",
                                                Content = GetLipsum(3)
                                            },
                                            new DocumentSection(){
                                                Title = "Aptitude questions",
                                                Description = "Set of questions to identify aptitude",
                                                Content = GetLipsum(4)
                                            },
                                            new DocumentSection(){
                                                Title = "Ability questions",
                                                Description = "Set of questions to identify ability",
                                                Content = GetLipsum(2)
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });

            context.SaveChanges();
        }