Example #1
0
        public async Task <bool> CreateModuleAsync(CreateModule createModule)
        {
            var module = await _tenantDataContext.Modules.FirstOrDefaultAsync(x => x.Name == createModule.Module.Name);

            if (module != null)
            {
                Console.WriteLine("There's a module with the name already");
                return(false);
            }

            var project = await _tenantDataContext.Projects.FirstOrDefaultAsync(x => x.Id == createModule.ProjectId);

            if (project == null)
            {
                Console.WriteLine("project does not exist");
                return(false);
            }

            createModule.Module.Project = project;

            await _tenantDataContext.Modules.AddAsync(createModule.Module);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
        public async Task <Project> CreateProjectAsync(NewProject newProject)
        {
            newProject.Project.Created = DateTime.Now;

            await _tenantDataContext.Projects.AddAsync(newProject.Project);

            newProject.Project.Employments = new List <ProjectEmployment>();

            foreach (var newProjectEmployment in newProject.Employments)
            {
                newProject.Project.Employments.Add(new ProjectEmployment
                {
                    ProjectId = newProject.Project.Id, UserId = newProjectEmployment.Id
                });
            }

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(newProject.Project);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception when creating project {e}");
                return(null);
            }
        }
Example #3
0
        public async Task <JobStatus> CreateJobStatus(NewStatus newStatus)
        {
            var jobStatusExists = await _tenantDataContext.JobStatuses.FirstOrDefaultAsync(x => x.Name == newStatus.Name);

            if (jobStatusExists != null)
            {
                Console.WriteLine("Job status already exists");
                return(null);
            }

            var jobStatus = new JobStatus()
            {
                Name     = newStatus.Name,
                Finished = newStatus.Finished,
                Order    = newStatus.Order,
                Colour   = newStatus.Colour
            };
            await _tenantDataContext.JobStatuses.AddAsync(jobStatus);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(jobStatus);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
Example #4
0
        public async Task <bool> CreateAsync(Guid id)
        {
            var userId = new UserId()
            {
                Id                 = id,
                JobEmployments     = new List <JobEmployment>(),
                ListEmployments    = new List <ListEmployment>(),
                ProjectEmployments = new List <ProjectEmployment>(),
                RoomMemberships    = new List <RoomMembership>()
            };

            await _tenantDataContext.UserIds.AddAsync(userId);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Example #5
0
        public async Task <Chat> CreateChat(Chat chat)
        {
            var room = await _tenantDataContext.Rooms.FirstOrDefaultAsync(x => x.Id == chat.Room.Id);

            // var userId = await _tenantDataContext.UserIds.FirstOrDefaultAsync(x => x.Id == chat.Id);

            // if (room == null || userId == null)
            if (room == null)
            {
                return(null);
            }

            chat.Room = room;
            // chat.UserId = userId;
            await _tenantDataContext.Chats.AddAsync(chat);

            if (room.Chats == null)
            {
                room.Chats = new List <Chat>();
            }
            room.Chats.Add(chat);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(chat);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception when creating chat {e}");
                return(null);
            }
        }
Example #6
0
        public async Task <bool> CreateRoomAsync(NewRoom newRoom)
        {
            var project = await _tenantDataContext.Projects.FirstOrDefaultAsync(x => x.Id == newRoom.ProjectId);

            if (project == null)
            {
                Console.WriteLine("Couldn't find project");
                return(false);
            }

            newRoom.Room.Project = project;

            await _tenantDataContext.Rooms.AddAsync(newRoom.Room);

            newRoom.Room.Chats       = new List <Chat>();
            newRoom.Room.Memberships = new List <RoomMembership>();
            foreach (var roomMembership in newRoom.Memberships)
            {
                newRoom.Room.Memberships.Add(new RoomMembership()
                {
                    RoomId = newRoom.Room.Id, UserId = roomMembership.Id
                });
            }


            if (project.Rooms == null)
            {
                project.Rooms = new List <Room>();
            }

            project.Rooms.Add(newRoom.Room);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception when creating room {e}");
                return(false);
            }
        }
        public async Task <bool> CreateListAsync(CreateList createList)
        {
            var project = await _tenantDataContext.Projects.FirstOrDefaultAsync(x => x.Id == createList.ProjectId);

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

            createList.List.Project = project;
            createList.List.Created = DateTime.Now;

            await _tenantDataContext.Lists.AddAsync(createList.List);

            createList.List.Employments = new List <ListEmployment>();
            foreach (var listEmployment in createList.Employments)
            {
                createList.List.Employments.Add(new ListEmployment()
                {
                    ListId = createList.List.Id,
                    UserId = listEmployment.Id
                });
            }

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Example #8
0
        private static async Task AddData(TenantDataContext dataContext, CreateTenant createTenant)
        {
            var projectId = Guid.NewGuid();
            var listId    = Guid.NewGuid();
            var userId    = createTenant.UserId;
            var roomId    = Guid.NewGuid();

            var jobIds         = new List <Guid>();
            var jobEmployments = new List <JobEmployment>();

            for (int i = 0; i < 10; i++)
            {
                var id = Guid.NewGuid();
                jobIds.Add(id);
                jobEmployments.Add(new JobEmployment()
                {
                    JobId  = id,
                    UserId = userId
                });
            }

            jobIds[0] = new Guid("0C8EBA6A-9765-43FB-A80D-A8C06D46AA2F");

            var user = new UserId()
            {
                Id              = userId,
                JobEmployments  = jobEmployments,
                ListEmployments = new List <ListEmployment>()
                {
                    new ListEmployment()
                    {
                        ListId = listId,
                        UserId = userId
                    }
                },
                ProjectEmployments = new List <ProjectEmployment>()
                {
                    new ProjectEmployment()
                    {
                        ProjectId = projectId,
                        UserId    = userId
                    }
                },
                RoomMemberships = new List <RoomMembership>()
                {
                    new RoomMembership()
                    {
                        RoomId = roomId, UserId = userId
                    }
                }
            };

            var statuses = new List <JobStatus>()
            {
                new JobStatus()
                {
                    Id       = Guid.NewGuid(),
                    Colour   = "#fec128",
                    Name     = "Todo",
                    Finished = false
                },
                new JobStatus()
                {
                    Id       = Guid.NewGuid(),
                    Colour   = "#f77d16",
                    Name     = "In progress",
                    Finished = false
                },
                new JobStatus()
                {
                    Id       = Guid.NewGuid(),
                    Colour   = "#03bbd3",
                    Name     = "Verify",
                    Finished = false
                },
                new JobStatus()
                {
                    Id       = Guid.NewGuid(),
                    Colour   = "#68B642",
                    Name     = "Completed",
                    Finished = true
                },
            };

            var types = new List <JobType>
            {
                new JobType()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#009688",
                    Name   = "Bug"
                },
                new JobType()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#9e9e9e",
                    Name   = "Feature"
                }
            };

            var priorities = new List <JobPriority>()
            {
                new JobPriority()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#ff5722",
                    Name   = "DEFCON 1"
                },
                new JobPriority()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#ff9800",
                    Name   = "DEFCON 2"
                },
                new JobPriority()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#ffc107",
                    Name   = "DEFCON 3"
                },
                new JobPriority()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#8bc34a",
                    Name   = "DEFCON 4"
                },
                new JobPriority()
                {
                    Id     = Guid.NewGuid(),
                    Colour = "#4caf50",
                    Name   = "DEFCON 5"
                }
            };

            var project = new Project()
            {
                Created     = DateTime.Now,
                Description = "Development project for development",
                Id          = projectId,
                Name        = "Development",
                Repo        = "",
                Accent      = "#1ad960",
                Avatar      = "https://pbs.twimg.com/profile_images/1292028907101671425/pp02tz90_400x400.jpg"
            };

            var list = new List()
            {
                Created     = DateTime.Now,
                Description = "Phase-1 list",
                Id          = listId,
                Name        = "Phase-1",
                Project     = project
            };

            var jobs  = new List <Job>();
            var count = 0;

            foreach (var id in jobIds)
            {
                jobs.Add(new Job()
                {
                    Created     = DateTime.Now,
                    Description =
                        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
                    Id            = id,
                    Title         = $"job #{count}",
                    Project       = project,
                    List          = list,
                    Link          = $"{createTenant.Tenant.Name}-{count}",
                    AssociatedUrl = "harrisonbarker.co.uk",
                    JobStatus     = statuses[new Random().Next(0, statuses.Count)],
                    JobPriority   = priorities[new Random().Next(0, priorities.Count)],
                    JobType       = types[new Random().Next(0, types.Count)]
                });
                count++;
            }

            var room = new Room()
            {
                Id      = roomId,
                Chats   = new List <Chat>(),
                Name    = "General",
                Project = project
            };

            var creationEvent = new Event()
            {
                Id          = Guid.NewGuid(),
                Description = "Created new project",
                Name        = "Creation",
                Project     = project,
                Time        = DateTime.Now
            };

            dataContext.Events.Add(creationEvent);
            dataContext.UserIds.Add(user);
            dataContext.Projects.Add(project);
            dataContext.Lists.Add(list);
            dataContext.Jobs.AddRange(jobs);
            dataContext.Rooms.Add(room);
            dataContext.JobStatuses.AddRange(statuses);
            dataContext.JobTypes.AddRange(types);
            dataContext.JobPriorities.AddRange(priorities);

            await dataContext.SaveChangesAsync();
        }
