Example #1
0
 public static Operation ById(int id)
 {
     using (var ctx = new SolutionsContext())
     {
         return(ctx.Operations.First(x => x.Id == id));
     }
 }
Example #2
0
        public static void EmployeeActivity(int employeeId, bool isActive)
        {
            var employee = Employee.GetEmployee(employeeId);

            if (employee != null)
            {
                using (var ctx = new SolutionsContext())
                {
                    if (!isActive)
                    {
                        if (employee.Permissions != null)
                        {
                            var permissions = ctx.Permissions
                                              .Where(x => x.EmployeeId == employeeId)
                                              .ToList();

                            ctx.Permissions.RemoveRange(permissions);
                            ctx.SaveChanges();
                        }
                    }

                    ctx.Employees.First(x => x.Id == employeeId).Active = isActive;
                    ctx.SaveChanges();
                }
            }
        }
        private static InitiateViewModel MainForm(Employee author)
        {
            using (var ctx = new SolutionsContext())
            {
                var troubleStatuses = new List <int>()
                {
                    (int)Enums.Statuses.NOT_APPROVED
                };

                var activeStatuses = new List <int>()
                {
                    (int)Enums.Statuses.ON_APPROVE,
                    (int)Enums.Statuses.ON_PERFORM,
                    (int)Enums.Statuses.HOLD
                };

                var model = new InitiateViewModel()
                {
                    AuthorId       = author.Id,
                    AuthorName     = ActiveDirectory.GetName(author.Account),
                    Operations     = new List <Operation>(ctx.Operations),
                    Priorities     = new List <Priority>(ctx.Priorities),
                    Resources      = new List <Resource>(ctx.Resources),
                    Testers        = Employee.ByRoleRepo((int)Enums.Roles.TESTER),
                    TroubleTickets = Ticket.AuthorRepo(troubleStatuses, author),
                    ActiveTickets  = Ticket.AuthorRepo(activeStatuses, author),
                    ClosedTickets  = Ticket.ClosedRepo(author, (int)Enums.Roles.AUTHOR)
                };

                return(model);
            }
        }
Example #4
0
 public static Priority ById(int id)
 {
     using (var ctx = new SolutionsContext())
     {
         return(ctx.Priorities.First(x => x.Id == id));
     }
 }
        private static void PrepareTicketList(List <Ticket> tickets)
        {
            using (var ctx = new SolutionsContext())
            {
                var resources  = ctx.Resources.ToList();
                var statuses   = ctx.Statuses.ToList();
                var operations = ctx.Operations.ToList();
            }

            foreach (var ticket in tickets)
            {
                ticket.Author    = Employee.GetEmployee(ticket.AuthorId);
                ticket.Priority  = Priority.ById(ticket.PriorityId);
                ticket.Operation = Operation.ById(ticket.OperationId);
                ticket.Resource  = Resource.ById(ticket.OperationId);
                ticket.Status    = Status.ById(ticket.StatusId);

                if (ticket.TesterId != null)
                {
                    ticket.Tester = Employee.GetEmployee(ticket.TesterId);
                }
                if (ticket.ApproverId != null)
                {
                    ticket.Approver = Employee.GetEmployee(ticket.ApproverId);
                }
                if (ticket.PerformerId != null)
                {
                    ticket.Performer = Employee.GetEmployee(ticket.PerformerId);
                }

                ticket.ApproverComments  = Comment.ByType(ticket.Id, (int)Enums.CommentTypes.Approve);
                ticket.PerformerComments = Comment.ByType(ticket.Id, (int)Enums.CommentTypes.Perform);
            }
        }
 public static Ticket ById(int ticketId)
 {
     using (var ctx = new SolutionsContext())
     {
         return(ctx.Tickets.First(x => x.Id == ticketId));
     }
 }
        public static List <Ticket> ByEmployeeRepo(int statusId, int roleId, Employee employee)
        {
            List <Ticket> tickets;

            if (employee.HasRole((int)Enums.Roles.ADMINISTRATOR))
            {
                tickets = Ticket.ByStatusRepo(statusId);
            }
            else
            {
                var resources = employee.Permissions
                                .Where(x => x.RoleId == roleId)
                                .Select(p => p.ResourceId)
                                .ToList();

                using (var ctx = new SolutionsContext())
                {
                    tickets = ctx.Tickets
                              .Where(x => x.StatusId == statusId && resources.Contains(x.ResourceId))
                              .OrderByDescending(x => x.Created)
                              .ToList();
                }
            }

            Ticket.PrepareTicketsToView(tickets);
            return(tickets);
        }
