public TicketDTO PostTicket([FromBody] TicketDTO ticket)
        {
            var newTicket = db.Ticket.Add(converter.DTOToTicket(ticket));

            db.SaveChanges();
            return(converter.TicketToDTO(newTicket.Entity));
        }
        public ParentChildRelationDTO PostParentChildRelation([FromBody] ParentChildRelationDTO parentChildRelation)
        {
            var newParentChildRelation = db.ParentChildRelation.Add(converter.DTOToParentChildRelation(parentChildRelation));

            db.SaveChanges();
            return(converter.ParentChildRelationToDTO(newParentChildRelation.Entity));
        }
Exemple #3
0
        public StateDTO PostState([FromBody] StateDTO state)
        {
            var newState = db.State.Add(converter.DTOToState(state));

            db.SaveChanges();
            return(converter.StateToDTO(newState.Entity));
        }
Exemple #4
0
        public TeamDTO PostTeam([FromBody] TeamDTO t)
        {
            var a = db.Team.Add(converter.DTOToTeam(t));

            db.SaveChanges();

            return(converter.TeamToDTO(a.Entity));
        }
Exemple #5
0
        public EmployeeTeamDTO PostEmployeeTeam([FromBody] EmployeeTeamDTO e)
        {
            var a = db.EmployeeTeam.Add(converter.DTOToEmployeeTeam(e));

            db.SaveChanges();

            return(converter.EmployeeTeamToDTO(a.Entity));
        }
Exemple #6
0
        public AddressDTO PostAddress([FromBody] AddressDTO a)
        {
            var add = db.Address.Add(converter.DTOToAddress(a));

            db.SaveChanges();

            return(converter.AddressToDTO(add.Entity));
        }
Exemple #7
0
        public SubprocessDTO PostSubprocess([FromBody] SubprocessDTO s)
        {
            var a = db.Subprocess.Add(converter.DTOToSubprocess(s));

            Console.WriteLine(s.Description);

            db.SaveChanges();

            return(converter.SubprocessToDTO(a.Entity));
        }
        public ProcessDTO PostProcess([FromBody] ProcessDTO p)
        {
            Console.WriteLine(p);

            var a = db.Process.Add(converter.DTOToProcess(p));

            Console.WriteLine(p.Description);

            db.SaveChanges();

            return(converter.ProcessToDTO(a.Entity));
        }
Exemple #9
0
        private static List <Process> SeedProcesses(ProTickDatabaseContext context, int amount)
        {
            var processes = GetSeededProcesses(amount);

            processes.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(processes);
        }
Exemple #10
0
        private static List <State> SeedStates(ProTickDatabaseContext context, int amount)
        {
            var states = GetSeededStates(amount);

            states.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(states);
        }
Exemple #11
0
        private static List <EmployeeTeam> SeedEmployeeTeams(ProTickDatabaseContext context, int amount, List <Employee> emps, List <Team> teams)
        {
            var empTeams = GetSeededEmployeeTeams(amount, emps, teams);

            empTeams.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(empTeams);
        }
Exemple #12
0
        private static List <Team> SeedTeams(ProTickDatabaseContext context, int amount)
        {
            var teams = GetSeededTeams(amount);

            teams.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(teams);
        }
Exemple #13
0
        private static List <Employee> SeedEmployees(ProTickDatabaseContext context, int amount, List <Address> addresses, List <Role> roles)
        {
            var employees = GetSeededEmployees(amount, addresses, roles);

            employees.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(employees);
        }
Exemple #14
0
        private static List <Ticket> SeedTickets(ProTickDatabaseContext context, int amount, List <State> states, List <Subprocess> subprocesses)
        {
            var tickets = GetSeededTickets(amount, states, subprocesses);

            tickets.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(tickets);
        }
Exemple #15
0
        private static List <ParentChildRelation> SeedParentChildRelations(ProTickDatabaseContext context, int amount, List <Subprocess> children, List <Subprocess> parents)
        {
            var parentChildRelations = GetSeededParentChildRelations(amount, children, parents);

            parentChildRelations.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(parentChildRelations);
        }
Exemple #16
0
        private static List <Subprocess> SeedSubprocesses(ProTickDatabaseContext context, int amount, List <Process> processes, List <Team> teams)
        {
            var subprocesses = GetSeededSubprocesses(amount, processes, teams);

            subprocesses.ForEach(x => context.Add(x));
            context.SaveChanges();
            return(subprocesses);
        }
Exemple #17
0
        public EmployeeDTO PostEmployee([FromBody] EmployeeDTO e)
        {
            Console.WriteLine(e.AddressID);
            Console.WriteLine(e.FirstName);
            Console.WriteLine(e.LastName);
            var newEmp         = converter.DTOToEmployee(e);
            var passwordString = (e.FirstName.Substring(0, 1));

            if (e.LastName.Length >= 15)
            {
                passwordString += e.LastName.Substring(0, 15);
            }
            else
            {
                passwordString += e.LastName;
            }

            newEmp.Password = hasher.HashPassword(passwordString.ToLower());
            var a = db.Employee.Add(newEmp);

            db.SaveChanges();

            return(converter.EmployeeToDTO(a.Entity));
        }