Example #9
0
        public async Task <bool> CreateJobAsync(NewJob newJob)
        {
            var list = await _tenantDataContext.Lists.FirstOrDefaultAsync(x => x.Id == newJob.ListId);

            var project = await _tenantDataContext.Projects.Include(x => x.Jobs).FirstOrDefaultAsync(x => x.Id == newJob.ProjectId);

            // var user = await _tenantDataContext.UserIds.FirstOrDefaultAsync(x => x.Id == newJob.UserId);

            var status =
                await _tenantDataContext.JobStatuses.FirstOrDefaultAsync(x => x.Name == newJob.Job.JobStatus.Name);

            var priority =
                await _tenantDataContext.JobPriorities.FirstOrDefaultAsync(x => x.Name == newJob.Job.JobPriority.Name);

            var type = await _tenantDataContext.JobTypes.FirstOrDefaultAsync(x => x.Name == newJob.Job.JobType.Name);

            if (newJob.ListId != Guid.Empty)
            {
                await _tenantDataContext.Lists.FirstOrDefaultAsync(x => x.Id == newJob.ListId);

                if (list == new List())
                {
                    Console.WriteLine("Couldn't find list");
                    return(false);
                }
            }

            if (project == null)
            {
                Console.WriteLine("Couldn't find project");
                return(false);
            }

            newJob.Job.List        = list;
            newJob.Job.Created     = DateTime.Now;
            newJob.Job.JobStatus   = status;
            newJob.Job.JobPriority = priority;
            newJob.Job.JobType     = type;

            newJob.Job.Link = $"{project.Short}-{project.Jobs.Count}";

            await _tenantDataContext.Jobs.AddAsync(newJob.Job);

            status.Jobs.Add(newJob.Job);
            priority.Jobs.Add(newJob.Job);
            type.Jobs.Add(newJob.Job);

            newJob.Job.Employments = new List <JobEmployment>();
            foreach (var newJobEmployment in newJob.Employments)
            {
                newJob.Job.Employments.Add(new JobEmployment {
                    JobId = newJob.Job.Id, UserId = newJobEmployment.Id
                });
            }

            if (list != new List() && list.Jobs == null)
            {
                list.Jobs = new List <Job>();
            }

            list.Jobs.Add(newJob.Job);

            if (project.Jobs == null)
            {
                project.Jobs = new List <Job>();
            }

            project.Jobs.Add(newJob.Job);

            try
            {
                await _tenantDataContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }