Example #1
0
        public override Project AddProject(string title, string userMail, int id = 0, bool db = false)
        {
            if (title == null || userMail == null) throw new ArgumentNullException();

            Project p = new Project() {
                Title = title
            };
            using (var dbContext = new sliceofpieEntities2()) { //Insert project
                dbContext.Projects.AddObject(p);
                dbContext.SaveChanges();
            }
            User u = new User() {
                Email = userMail
            };
            ProjectUser pu = new ProjectUser() {
                UserEmail = userMail,
                ProjectId = p.Id
            };
            using (var dbContext = new sliceofpieEntities2()) { //Insert projectUser
                if (dbContext.Users.Count(dbUser => dbUser.Email.Equals(u.Email)) < 1) throw new ArgumentException("No user with email " + u.Email + " exists!");
                dbContext.ProjectUsers.AddObject(pu);
                dbContext.SaveChanges();
            }
            return new Project() {
                Title = p.Title,
                Id = p.Id
            };
        }
Example #2
0
 public void ShareProject(int projectId, string userMail)
 {
     if (projectId == 0) {
         throw new ArgumentException("Project has to be synced, before it can be shared");
     }
     if (userMail.Length < 1) {
         throw new ArgumentException("User email cannot be blank");
     }
     userMail = userMail.Trim();
     bool userExists = false;
     using (var dbContext = new sliceofpieEntities2()) {
         if (dbContext.Users.Count(dbUser => dbUser.Email.Equals(userMail)) > 0) {
             userExists = true;
         }
     }
     if (!userExists) {
         throw new ArgumentException("User does not exist");
     }
     bool projectUserExists = true;
     using (var dbContext = new sliceofpieEntities2()) {
         var projectUsers = from projectUser in dbContext.ProjectUsers
                            where projectUser.ProjectId == projectId && projectUser.UserEmail == userMail
                            select projectUser;
         if (projectUsers.Count() == 0) {
             projectUserExists = false;
         }
     }
     if (projectUserExists) {
         throw new ArgumentException("User is already sharing this project");
     }
     using (var dbContext = new sliceofpieEntities2()) {
         ProjectUser projectUser = new ProjectUser();
         projectUser.ProjectId = projectId;
         projectUser.UserEmail = userMail;
         dbContext.ProjectUsers.AddObject(projectUser);
         dbContext.SaveChanges();
     }
 }
 /// <summary>
 /// Create a new ProjectUser object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static ProjectUser CreateProjectUser(global::System.Int64 id)
 {
     ProjectUser projectUser = new ProjectUser();
     projectUser.Id = id;
     return projectUser;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the ProjectUsers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProjectUsers(ProjectUser projectUser)
 {
     base.AddObject("ProjectUsers", projectUser);
 }