Exemple #1
0
        public async System.Threading.Tasks.Task RemoveAsync(Project project)
        {
            if (project != null)
            {
                try
                {
                    using (var db = new AsanaDbContext())
                    {
                        var pm = db.Projects.FirstOrDefault(x => x.Id == project.Id).ProjectManager;
                        if (!pm.Equals(CurrentUser.Instance.User.FullName))
                        {
                            throw new Exception("You are not permitted to delete this project.");
                        }
                        var p = db.Projects.FirstOrDefault(x => x.Id == project.Id);

                        if (p != null)
                        {
                            var x = new ChatService();
                            x.RemoveAsync(p.Id);
                            db.Projects.Remove(p);
                        }
                        await db.SaveChangesAsync();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Exemple #2
0
        public async System.Threading.Tasks.Task UpdatePositionAsync(int index, Project project)
        {
            if (project != null)
            {
                try
                {
                    using (var db = new AsanaDbContext())
                    {
                        var pm = db.Projects.FirstOrDefault(x => x.Id == project.Id).ProjectManager;
                        if (!pm.Equals(CurrentUser.Instance.User.FullName))
                        {
                            throw new Exception("You are not permitted to edit this project.");
                        }
                        var item = db.Projects.FirstOrDefault(x => x.Id == project.Id);
                        if (item != null)
                        {
                            db.Projects.First(x => x.Id == item.Id).Position = index;
                        }
                        await db.SaveChangesAsync();
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Exemple #3
0
        public async System.Threading.Tasks.Task CreateAsync(UserRoles user)
        {
            EmailHelper sendEmail = new EmailHelper();

            if (user != null)
            {
                try
                {
                    using (var asana = new AsanaDbContext())
                    {
                        var u = asana.Users.FirstOrDefault(x => x.Email.Equals(user.Email));
                        if (u == null)
                        {
                            sendEmail.SendInvitation(user.Email);
                            throw new Exception($"This employee has not registered yet. Invitation message is sent to {user.Email}.");
                        }
                        var userRole = asana.UserRoles.FirstOrDefault(x => x.Email.Equals(user.Email) &&
                                                                      x.ProjectId == user.ProjectId &&
                                                                      x.FullName.Equals(x.FullName));
                        if (userRole != null)
                        {
                            throw new Exception("User with this username already exists.");
                        }
                        asana.UserRoles.Add(user);
                        await asana.SaveChangesAsync();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Exemple #4
0
        public async System.Threading.Tasks.Task UpdateAsync(Project project)
        {
            if (project != null)
            {
                try
                {
                    using (var db = new AsanaDbContext())
                    {
                        var pm = db.Projects.FirstOrDefault(x => x.Id == project.Id).ProjectManager;
                        if (!pm.Equals(CurrentUser.Instance.User.FullName))
                        {
                            throw new Exception("You are not permitted to edit this project.");
                        }
                        db.Projects.First(x => x.Id == project.Id).Name           = project.Name;
                        db.Projects.First(x => x.Id == project.Id).ProjectEmail   = project.ProjectEmail;
                        db.Projects.First(x => x.Id == project.Id).ProjectManager = project.ProjectManager;
                        db.Projects.First(x => x.Id == project.Id).Description    = project.Description;
                        db.Projects.First(x => x.Id == project.Id).Deadline       = project.Deadline;

                        await db.SaveChangesAsync();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Exemple #5
0
 public async System.Threading.Tasks.Task RemoveAsync(Column column)
 {
     if (column != null)
     {
         try
         {
             if (!CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager))
             {
                 throw new Exception("You are not permited to remove the column.");
             }
             using (var context = new AsanaDbContext())
             {
                 var c = context.Columns.FirstOrDefault(x => x.Id == column.Id);
                 if (c != null)
                 {
                     context.Columns.Remove(c);
                 }
                 await context.SaveChangesAsync();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #6
0
 public async System.Threading.Tasks.Task CreateAsync(Column column)
 {
     if (column != null)
     {
         try
         {
             if (!CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager))
             {
                 throw new Exception("You are not permited to add new column.");
             }
             using (var context = new AsanaDbContext())
             {
                 int maxPosition = 0;
                 if (context.Columns.Count() > 0)
                 {
                     maxPosition = context.Columns.Max(x => x.Position) + 1;
                 }
                 column.Position = maxPosition;
                 context.Columns.Add(column);
                 await context.SaveChangesAsync();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #7
0
 public async void RemoveAsync(Guid projectId)
 {
     if (projectId != null)
     {
         try
         {
             using (var context = new AsanaDbContext())
             {
                 var chat = context.ChatRooms.Where(x => x.ProjectId == projectId);
                 if (chat != null)
                 {
                     foreach (var item in chat)
                     {
                         context.ChatRooms.Remove(item);
                     }
                 }
                 await context.SaveChangesAsync();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #8
0
 public async System.Threading.Tasks.Task RemoveAsync(Objects.Task task)
 {
     if (task != null)
     {
         try
         {
             if (CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager) ||
                 CurrentUser.Instance.User.FullName.Equals(task.AssignedTo))
             {
                 using (var context = new AsanaDbContext())
                 {
                     var t = context.Tasks.FirstOrDefault(x => x.Id == task.Id);
                     if (t != null)
                     {
                         context.Tasks.Remove(t);
                     }
                     await context.SaveChangesAsync();
                 }
             }
             else
             {
                 throw new Exception("You are not permitted to delete task.");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #9
0
        public async System.Threading.Tasks.Task UpdateColumnId(Guid columnId, Objects.Task task)
        {
            if (task != null)
            {
                try
                {
                    if (CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager) ||
                        CurrentUser.Instance.User.FullName.Equals(task.AssignedTo))
                    {
                        using (var context = new AsanaDbContext())
                        {
                            var t = context.Tasks.Include("Column").Include("TaskLogs").FirstOrDefault(x => x.Id == task.Id);

                            if (t != null)
                            {
                                var c = context.Columns.FirstOrDefault(x => x.Id == task.ColumnId);
                                if (c != null)
                                {
                                    context.Tasks.FirstOrDefault(x => x.Id == t.Id).ColumnId = columnId;
                                }
                                await context.SaveChangesAsync();
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("You are not permitted to edit the task.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Exemple #10
0
 public async System.Threading.Tasks.Task CreateAsync(Objects.Task task)
 {
     if (task != null)
     {
         try
         {
             if (CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager))
             {
                 using (var context = new AsanaDbContext())
                 {
                     int maxPosition = 0;
                     task.IsTaskAdded = true;
                     task.CreatedAt   = DateTime.Now;
                     if (context.Tasks.Count() > 0)
                     {
                         maxPosition = context.Tasks.Max(x => x.Position) + 1;
                     }
                     task.Position           = maxPosition;
                     task.CurrentKanbanState = context.KanbanState.FirstOrDefault(z => z.Name.Equals("In Progress")).Name;
                     context.Tasks.Add(task);
                     await context.SaveChangesAsync();
                 }
             }
             else
             {
                 throw new Exception("You are not permitted to create task");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #11
0
 public static async void EnsurePopulated()
 {
     using (var context = new AsanaDbContext())
     {
         if (context.KanbanState.Count() == 0)
         {
             context.KanbanState.Add(new KanbanState {
                 Name = "Ready for Next Stage"
             });
             context.KanbanState.Add(new KanbanState {
                 Name = "In Progress"
             });
             context.KanbanState.Add(new KanbanState {
                 Name = "Blocked"
             });
         }
         await context.SaveChangesAsync();
     }
 }
Exemple #12
0
 public async System.Threading.Tasks.Task CreateAsync(TaskLog log)
 {
     if (log != null)
     {
         try
         {
             using (var context = new AsanaDbContext())
             {
                 log.CreatedAt  = DateTime.Now;
                 log.ChangedBy += " - ";
                 context.TaskLogs.Add(log);
                 await context.SaveChangesAsync();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Exemple #13
0
 public async System.Threading.Tasks.Task CreateAsync(Project project)
 {
     if (project != null)
     {
         try
         {
             using (var context = new AsanaDbContext())
             {
                 var p = context.Projects.FirstOrDefault(x => x.ProjectEmail.Equals(project.ProjectEmail));
                 if (p != null)
                 {
                     throw new Exception("Project with this email already exists. TRY another email!");
                 }
                 else
                 {
                     int maxPosition = 0;
                     if (context.Projects.Count() > 0)
                     {
                         maxPosition = context.Projects.Max(x => x.Position) + 1;
                     }
                     project.Position = maxPosition;
                     context.Projects.Add(project);
                     context.UserRoles.Add(new UserRoles
                     {
                         Email     = CurrentUser.Instance.User.Email,
                         ProjectId = project.Id,
                         FullName  = project.ProjectManager
                     });
                     await context.SaveChangesAsync();
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #14
0
 public async System.Threading.Tasks.Task UpdateTitleAsync(string title, Column column)
 {
     if (!String.IsNullOrWhiteSpace(title) || column == null)
     {
         try
         {
             if (!CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager))
             {
                 throw new Exception("You are not permited to edit the column.");
             }
             using (var context = new AsanaDbContext())
             {
                 context.Columns.First(x => x.Id == column.Id)
                 .Title = title;
                 await context.SaveChangesAsync();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
     }
 }
Exemple #15
0
 public async Task CreateAsync(User user)
 {
     try
     {
         if (user != null)
         {
             using (var dbContext = new AsanaDbContext())
             {
                 if (dbContext.Users.ToList().Exists(x => x.Username == user.Username) &&
                     dbContext.Users.ToList().Exists(x => x.Email == user.Email))
                 {
                     throw new Exception("User with this username already exists.");
                 }
                 user.Password = PasswordHasher.Hash(user.Password);
                 dbContext.Users.Add(user);
                 await dbContext.SaveChangesAsync();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.InnerException.InnerException.ToString());
     }
 }
Exemple #16
0
        public async System.Threading.Tasks.Task UpdateAsync(Objects.Task task)
        {
            if (task != null)
            {
                try
                {
                    if (CurrentUser.Instance.User.FullName.Equals(CurrentProject.Instance.Project.ProjectManager) ||
                        CurrentUser.Instance.User.FullName.Equals(task.AssignedTo))
                    {
                        using (var context = new AsanaDbContext())
                        {
                            context.Tasks.First(x => x.Id == task.Id).IsStarred          = task.IsStarred;
                            context.Tasks.First(x => x.Id == task.Id).StarPath           = task.StarPath;
                            context.Tasks.First(x => x.Id == task.Id).CurrentKanbanState = task.CurrentKanbanState;

                            context.Tasks.First(x => x.Id == task.Id).AssignedTo = task.AssignedTo;

                            context.Tasks.First(x => x.Id == task.Id).ColumnId    = task.ColumnId;
                            context.Tasks.First(x => x.Id == task.Id).Deadline    = task.Deadline;
                            context.Tasks.First(x => x.Id == task.Id).Image       = task.Image;
                            context.Tasks.First(x => x.Id == task.Id).Description = task.Description;
                            context.Tasks.First(x => x.Id == task.Id).Title       = task.Title;
                            await context.SaveChangesAsync();
                        }
                    }
                    else
                    {
                        throw new Exception("You are not permitted to edit the task.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }