Пример #1
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();
                }
            }
        }
Пример #2
0
        private void RemovePermission(SolutionsContext ctx, int permissionId)
        {
            var permission = ctx.Permissions.First(x => x.Id == permissionId);

            ctx.Permissions.Remove(permission);
            ctx.SaveChanges();
        }
Пример #3
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();
            }
        }
Пример #4
0
        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();
            }
        }
Пример #5
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);
            }
        }
Пример #6
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);
            }
        }
Пример #7
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();
        }
Пример #8
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);
            }
        }
Пример #9
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);
            }
        }
Пример #10
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);
            }
        }
Пример #11
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);
                }
            }
        }
Пример #12
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);
            }
        }
Пример #13
0
        public static void Save(int ticketId, int employeeId, string text, int commentType)
        {
            using (var ctx = new SolutionsContext())
            {
                var comment = new Comment()
                {
                    AuthorId      = employeeId,
                    CommentTypeId = commentType,
                    Date          = DateTime.Now,
                    TicketId      = ticketId,
                    Text          = text
                };

                ctx.Comments.Add(comment);
                ctx.SaveChanges();
            }
        }
Пример #14
0
        public static void Approve(int ticketId, int approverId, string comment)
        {
            using (var ctx = new SolutionsContext())
            {
                var ticket = ctx.Tickets.First(x => x.Id == ticketId);
                ticket.Approved   = DateTime.Now;
                ticket.ApproverId = approverId;

                if (ticket.PriorityId == (int)Enums.Priorities.C)
                {
                    ticket.StatusId = (int)Enums.Statuses.HOLD;
                }
                else
                {
                    ticket.StatusId = (int)Enums.Statuses.ON_PERFORM;
                }

                ctx.SaveChanges();

                Mail.Send(ticket, comment);
            }
        }
        public ActionResult AddTicket(InitiateViewModel model)
        {
            if (model.PriorityId == (int)Enums.Priorities.A)
            {
                if (model.PriorityDesc == null)
                {
                    ModelState.AddModelError("PriorityDesc", "Не указано обоснование класса А");
                }
            }

            if (!ModelState.IsValid)
            {
                var employee = Employee.GetEmployee(User.Identity.Name);
                var data     = MainForm(employee);

                data.Solutions     = model.Solutions ?? null;
                data.TechnicalTask = model.TechnicalTask ?? null;
                data.Desc          = model.Desc ?? null;
                data.FullDesc      = model.FullDesc ?? null;
                data.Instructions  = model.Instructions ?? null;
                data.PriorityDesc  = model.PriorityDesc ?? null;

                if (model.PriorityId != (int)Enums.Priorities.B)
                {
                    data.PriorityId = model.PriorityId;
                }

                if (model.TesterId != 1)
                {
                    data.TesterId = model.TesterId;
                }

                return(View("Index", data));
            }

            using (var ctx = new SolutionsContext())
            {
                var ticket = new Ticket()
                {
                    AuthorId      = model.AuthorId,
                    Desc          = model.Desc,
                    FullDesc      = model.FullDesc,
                    Instructions  = model.Instructions,
                    OperationId   = model.OperationId,
                    PriorityId    = model.PriorityId,
                    ResourceId    = model.ResourceId,
                    Solutions     = model.Solutions,
                    TechnicalTask = model.TechnicalTask,
                    Created       = DateTime.Now
                };

                if (ticket.ResourceId == (int)Enums.Resources.PRODUCTION)
                {
                    ticket.TesterId = model.TesterId;
                    ticket.StatusId = (int)Enums.Statuses.ON_APPROVE;
                }
                else if (ticket.PriorityId == (int)Enums.Priorities.A)
                {
                    ticket.StatusId = (int)Enums.Statuses.ON_APPROVE;
                }
                else if (ticket.PriorityId == (int)Enums.Priorities.C)
                {
                    ticket.StatusId = (int)Enums.Statuses.HOLD;
                }
                else
                {
                    ticket.StatusId = (int)Enums.Statuses.ON_PERFORM;
                }

                ctx.Tickets.Add(ticket);
                ctx.SaveChanges();

                Mail.Send(ticket);

                return(RedirectToAction("RequestSent"));
            }
        }