Example #8
0
        public ActionResult SaveEmployeeForm(PermissionsViewModel model)
        {
            if (model.Id == 0)
            {
                if (model.Account == null)
                {
                    using (var ctx = new SolutionsContext())
                        model.ResourceRepo = ctx.Resources.ToList();

                    model.SelectedApproveResources = new List <int>();
                    model.SelectedPerformResources = new List <int>();

                    ModelState.AddModelError("Account", "Не указана учетная запись");
                    return(View("EmployeeForm", model));
                }

                var employee = Employee.GetEmployee(model.Account);
                if (employee == null)
                {
                    InsertEmployee(model);
                }
                else
                {
                    Employee.EmployeeActivity(employee.Id, true);
                    model.Id = employee.Id;
                    UpdateEmployee(model);
                }
            }
            else
            {
                UpdateEmployee(model);
            }

            return(RedirectToAction("Index"));
        }
 public static Status ById(int id)
 {
     using (var ctx = new SolutionsContext())
     {
         return(ctx.Statuses.First(x => x.Id == id));
     }
 }
Example #10
0
        private void RemovePermission(SolutionsContext ctx, int permissionId)
        {
            var permission = ctx.Permissions.First(x => x.Id == permissionId);

            ctx.Permissions.Remove(permission);
            ctx.SaveChanges();
        }
Example #11
0
 private void InsertPermissions(SolutionsContext ctx, int employeeId, int roleId, List <int> resourceIds)
 {
     foreach (var id in resourceIds)
     {
         InsertPermission(ctx, employeeId, roleId, id);
     }
 }
Example #12
0
 public static Resource ById(int id)
 {
     using (var ctx = new SolutionsContext())
     {
         return(ctx.Resources.First(x => x.Id == id));
     }
 }
Example #13
0
        public static List <Ticket> AuthorRepo(List <int> statusIds, Employee employee)
        {
            List <Ticket> tickets;

            using (var ctx = new SolutionsContext())
            {
                if (employee.HasRole((int)Enums.Roles.ADMINISTRATOR))
                {
                    tickets = ctx.Tickets
                              .Where(x => statusIds.Contains(x.StatusId))
                              .OrderByDescending(x => x.Created)
                              .ToList();
                }
                else
                {
                    tickets = ctx.Tickets
                              .Where(x => x.AuthorId == employee.Id &&
                                     statusIds.Contains(x.StatusId))
                              .OrderByDescending(x => x.Created)
                              .ToList();
                }
            }

            Ticket.PrepareTicketsToView(tickets);
            return(tickets);
        }
        public static void Update(int commentId, string answer)
        {
            using (var ctx = new SolutionsContext())
            {
                var comment = ctx.Comments.First(x => x.Id == commentId);
                comment.Answer = answer;

                ctx.SaveChanges();
            }
        }
Example #15
0
        private void SetSendMail(Employee employee, bool sendMail)
        {
            using (var ctx = new SolutionsContext())
            {
                var emp = ctx.Employees.First(x => x.Id == employee.Id);
                emp.SendMail = sendMail;

                ctx.SaveChanges();
            }
        }
