public string Login(string email, string password) { // Validations if (string.IsNullOrEmpty(email)) { throw new ParameterException("email"); } if (string.IsNullOrEmpty(password)) { throw new ParameterException("password"); } string bagToken = null; using (DocuFlowContext context = new DocuFlowContext()) { Contributor contributor = context.Contributors .Where(item => item.Email == email) .Include(item => item.Department.Company) .FirstOrDefault(); if (contributor == null) { throw new ContributorNotFoundException(); } else { // We found a contributor by that email. Let's check the password (it is hashed) if (contributor.Password == PasswordManager.HashPassword(password)) { // Success: store him in session bagToken = _sessionManager.StoreFirst("CurrentContributor", contributor); } else { throw new ContributorPasswordDoNotMatxhException(); } } } return bagToken; }
public ContributorManager() { _sessionManager = new SessionManager(); _context = new DocuFlowContext(); }
public ContributorManager(ISessionManager sessionManager) { _sessionManager = sessionManager; _context = new DocuFlowContext(); }
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(); }
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; }
public DocumentManager(ISessionManager sessionManager) { _sessionManager = sessionManager; _context = new DocuFlowContext(); }
public DocumentManager() { _sessionManager = new SessionManager(); _context = new DocuFlowContext(); }
public ContributorManagerTest() { _context = new DocuFlowContext(); _sessionManager = new SessionManagerMock(); _contributorManager = new ContributorManager(_sessionManager); }
public void Initially_there_is_one_contributor() { using (DocuFlowContext context = new DocuFlowContext()) { Assert.AreEqual(1, context.Contributors.Count()); } }
public ProjectManager() { _sessionManager = new SessionManager(); _context = new DocuFlowContext(); }