Exemplo n.º 1
0
        /// <summary>
        /// Adds a project by current user username to the Db. Adds a default empty index file to the Db.
        /// Adds current user as owner of the new project to the Db.
        /// </summary>
        /// <param name="model">'CreateProjectViewModel'</param>
        /// <param name="ownerName">Owner Name</param>
        public void addProject(CreateProjectViewModel model, string ownerName)
        {
            Project newProject = new Project();

            newProject._projectName       = model._projectName;
            newProject._projectFileTypeId = model._projectTypeId;

            _db._projects.Add(newProject);
            _db.SaveChanges();

            string extension    = _db._fileTypes.Where(x => x.ID == model._projectTypeId).SingleOrDefault()._extension;
            string aceExtension = _db._fileTypes.Where(x => x.ID == model._projectTypeId).SingleOrDefault()._aceExtension;
            string defaultData  = _db._fileTypes.Where(x => x.ID == model._projectTypeId).SingleOrDefault()._initialCode;

            ProjectFile defaultFile = new ProjectFile();

            defaultFile._projectFileName = "index" + "." + extension;
            defaultFile._projectFileType = "." + extension;
            defaultFile._aceExtension    = aceExtension;
            defaultFile._projectFileData = defaultData;
            defaultFile._projectID       = _db._projects.OrderByDescending(p => p.ID)
                                           .Select(p => p.ID).FirstOrDefault();

            _db._projectFiles.Add(defaultFile);
            _db.SaveChanges();

            ProjectOwner owner = new ProjectOwner();

            owner._projectID = defaultFile._projectID;
            owner._userName  = ownerName;

            _db._projectOwners.Add(owner);
            _db.SaveChanges();
        }
        /// <summary>
        /// A function that deletes a specific milestone, also deletes it's
        /// solutions and submissions
        /// </summary>
        public void deleteMilestone(Milestone milestone)
        {
            if (milestone != null)
            {
                List <Solution>   solutions   = (from s in db.Solutions where s.MilestoneID == milestone.ID select s).ToList();
                List <Submission> submissions = (from s in db.Submission where s.MilestoneID == milestone.ID select s).ToList();
                if (solutions.Count != 0)
                {
                    IEnumerable <Solution> solutionsToDelete = solutions;
                    foreach (var item in solutionsToDelete)
                    {
                        db.Solutions.Remove(item);
                    }
                    db.SaveChanges();
                }

                if (submissions.Count != 0)
                {
                    IEnumerable <Submission> submissionsToDelete = submissions;
                    foreach (var item in submissionsToDelete)
                    {
                        db.Submission.Remove(item);
                    }
                    db.SaveChanges();
                }
                Milestone milestoneToDelete = db.Milestones.Where(x => x.ID == milestone.ID).SingleOrDefault();
                db.Milestones.Remove(milestoneToDelete);
                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        //Creates a project with User withc specific username as owner. Returns false if fails, otherwise true
        public bool CreateProject(CreateProjectViewModel NewCreateProject, string Username)
        {
            if (NewCreateProject == null || Username == "")
            {
                return(false);
            }
            var ProjectWithSameName = DB.Projects.Where(x => x.Owner.Username == Username &&
                                                        x.Name == NewCreateProject.Name).FirstOrDefault();

            if (ProjectWithSameName != null) //If user has created a project with same name nothing is created and function returns false
            {
                return(false);
            }

            UserInfo Owner      = DB.UsersInfo.Where(x => x.Username == Username).SingleOrDefault(); //User that is creating project
            Project  NewProject = new Project();                                                     //The project that is being made, gets values from viewmodel

            NewProject.Name         = NewCreateProject.Name;
            NewProject.Type         = NewCreateProject.Type;
            NewProject.Owner        = Owner;
            NewProject.ReadMe       = FService.CreateReadMe(NewCreateProject.ReadMe); //New ReadMe created
            NewProject.DateCreated  = DateTime.Now;
            NewProject.DateModified = DateTime.Now;

            //If project is a web application more default files are made
            if (NewProject.Type == "Web Application")
            {
                var           Files        = FService.CreateWebApplication(); //Gets a list of extra files
                FileInProject FIProjectCSS = new FileInProject();             //connection between file and project is made
                FIProjectCSS.FileProject = NewProject;
                FIProjectCSS.ProjectFile = Files[0];                          //css file

                FileInProject FIProjectJS = new FileInProject();              //connection between file and project is made
                FIProjectJS.FileProject = NewProject;
                FIProjectJS.ProjectFile = Files[1];                           //js file

                DB.FilesInProjects.Add(FIProjectCSS);                         //added to database
                DB.FilesInProjects.Add(FIProjectJS);
            }

            DB.Projects.Add(NewProject); //Project added to database
            DB.SaveChanges();

            //Connection between user creating and project is made
            ProjectOwner POwner = new ProjectOwner();

            POwner.Owner        = Owner;
            POwner.OwnerProject = NewProject;
            //Connection between default file and project is made
            FileInProject FIProject = new FileInProject();

            FIProject.FileProject = NewProject;
            FIProject.ProjectFile = FService.CreateDefaultFile(NewProject.Type); //default file is made

            DB.ProjectOwners.Add(POwner);                                        //connections added to database
            DB.FilesInProjects.Add(FIProject);
            DB.SaveChanges();                                                    //changes saved and function returns true
            return(true);
        }
Exemplo n.º 4
0
        public void UpdateRatePost(Post p)
        {
            var result = (from posts in _db.Posts
                          where posts.Id == p.Id
                          select posts).SingleOrDefault();

            result.Rating = p.Rating;

            _db.SaveChanges();
        }
Exemplo n.º 5
0
        //Add Course to db.Courses
        public bool add(CreateCourseViewModel newCourse)
        {
            Course temp = new Course()
            {
                name = newCourse.name, description = newCourse.description
            };

            db.Courses.Add(temp);
            return(Convert.ToBoolean(db.SaveChanges()));
        }
Exemplo n.º 6
0
        public void UpdateUser(ApplicationUser a, Photo p)
        {
            var query = (from u in _db.Users
                         where u.Id == a.Id
                         select u).SingleOrDefault();

            query.Photo = p;

            _db.SaveChanges();
        }
Exemplo n.º 7
0
        //Create link between User and Course
        public bool createLink(string userID, int courseID, int roleID)
        {
            UsersInCourse uInC = new UsersInCourse()
            {
                userID = userID, courseID = courseID, roleID = roleID
            };

            db.UsersInCourse.Add(uInC);

            return(Convert.ToBoolean(db.SaveChanges()));
        }
Exemplo n.º 8
0
        /// <summary>
        /// A function that connects a student to a course in the database
        /// </summary>
        public void ConnectStudents(string userID, int courseID)
        {
            Course_Student newStudent = new Course_Student
            {
                UserID   = userID,
                CourseID = courseID
            };

            db.CoursesStudents.Add(newStudent);
            db.SaveChanges();
            return;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Add project file to the Db.
        /// </summary>
        /// <param name="model">'CreateProjectFileViewModel'</param>
        public void addProjectFile(CreateProjectFileViewModel model)
        {
            ProjectFile newProjectFile = new ProjectFile();

            newProjectFile._projectFileName = model._projectFileName + "." + model._projectFileType;
            newProjectFile._projectFileData = model._projectFileData;
            newProjectFile._projectFileType = "." + model._projectFileType;
            newProjectFile._aceExtension    = getAceExtensionByProjectId(model._projectID);
            newProjectFile._projectID       = model._projectID;

            _db._projectFiles.Add(newProjectFile);
            _db.SaveChanges();
        }
Exemplo n.º 10
0
        //Adds a folder to a project
        public void AddFolder(AddFolderViewModel Model)
        {
            Folder NewFolder = new Folder();                        //A new folder is created

            NewFolder.Name             = Model.Name;                //It gets Model's name and is added to Project with Model's ProjectID
            NewFolder.ProjectStructure = DB.Projects.Where(x => x.ID == Model.ProjectID).FirstOrDefault();
            NewFolder.FolderStructure  = null;                      //It goes to root of project by default
            NewFolder.DateCreated      = DateTime.Now;              //DateTime attributes are setted
            NewFolder.DateModified     = DateTime.Now;
            NewFolder.ProjectStructure.DateModified = DateTime.Now; //Date modified resetted on project
            DB.Folders.Add(NewFolder);                              //Added to database and saved
            DB.SaveChanges();
        }
Exemplo n.º 11
0
        public void UpdatePhotoPath(string photopath, ApplicationUser user)
        {
            var query = (from c in _db.Comments
                         where c.AuthorId == user.Id
                         select c);

            foreach (var item in query)
            {
                item.AuthorPhotoFileName = photopath;
            }

            _db.SaveChanges();
        }
Exemplo n.º 12
0
        public void UpdateEventList(EventList el, ApplicationUser user)
        {
            EventList t = getEventList(el.Id, user);

            if (t != null)
            {
                t.Id       = el.Id;
                t.Event    = el.Event;
                t.JoinTime = el.JoinTime;
                t.User     = el.User;
                _db.SaveChanges();
            }
        }
Exemplo n.º 13
0
 public void CreateGroup(string userId, Group groupName)
 {
     try
     {
         groupName.ownerId     = userId;
         groupName.timeCreated = System.DateTime.Now;
         db.groups.Add(groupName);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write(ex.Message + Environment.NewLine + "Location of error: " + ex.Source +
                                        Environment.NewLine + "StackTrace: " + Environment.NewLine + ex.StackTrace +
                                        Environment.NewLine + "Time : " + DateTime.Now + Environment.NewLine);
     }
 }
Exemplo n.º 14
0
        public void createHandinAttempt(int assignmentId, string solution)
        {
            var currentUser = HttpContext.Current.User.Identity.GetUserId();

            var assignmentSolution = (from assign in db.Assignments
                                      where assign.ID == assignmentId
                                      select assign.solution).FirstOrDefault();

            var acceptedOrNot = "";

            if (assignmentSolution == solution)
            {
                acceptedOrNot = "Accepted";
            }
            else
            {
                acceptedOrNot = "Not Accepted";
            }

            Solution sol = new Solution()
            {
                userID = currentUser, assignmentID = assignmentId, accepted = acceptedOrNot, handinDate = DateTime.Now, file = solution
            };

            db.Solutions.Add(sol);
            db.SaveChanges();

            getSolution(assignmentId);

            return;
        }
Exemplo n.º 15
0
 /// <summary>
 /// Take data from 'ConctactLogViewModel' and save to Db table 'contactLog', if model is not valid return false.
 /// </summary>
 /// <param name="model">'ContactLogViewModel'</param>
 /// <returns>bool</returns>
 public bool addContactLog(ConctactLogViewModel model)
 {
     if (model._contactName != null || model._contactEmail != null || model._contactEmail != null) // FIXME::?
     {
         ContactLog contactLog = new ContactLog
         {
             _contactName    = model._contactName,
             _contactEmail   = model._contactEmail,
             _ContactMessage = model._contactMessage
         };
         _db._contacts.Add(contactLog);
         _db.SaveChanges();
         return(true);
     }
     return(false);
 }
Exemplo n.º 16
0
        public void EditUser(UserInfo User) //Saves the changes of specific User in database
        {
            UserInfo ToEdit = db.UsersInfo.Find(User.ID);

            ToEdit.Name    = User.Name;
            ToEdit.Email   = User.Email;
            ToEdit.Country = User.Country;
            db.SaveChanges();
        }
Exemplo n.º 17
0
 public void StalkUser(string userId, string stalkId)
 {
     try
     {
         if (!String.IsNullOrEmpty(userId) && !String.IsNullOrEmpty(stalkId))
         {
             var stalking = new Stalking();
             stalking.userId    = userId;
             stalking.stalkedId = stalkId;
             db.stalking.Add(stalking);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write(ex.Message + Environment.NewLine + "Location of error: " + ex.Source +
                                        Environment.NewLine + "StackTrace: " + Environment.NewLine + ex.StackTrace +
                                        Environment.NewLine + "Time : " + DateTime.Now + Environment.NewLine);
     }
 }
Exemplo n.º 18
0
        // Add assignment to db.assignments
        public bool createAssignment(CreateAssignmentViewModel newAssignment)
        {
            Assignment temp = new Assignment()
            {
                name        = newAssignment.name, solution = newAssignment.solution,
                description = newAssignment.description, startDate = newAssignment.startDate,
                endDate     = newAssignment.endDate
            };

            db.Assignments.Add(temp);
            db.SaveChanges();

            AssignmentsInCourse link = new AssignmentsInCourse()
            {
                assignmentID = temp.ID, courseID = newAssignment.courseID
            };

            db.AssingmentInCourse.Add(link);

            return(Convert.ToBoolean(db.SaveChanges()));
        }
Exemplo n.º 19
0
        public bool AddFile(AddFilesViewModel Model)
        {
            var FileWithSameName = DB.FilesInProjects.Where(x => x.ProjectFile.Name == Model.Name &&
                                                            x.FileProject.ID == Model.ProjectID &&
                                                            x.ProjectFile.Type == Model.Type).FirstOrDefault();

            if (FileWithSameName != null)
            {
                return(false);
            }
            // Make the file.
            File NewFile = new File();

            NewFile.Name            = Model.Name;
            NewFile.Type            = Model.Type;
            NewFile.Location        = "//This is a new file";
            NewFile.FolderStructure = null;
            NewFile.DateCreated     = DateTime.Now;
            NewFile.DateModified    = DateTime.Now;

            // Add the connection.
            FileInProject NewConnection = new FileInProject();

            NewConnection.ProjectFile = NewFile;
            Project TheProj = DB.Projects.Where(x => x.ID == Model.ProjectID).FirstOrDefault();

            NewConnection.FileProject = TheProj;

            // Adding to the database.
            DB.Files.Add(NewFile);
            DB.FilesInProjects.Add(NewConnection);
            // If no changes are made to the database we return false.
            if (DB.SaveChanges() == 0)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 20
0
 public void PostStatus(string userId, Status userStatus)
 {
     try
     {
         userStatus.userId      = userId;
         userStatus.timeCreated = System.DateTime.Now;
         userStatus.fullName    = (from p in db.profiles
                                   where p.userID == userId
                                   select p.name).SingleOrDefault();
         if (!String.IsNullOrEmpty(userStatus.urlToPic))
         {
             userStatus.urlToPic = userStatus.urlToPic;
         }
         db.userStatuses.Add(userStatus);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write(ex.Message + Environment.NewLine + "Location of error: " + ex.Source +
                                        Environment.NewLine + "StackTrace: " + Environment.NewLine + ex.StackTrace +
                                        Environment.NewLine + "Time : " + DateTime.Now + Environment.NewLine);
     }
 }
Exemplo n.º 21
0
        public void ChangeProfilePicUrl(string userId, string url)
        {
            try
            {
                if (!String.IsNullOrEmpty(url))
                {
                    var profile = (from p in db.profiles
                                   where p.userID == userId
                                   select p).SingleOrDefault();

                    profile.profilePicUrl = url;


                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.Message + Environment.NewLine + "Location of error: " + ex.Source +
                                               Environment.NewLine + "StackTrace: " + Environment.NewLine + ex.StackTrace +
                                               Environment.NewLine + "Time : " + DateTime.Now + Environment.NewLine);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Adds a submission to the database from a student.
        /// </summary>
        public void AddSubmission(SubmissionViewModel sub)
        {
            if (sub == null)
            {
                return;
            }

            Submission NewSub = new Submission();

            NewSub.AssignmentID = sub.AssignmentID;
            NewSub.CourseID     = sub.CourseID;
            NewSub.Error        = sub.Error;
            NewSub.FilePath     = sub.FilePath;
            NewSub.Grade        = sub.Grade;
            NewSub.MilestoneID  = sub.MilestoneID;
            NewSub.Output       = sub.Output;
            NewSub.Status       = sub.Status;
            NewSub.UserName     = sub.UserName;
            NewSub.DrMemory     = sub.DrMemory;
            NewSub.Comment      = sub.Comment;

            _db.Submission.Add(NewSub);
            _db.SaveChanges();
        }
Exemplo n.º 23
0
        // Creates a project with the attributes from the CreateProjectViewModel that gets sent in
        public void CreateProject(CreateProjectViewModel projectVM)
        {
            Project project = new Project
            {
                Name    = projectVM.Name,
                Type    = projectVM.Type,
                OwnerID = projectVM.OwnerID,
            };

            _db.Projects.Add(project);
            _db.SaveChanges();

            CreateFileViewModel file = new CreateFileViewModel
            {
                Name      = "index",
                Type      = project.Type,
                ProjectID = project.ID
            };

            CreateFile(file);
        }
Exemplo n.º 24
0
 public void AddGroup(Group g)
 {
     _db.Groups.Add(g);
     _db.SaveChanges();
 }
Exemplo n.º 25
0
 public void SendFriendRequest(FriendRequest friendRequest)
 {
     _dbContext.FriendRequests.Add(friendRequest);
     _dbContext.SaveChanges();
 }
Exemplo n.º 26
0
        //Add & remove

        public void AddPhoto(Photo s)
        {
            _db.Photos.Add(s);
            _db.SaveChanges();
        }
Exemplo n.º 27
0
 public void AddGroupToList(GroupList gl)
 {
     _db.GroupList.Add(gl);
     _db.SaveChanges();
 }
Exemplo n.º 28
0
 /// <summary>
 /// Adds a Group to the database
 /// </summary>
 /// <param name="group"></param>
 public void CreateGroup(Group group)
 {
     _dbContext.Groups.Add(group);
     _dbContext.SaveChanges();
 }
Exemplo n.º 29
0
 public void AddPost(Post post)
 {
     _dbContext.Posts.Add(post);
     _dbContext.SaveChanges();
 }
Exemplo n.º 30
0
 public void AddEvent(Event e)
 {
     _db.Events.Add(e);
     _db.SaveChanges();
 }