Example #16
0
        public static List <Ticket> ClosedRepo(Employee employee, int roleId)
        {
            var from           = DateTime.Now.AddMonths(-1);
            var closedStatuses = new List <int>()
            {
                (int)Enums.Statuses.DONE,
                (int)Enums.Statuses.DECLINED
            };

            using (var ctx = new SolutionsContext())
            {
                var tickets = new List <Ticket>();

                if (employee.HasRole((int)Enums.Roles.ADMINISTRATOR))
                {
                    tickets = ctx.Tickets
                              .Where(x => x.Created >= from &&
                                     closedStatuses.Contains(x.StatusId))
                              .OrderByDescending(x => x.Created)
                              .AsNoTracking()
                              .ToList();
                }
                else
                {
                    if (roleId == (int)Enums.Roles.AUTHOR)
                    {
                        ctx.Tickets
                        .Where(x => x.AuthorId == employee.Id &&
                               x.Created >= from &&
                               closedStatuses.Contains(x.StatusId))
                        .OrderByDescending(x => x.Created)
                        .AsNoTracking()
                        .ToList();
                    }
                    else
                    {
                        var employeeResources = employee.Permissions
                                                .Where(x => x.RoleId == roleId)
                                                .Select(p => p.ResourceId)
                                                .ToList();

                        tickets = ctx.Tickets
                                  .Where(x => employeeResources.Contains(x.ResourceId) &&
                                         x.Created >= from &&
                                         closedStatuses.Contains(x.StatusId))
                                  .AsNoTracking()
                                  .ToList();
                    }
                }

                Ticket.PrepareTicketsToView(tickets);
                return(tickets);
            }
        }
Example #17
0
 public void GetData()
 {
     using (var ctx = new SolutionsContext())
     {
         this.Name        = ActiveDirectory.GetName(this.Account);
         this.Permissions = ctx.Permissions
                            .Where(x => x.EmployeeId == this.Id)
                            .AsNoTracking()
                            .ToList();
     }
 }
Example #18
0
        public static void Close(int ticketId)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketId);
                ticket.StatusId = (int)Enums.Statuses.CLOSED;

                ctx.SaveChanges();

                Mail.Send(ticket);
            }
        }
Example #19
0
        private void InsertPermission(SolutionsContext ctx, int employeeId, int roleId, int resourceId)
        {
            var permission = new Permission()
            {
                EmployeeId = employeeId,
                RoleId     = roleId,
                ResourceId = resourceId
            };

            ctx.Permissions.Add(permission);
            ctx.SaveChanges();
        }
Example #20
0
        public static void Hold(int ticketId, int employeeId, string comment)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketId);
                ticket.StatusId = (int)Enums.Statuses.HOLD;

                ctx.SaveChanges();

                Mail.Send(ticket, comment);
            }
        }
Example #21
0
        public static List <Ticket> ByStatusRepo(int statusId)
        {
            using (var ctx = new SolutionsContext())
            {
                var tickets = ctx.Tickets
                              .Where(x => x.StatusId == statusId)
                              .OrderByDescending(x => x.Created)
                              .ToList();

                Ticket.PrepareTicketsToView(tickets);
                return(tickets);
            }
        }
Example #22
0
        public static void Assign(int ticketId, int employeeId, string comment)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketId);
                ticket.PerformerId = employeeId;
                ticket.StatusId    = (int)Enums.Statuses.ON_PERFORM;

                ctx.SaveChanges();

                Mail.Send(ticket, comment);
            }
        }
Example #23
0
        public static void Decline(int ticketId, int employeeId, string comment)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketId);
                ticket.Performed = DateTime.Now;
                ticket.StatusId  = (int)Enums.Statuses.DECLINED;

                ctx.SaveChanges();

                Mail.Send(ticket, comment);
            }
        }
Example #24
0
        public static Employee GetEmployee(string account)
        {
            using (var ctx = new SolutionsContext())
            {
                var user = ctx.Employees.FirstOrDefault(x => x.Account == account);
                if (user == null)
                {
                    return(null);
                }

                user.GetData();
                return(user);
            }
        }
Example #25
0
        public static void Reject(int ticketId, int employeeId, string comment)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketId);
                ticket.Approved   = DateTime.Now;
                ticket.ApproverId = employeeId;
                ticket.StatusId   = (int)Enums.Statuses.NOT_APPROVED;

                ctx.SaveChanges();

                Mail.Send(ticket, comment);
            }
        }
