Ejemplo n.º 1
0
        public void DeleteProjectTest()
        {
            var appDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C:\\Users\\Claudiu Sirbu\\source\\repos\\SE\\Student\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataDir);
            ManagementController managementController = new ManagementController();

            managementController.AddProject("project", false);
            Student.Models.ApplicationDbContext dbContext = Models.ApplicationDbContext.Create();
            List <Student.Models.Project>       projects  = dbContext.Projects.Where(m => m.Name == "project").ToList();
            var ID = projects[0].ID;

            dbContext.Projects.Remove(projects[0]);
            dbContext.SaveChanges();
            List <Student.Models.Project> list = dbContext.Projects.Where(m => m.ID == ID).ToList();
            var count = list.Count;

            Assert.Equal(count, 0);
            if (list.Count != 0)
            {
                dbContext.Projects.Remove(list[0]);
                dbContext.SaveChanges();
            }
            dbContext.Dispose();
        }
Ejemplo n.º 2
0
        public void DeleteUser()
        {
            var appDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C:\\Users\\Claudiu Sirbu\\source\\repos\\SE\\Student\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataDir);
            ManagementController managementController = new ManagementController();

            managementController.AddUser("stoe", "password", "stoenica", "robert", 1960718162021, "*****@*****.**", "admin");
            Student.Models.ApplicationDbContext dbContext = Models.ApplicationDbContext.Create();
            List <Student.Models.User>          users     = dbContext.Users.Where(m => m.Username == "stoe").ToList();
            var ID = users[0].ID;

            dbContext.Users.Remove(users[0]);
            dbContext.SaveChanges();
            List <Student.Models.User> list = dbContext.Users.Where(m => m.ID == ID).ToList();
            var count = list.Count;

            Assert.Equal(count, 0);
            if (list.Count != 0)
            {
                var uid  = list[0].ID;
                var role = dbContext.Roles.Where(r => r.UserID == uid).ToList()[0];
                dbContext.Roles.Remove(role);
                dbContext.Users.Remove(list[0]);
                dbContext.SaveChanges();
            }
            dbContext.Dispose();
        }
Ejemplo n.º 3
0
        public void SetProjectTest()
        {
            var appDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C:\\Users\\Claudiu Sirbu\\source\\repos\\SE\\Student\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataDir);
            ManagementController managementController = new ManagementController();

            managementController.AddUser("stoe", "password", "stoenica", "robert", 1960718162021, "*****@*****.**", "admin");
            managementController.AddProject("project", false);
            managementController.SetProject("stoe", "project");
            Student.Models.ApplicationDbContext dbContext = Models.ApplicationDbContext.Create();
            dbContext.SaveChanges();
            List <Student.Models.User> user = dbContext.Users.Where(m => m.Username == "stoe").ToList();

            List <Student.Models.Project> project = dbContext.Projects.Where(m => m.Name == "project").ToList();

            var projectID = project[0].ID;
            var userID    = user[0].ID;
            List <Student.Models.Users_Projects> projects = dbContext.UsersProjects.Where(m => m.ProjectID == projectID && m.UserID == userID).ToList();
            var firstProjectID = projects[0].ProjectID;
            var firstUserID    = projects[0].UserID;

            Assert.Equal(firstProjectID, projectID);
            Assert.Equal(firstUserID, userID);
            dbContext.UsersProjects.Remove(projects[0]);
            dbContext.Projects.Remove(project[0]);
            var uid  = user[0].ID;
            var role = dbContext.Roles.Where(r => r.UserID == uid).ToList()[0];

            dbContext.Roles.Remove(role);
            dbContext.Users.Remove(user[0]);
            dbContext.SaveChanges();
            dbContext.Dispose();
        }
