Beispiel #1
0
        public void AddTaskSectors(string sectorCustomers, string sectorMarketing, string sectorFinances, string sectorInternal, string sectorManagement, int taskId)
        {
            var sectors = new List <string>
            {
                sectorCustomers,
                sectorMarketing,
                sectorFinances,
                sectorInternal,
                sectorManagement
            };

            using (var db = new TorshiaDbContext())
            {
                foreach (var sectorString in sectors)
                {
                    if (Enum.TryParse <Sector>(sectorString, true, out var sector))
                    {
                        var taskSector = new TaskSector
                        {
                            TaskId = taskId,
                            Sector = sector
                        };

                        db.TaskSectors.Add(taskSector);
                        db.SaveChanges();
                    }
                }
            }
        }
        public bool AddToRole(string roleName, string userId)
        {
            Role role = context.Roles.FirstOrDefault(r => r.Name == roleName);

            if (role == null)
            {
                return(false);
            }

            UserRole userRole = new UserRole()
            {
                RoleId = role.Id, UserId = userId
            };

            context.UserRoles.Add(userRole);
            context.SaveChanges();
            return(true);
        }
Beispiel #3
0
        public void Create(TaskCreateInputModel model)
        {
            string[]         participantNames = model.Participants.Split(AffectedSectorSeperator);
            HashSet <string> participantIds   = new HashSet <string>();

            foreach (var participantName in participantNames)
            {
                Participant participant = context.Participants.FirstOrDefault(p => p.Name == participantName);
                if (participant == null)
                {
                    participant = new Participant {
                        Name = participantName
                    };
                    context.Participants.Add(participant);
                }

                participantIds.Add(participant.Id);
            }

            context.SaveChanges();

            HashSet <ParticipantTask> participantTasks = new HashSet <ParticipantTask>();

            foreach (var participanId in participantIds)
            {
                participantTasks.Add(new ParticipantTask {
                    ParticipantId = participanId
                });
            }

            Task task = new Task
            {
                AffectedSectors = string.Join(AffectedSectorSeperator, model.AffectedSectors),
                Description     = model.Description,
                Title           = model.Title,
                DueDate         = model.DueDate,
                Participants    = participantTasks,
            };

            context.Tasks.Add(task);
            context.SaveChanges();
        }
Beispiel #4
0
        public void ChangeIsReported(int taskId)
        {
            using (var db = new TorshiaDbContext())
            {
                var task = db.Tasks.FirstOrDefault(t => t.Id == taskId);

                task.IsReported = true;

                db.SaveChanges();
            }
        }
Beispiel #5
0
        public void ReportTask(string taskId, string reporterUsername)
        {
            Task task = this.GetTaskById(taskId);

            if (task == null)
            {
                return;
            }

            task.IsReported = true;

            this.reportsService.CreateReport(task.Id, reporterUsername);
            context.SaveChanges();
        }
        public void AddReport(DateTime date, Status status, int taskId, int userId)
        {
            using (var db = new TorshiaDbContext())
            {
                var reporter = new Report
                {
                    ReportedOn = date,
                    Status     = status,
                    TaskId     = taskId,
                    ReporterId = userId
                };

                db.Reports.Add(reporter);
                db.SaveChanges();
            }
        }
Beispiel #7
0
        public void AddUser(string username, string password, string email, Role role)
        {
            using (var db = new TorshiaDbContext())
            {
                var user = new User
                {
                    Username = username,
                    Password = password,
                    Email    = email,
                    Role     = role
                };

                db.Users.Add(user);
                db.SaveChanges();
            }
        }
Beispiel #8
0
        public Task AddTask(string title, DateTime dueDate, string description, string participants)
        {
            using (var db = new TorshiaDbContext())
            {
                var task = new Task
                {
                    Title        = title,
                    DueDate      = dueDate,
                    Description  = description,
                    Participants = participants
                };

                db.Tasks.Add(task);
                db.SaveChanges();

                return(task);
            }
        }
Beispiel #9
0
        public void CreateTask(string title, string dueDate, string description, string participants,
                               List <string> selectedSectors)
        {
            DateTime.TryParse(dueDate, out DateTime date);

            var task = new Task
            {
                Title        = title,
                DueDate      = date,
                Description  = description,
                Participants = participants
            };

            var taskSectors = new List <TaskSector>();

            foreach (var selectedSector in selectedSectors)
            {
                if (selectedSector != null)
                {
                    bool isValidSector = Enum.TryParse(typeof(Models.Enums.Sector), selectedSector.ToString(),
                                                       out object sectorValue);

                    if (isValidSector)
                    {
                        var sector = new Models.Sector {
                            Name = (Models.Enums.Sector)sectorValue
                        };
                        var taskSector = new TaskSector {
                            Task = task, Sector = sector
                        };
                        taskSectors.Add(taskSector);
                    }
                }
            }

            task.AffectedSectors.AddRange(taskSectors);

            context.Tasks.Add(task);
            context.SaveChanges();
        }
Beispiel #10
0
        private void SeedDatabase()
        {
            using (var context = new TorshiaDbContext())
            {
                context.Database.EnsureCreated();

                context.UserRoles.Add(new UserRole {
                    Name = "User"
                });
                context.UserRoles.Add(new UserRole {
                    Name = "Admin"
                });

                context.Sectors.Add(new Sector {
                    Name = "Customers"
                });
                context.Sectors.Add(new Sector {
                    Name = "Marketing"
                });
                context.Sectors.Add(new Sector {
                    Name = "Finances"
                });
                context.Sectors.Add(new Sector {
                    Name = "Internal"
                });
                context.Sectors.Add(new Sector {
                    Name = "Management"
                });

                context.ReportStatuses.Add(new ReportStatus {
                    Status = "Completed"
                });
                context.ReportStatuses.Add(new ReportStatus {
                    Status = "Archived"
                });

                context.SaveChanges();
            }
        }