Example #26
0
        private void ActualizePermissions(Employee employee, List <int> newResourceIds, int roleId)
        {
            var oldRolePermissions = employee.Permissions.Where(x => x.RoleId == roleId).ToList();

            using (var ctx = new SolutionsContext())
            {
                if (newResourceIds != null)
                {
                    foreach (var oldPermission in oldRolePermissions)
                    {
                        var permission = oldRolePermissions
                                         .FirstOrDefault(x => newResourceIds.Contains(oldPermission.ResourceId));

                        if (permission == null)
                        {
                            RemovePermission(ctx, oldPermission.Id);
                        }
                    }

                    foreach (var newResourceId in newResourceIds)
                    {
                        if (oldRolePermissions != null)
                        {
                            var oldPermission = oldRolePermissions
                                                .FirstOrDefault(x => x.ResourceId == newResourceId);

                            if (oldPermission == null)
                            {
                                InsertPermission(ctx, employee.Id, roleId, newResourceId);
                            }
                        }
                        else
                        {
                            InsertPermission(ctx, employee.Id, roleId, newResourceId);
                        }
                    }
                }
                else
                {
                    if (oldRolePermissions != null)
                    {
                        foreach (var permission in oldRolePermissions)
                        {
                            RemovePermission(ctx, permission.Id);
                        }
                    }
                }
            }
        }
        public static List <Comment> ByType(int ticketId, int commentTypeId)
        {
            using (var ctx = new SolutionsContext())
            {
                var comments = ctx.Comments.Where(x =>
                                                  x.TicketId == ticketId &&
                                                  x.CommentTypeId == commentTypeId)
                               .AsNoTracking()
                               .ToList();

                comments.ForEach(x => x.Author = Employee.GetEmployee(x.AuthorId));

                return(comments);
            }
        }
Example #28
0
        private void InsertEmployee(PermissionsViewModel permissions)
        {
            using (var ctx = new SolutionsContext())
            {
                var employee = new Employee()
                {
                    Account  = AccountFormat(permissions.Account),
                    Active   = true,
                    SendMail = permissions.SendMail
                };

                ctx.Employees.Add(employee);
                ctx.SaveChanges();

                if (permissions.Author)
                {
                    InsertPermission(ctx, employee.Id, (int)Enums.Roles.AUTHOR, 0);
                }

                if (permissions.Tester)
                {
                    InsertPermission(ctx, employee.Id, (int)Enums.Roles.TESTER, 0);
                }

                if (permissions.SelectedApproveResources != null)
                {
                    InsertPermissions(
                        ctx,
                        employee.Id,
                        (int)Enums.Roles.APPROVER,
                        permissions.SelectedApproveResources);
                }

                if (permissions.SelectedPerformResources != null)
                {
                    InsertPermissions(
                        ctx,
                        employee.Id,
                        (int)Enums.Roles.PERFORMER,
                        permissions.SelectedPerformResources);
                }

                if (permissions.Administrator)
                {
                    InsertPermission(ctx, employee.Id, (int)Enums.Roles.ADMINISTRATOR, 0);
                }
            }
        }
Example #29
0
        public static void Reapprove(Ticket ticketData, string comment)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketData.Id);
                ticket.TechnicalTask = ticketData.TechnicalTask;
                ticket.Desc          = ticketData.Desc;
                ticket.FullDesc      = ticketData.FullDesc;
                ticket.Instructions  = ticketData.Instructions;
                ticket.StatusId      = (int)Enums.Statuses.ON_APPROVE;

                ctx.SaveChanges();

                Mail.Send(ticket, comment);
            }
        }
Example #30
0
        public static List <Ticket> ActiveRepo()
        {
            using (var ctx = new SolutionsContext())
            {
                var tickets = ctx.Tickets
                              .Where(x => x.StatusId != (int)Enums.Statuses.DONE &&
                                     x.StatusId != (int)Enums.Statuses.DECLINED &&
                                     x.StatusId != (int)Enums.Statuses.DELETED)
                              .OrderByDescending(x => x.Created)
                              .AsNoTracking()
                              .ToList();

                Ticket.PrepareTicketsToView(tickets);
                return(tickets);
            }
        }