Ejemplo n.º 4
0
        public ActionResult AddProject(string projectName, bool?projectOptional)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            Student.Models.Project projectModel = new Student.Models.Project();

            if (dbContext.Projects.Where(m => m.Name == projectName).ToList().Count > 0)
            {
                TempData["Error"] = "Project already exists!";
                return(RedirectToAction("Index"));
            }

            projectModel.Name        = projectName;
            projectModel.Description = "";
            projectModel.Deadline    = DateTime.Now;
            if (projectOptional == true)
            {
                projectModel.Optional = true;
            }
            else
            {
                projectOptional = false;
            }

            dbContext.Projects.Add(projectModel);

            dbContext.SaveChanges();

            dbContext.Dispose();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public ActionResult DeleteUser(string username)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            List <Student.Models.User> user = dbContext.Users.Where(m => m.Username == username).ToList();


            if (user.Count() != 0)
            {
                int id = user[0].ID;
                List <Student.Models.UserRole> role = dbContext.Roles.Where(m => m.UserID == id).ToList();



                dbContext.Users.Remove(user[0]);
                dbContext.Roles.Remove(role[0]);

                dbContext.SaveChanges();

                dbContext.Dispose();
            }


            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public ActionResult SetProject(string username, string projectName)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            List <Student.Models.User> user = dbContext.Users.Where(m => m.Username == username).ToList();

            List <Student.Models.Project> project = dbContext.Projects.Where(m => m.Name == projectName).ToList();


            Student.Models.Users_Projects users_projects = new Student.Models.Users_Projects();

            if (user.Count() != 0 && project.Count() != 0)
            {
                users_projects.UserID    = user[0].ID;
                users_projects.ProjectID = project[0].ID;
                users_projects.Mark      = 0;


                dbContext.UsersProjects.Add(users_projects);

                dbContext.SaveChanges();
            }


            dbContext.Dispose();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public ActionResult GiveMark(int mark, int ID)
        {
            Student.Models.ApplicationDbContext db = Student.Models.ApplicationDbContext.Create();

            var uprj = db.UsersProjects.SingleOrDefault(up => up.UsersProjectsID == ID);

            uprj.Mark = mark;

            db.SaveChanges();
            db.Dispose();

            ViewBag.ID = ID;
            return(View("_ViewAssigment"));
        }
Ejemplo n.º 8
0
        public ActionResult AddUser(string username, string password, string firstName, string lastName, long cnp, string email, string role)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            Student.Models.User     userModel = new Student.Models.User();
            Student.Models.UserRole roleModel = new Student.Models.UserRole();

            if (dbContext.Users.Where(m => m.Username == username).ToList().Count > 0)
            {
                TempData["Error"] = "Username already exists!";
                return(RedirectToAction("Index"));
            }

            List <Student.Models.User> list = dbContext.Users.ToList();


            userModel.Username  = username;
            userModel.Password  = password;
            userModel.FirstName = firstName;
            userModel.LastName  = lastName;
            userModel.CNP       = cnp;
            userModel.Email     = email;

            roleModel.UserID = userModel.ID;

            if (role == "Student")
            {
                roleModel.Role = Student.Models.UserRole.roles.student;
            }
            else if (role == "Professor")
            {
                roleModel.Role = Student.Models.UserRole.roles.professor;
            }
            else
            {
                roleModel.Role = Student.Models.UserRole.roles.administrator;
            }


            dbContext.Users.Add(userModel);
            dbContext.Roles.Add(roleModel);

            dbContext.SaveChanges();

            dbContext.Dispose();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public ActionResult SaveInformation(string description, DateTime deadline, int ID)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            var project = dbContext.Projects.SingleOrDefault(m => m.ID == ID);

            project.Description = description;
            project.Deadline    = deadline;

            dbContext.SaveChanges();

            dbContext.Dispose();

            ViewBag.ID = ID;
            return(View("_ViewProject"));
        }
Ejemplo n.º 10
0
        public ActionResult SubmitComment(string comment, int userID, int ID)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            Student.Models.Users_Projects_Comments conversation = new Student.Models.Users_Projects_Comments();

            conversation.Comment         = comment;
            conversation.UserID          = userID;
            conversation.UsersProjectsID = ID;

            dbContext.UsersProjectsComments.Add(conversation);

            dbContext.SaveChanges();

            dbContext.Dispose();

            ViewBag.ID = ID;
            return(View("_ViewAssigment"));
        }
Ejemplo n.º 11
0
        public ActionResult DeleteProject(string projectName)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            List <Student.Models.Project> project = dbContext.Projects.Where(m => m.Name == projectName).ToList();


            if (project.Count() != 0)
            {
                dbContext.Projects.Remove(project[0]);

                dbContext.SaveChanges();

                dbContext.Dispose();
            }



            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
        public void LoginFailedTest()
        {
            var appDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C:\\Users\\Claudiu Sirbu\\source\\repos\\SE\\Student\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataDir);
            AccountController    accountController    = new AccountController();
            ManagementController managementController = new ManagementController();

            managementController.AddUser("stoe", "password", "stoenica", "robert", 1960718162021, "*****@*****.**", "admin");
            var result = accountController.Login("stoe2", "password") as ViewResult;

            Assert.True(result != null);
            Student.Models.ApplicationDbContext dbContext = Models.ApplicationDbContext.Create();
            List <Student.Models.User>          list      = dbContext.Users.Where(m => m.Username == "stoe").ToList();
            var uid  = list[0].ID;
            var role = dbContext.Roles.Where(r => r.UserID == uid).ToList()[0];

            dbContext.Roles.Remove(role);
            dbContext.Users.Remove(list[0]);
            dbContext.SaveChanges();
            dbContext.Dispose();
        }