Exemple #18
0
        public static ProTickDatabaseContext SeedFull(ProTickDatabaseContext context)
        {
            var addresses     = SeedAddresses(context, 3);
            var roles         = SeedRoles(context, 3);
            var emps          = SeedEmployees(context, 3, addresses, roles);
            var teams         = SeedTeams(context, 3);
            var empTeams      = SeedEmployeeTeams(context, 3, emps, teams);
            var states        = SeedStates(context, 3);
            var processes     = SeedProcesses(context, 3);
            var subprocesses  = SeedSubprocesses(context, 3, processes, teams);
            var cSubprocesses = new List <Subprocess>()
            {
                subprocesses[0], subprocesses[1], subprocesses[2], null
            };
            var pSubprocesses = new List <Subprocess>()
            {
                null, subprocesses[0], subprocesses[1], subprocesses[2]
            };
            var pcRelations = SeedParentChildRelations(context, 4, cSubprocesses, pSubprocesses);
            var tickets     = SeedTickets(context, 3, states, subprocesses);

            context.SaveChanges();
            return(context);
        }
Exemple #19
0
        public void TestGetProcessesWithSubprocess()
        {
            // db is empty
            using (var context = new ProTickDatabaseContext(dbOptions))
            {
                var dbm       = new DatabaseQueryManager(context);
                var converter = new ResourceDTOConverter(dbm);

                var controller = new ProcessController(context, converter, dbm);

                var actual  = controller.GetProcessesWithSubprocess(true).ToList().Count;
                var actual2 = controller.GetProcessesWithSubprocess(false).ToList().Count;

                int expected = 0;

                Assert.Equal(expected, actual);
                Assert.Equal(expected, actual2);
            }

            // seeding DB
            using (var context = new ProTickDatabaseContext(dbOptions))
            {
                DbContextSeeder.SeedFull(context);
            }

            // db is Test-Ready
            using (var context = new ProTickDatabaseContext(dbOptions))
            {
                var dbm       = new DatabaseQueryManager(context);
                var converter = new ResourceDTOConverter(dbm);

                var controller = new ProcessController(context, converter, dbm);

                var actual  = controller.GetProcessesWithSubprocess(true).ToList();
                var actual2 = controller.GetProcessesWithSubprocess(false).ToList().Count;


                var expected = DbContextSeeder.GetSeededProcessDTOs(
                    3
                    )
                               .ToList();

                Assert.Equal(expected.Count, actual.Count);
                Assert.Equal(0, actual2);

                expected.Should().BeEquivalentTo(actual);

                context.Subprocess.First(x => x.SubprocessID == 1).Process =
                    context.Process.First(x => x.ProcessID == 2);
                context.SaveChanges();

                var actual3 = controller.GetProcessesWithSubprocess(true).ToList();
                var actual4 = controller.GetProcessesWithSubprocess(false).ToList();

                var expected2 = new List <ProcessDTO>()
                {
                    expected[0]
                };
                expected.RemoveAt(0);

                Assert.Equal(actual3.Count, expected.Count);
                Assert.Equal(actual4.Count, expected2.Count);

                expected.Should().BeEquivalentTo(actual3);
                expected2.Should().BeEquivalentTo(actual4);
            }
        }
        public IActionResult ChangePassword([FromBody] LoginUserDTO editedLoginUser)
        {
            var username = editedLoginUser.Username;
            var emp      = dbm.FindEmployeeByUsername(username);

            string loggedInRole = User.Claims.FirstOrDefault(
                x => x.Type == ClaimTypes.Role)?.Value;
            string loggedInUser = User.Claims.FirstOrDefault(
                x => x.Type == ClaimTypes.NameIdentifier)?.Value;

            bool canEdit = false;

            if (loggedInRole != null && loggedInRole != string.Empty)
            {
                if (loggedInRole == StaticRoles.Admin)
                {
                    canEdit = true;
                }
                if (loggedInUser != null && loggedInUser != string.Empty)
                {
                    if (loggedInUser == username)
                    {
                        if (emp != null &&
                            editedLoginUser.OldPassword != null &&
                            editedLoginUser.OldPassword != "" &&
                            emp.Password == hasher.HashPassword(editedLoginUser.OldPassword))
                        {
                            canEdit = true;
                        }
                    }
                }
            }
            // Check if new password is valid
            if (editedLoginUser.Password == null || editedLoginUser.Password == "")
            {
                canEdit = false;
            }

            if (canEdit)
            {
                // Request is valid
                bool changesMade = false;

                string hashedPass = hasher.HashPassword(editedLoginUser.Password);

                if (hashedPass != null && hashedPass != "" && emp.Password != hashedPass)
                {
                    emp.Password = hashedPass;
                    changesMade  = true;
                }

                if (changesMade)
                {
                    db.SaveChanges();
                }

                return(Ok(converter.EmployeeToDTO(emp)));
            }

            return(Unauthorized());
        }