public static Operation ById(int id) { using (var ctx = new SolutionsContext()) { return(ctx.Operations.First(x => x.Id == id)); } }
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); } }
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); }
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)); } }
private void RemovePermission(SolutionsContext ctx, int permissionId) { var permission = ctx.Permissions.First(x => x.Id == permissionId); ctx.Permissions.Remove(permission); ctx.SaveChanges(); }
private void InsertPermissions(SolutionsContext ctx, int employeeId, int roleId, List <int> resourceIds) { foreach (var id in resourceIds) { InsertPermission(ctx, employeeId, roleId, id); } }
public static Resource ById(int id) { using (var ctx = new SolutionsContext()) { return(ctx.Resources.First(x => x.Id == id)); } }
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(); } }
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(); } }
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); } }
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(); } }
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); } }
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(); }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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); } }
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); } }