Example #1
0
        protected void AproveChanges(Ticket_statistic statistic, string secureID = null)
        {
            Tickets ticket = new Tickets();

            if (!string.IsNullOrEmpty(secureID))
            {
                ticket.SecureID = secureID;
                ticket.GetBySecureId();
            }
            else
            {
                ticket.ID = ID;
                ticket.GetById();
            }

            string status = string.Empty;

            TicketStatuses.TryGetValue(Convert.ToInt32(ticket.StatusID), out status);

            statistic.Status       = status;
            statistic.SecureID     = ticket.SecureID;
            statistic.UserID       = ticket.UserID;
            statistic.AgreedCost   = ticket.AgreedCost;
            statistic.GruzobozCost = ticket.GruzobozCost;
            statistic.AssessedCost = ticket.AssessedCost;
            statistic.ChangeDate   = DateTime.Now;
            statistic.Goods        = BLL.Helpers.GoodsHelper.GoodsToString(ticket.FullSecureID);

            statistic.Create();
        }
            public bool IsSlaPaused(int triggerId, int organizationId)
            {
                bool           isPaused = false;
                TicketStatuses statuses = new TicketStatuses(_loginUser);

                statuses.LoadByStatusIDs(organizationId, new int[] { TicketStatusId });

                if (statuses != null && statuses.Any())
                {
                    isPaused = statuses[0].PauseSLA;
                }

                //check if "Pause on Specific Dates"
                if (!isPaused)
                {
                    List <DateTime> daysToPause = SlaTriggers.GetSpecificDaysToPause(triggerId);
                    isPaused = daysToPause.Where(p => DateTime.Compare(p.Date, DateTime.UtcNow.Date) == 0).Any();
                }

                //If Pause on Company Holidays is selected
                SlaTrigger slaTrigger = SlaTriggers.GetSlaTrigger(_loginUser, triggerId);

                if (!isPaused && slaTrigger.PauseOnHoliday)
                {
                    isPaused = SlaTriggers.IsOrganizationHoliday(organizationId, DateTime.UtcNow);
                }

                return(isPaused);
            }
        public ActionResult DeleteConfirmed(int id)
        {
            TicketStatuses ticketStatuses = db.TicketStatuses.Find(id);

            db.TicketStatuses.Remove(ticketStatuses);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #4
0
        protected Ticket_statistic CheckChanges(string statusChange)
        {
            Tickets ticket = new Tickets()
            {
                ID = ID
            };

            ticket.GetById();

            var statistic = new Ticket_statistic();

            if (statusChange == "редактирование")
            {
                bool changed = false;
                statistic.Changes = "Редактирование заявки";

                if (GruzobozCost != ticket.GruzobozCost && GruzobozCost != null)
                {
                    changed            = true;
                    statistic.Changes += String.Format(", стоимость за услугу изменена с {0} на {1}", ticket.GruzobozCost, GruzobozCost);
                }

                if (AgreedCost != ticket.AgreedCost && AgreedCost != null)
                {
                    changed            = true;
                    statistic.Changes += String.Format(", согласованная стоимость изменена с {0} на {1}", ticket.AgreedCost, AgreedCost);
                }

                if (AssessedCost != ticket.AssessedCost && AssessedCost != null)
                {
                    changed            = true;
                    statistic.Changes += String.Format(", оценочная стоимость изменена с {0} на {1}", ticket.AssessedCost, AssessedCost);
                }

                if (StatusID != ticket.StatusID && StatusID != null)
                {
                    changed = true;

                    string statusOld = string.Empty;
                    string statusNew = string.Empty;
                    TicketStatuses.TryGetValue(Convert.ToInt32(ticket.StatusID), out statusOld);
                    TicketStatuses.TryGetValue(Convert.ToInt32(StatusID), out statusNew);

                    statistic.Changes += String.Format(", статус изменен с {0} на {1}", statusOld, statusNew);
                }

                if (changed == false)
                {
                    return(null);
                }
            }
            else
            {
                statistic.Changes = "Создание заявки";
            }

            return(statistic);
        }
 public ActionResult Edit([Bind(Include = "Id,Name")] TicketStatuses ticketStatuses)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticketStatuses).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ticketStatuses));
 }
        public static string GetTicketStatus(RestCommand command, int ticketStatusID)
        {
            TicketStatus ticketStatus = TicketStatuses.GetTicketStatus(command.LoginUser, ticketStatusID);

            if (ticketStatus.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(ticketStatus.GetXml("TicketStatus", true));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] TicketStatuses ticketStatuses)
        {
            if (ModelState.IsValid)
            {
                db.TicketStatuses.Add(ticketStatuses);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ticketStatuses));
        }
Example #8
0
        public async Task <List <Ticket> > GetTicketsByStatusAndUserName(TicketStatuses ticketStatus, string userName)
        {
            List <Ticket> resultTickets = new List <Ticket>();

            string userId = await context.Users.Where(u => u.UserName == userName).Select(u => u.Id).FirstOrDefaultAsync();

            if (userId != "" && ticketStatus != 0)
            {
                resultTickets = await context.Tickets.Where(t => t.SellerId == userId && t.Status == ticketStatus).Select(t => t).ToListAsync();
            }

            return(resultTickets);
        }
        // GET: TicketStatuses/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketStatuses ticketStatuses = db.TicketStatuses.Find(id);

            if (ticketStatuses == null)
            {
                return(HttpNotFound());
            }
            return(View(ticketStatuses));
        }
Example #10
0
        public static string GetTicketStatuses(RestCommand command, bool orderByDateCreated = false)
        {
            TicketStatuses items = new TicketStatuses(command.LoginUser);

            if (orderByDateCreated)
            {
                items.LoadByOrganizationID(command.Organization.OrganizationID, "DateCreated DESC");
            }
            else
            {
                items.LoadByOrganizationID(command.Organization.OrganizationID);
            }
            return(items.GetXml("TicketStatuses", "TicketStatus", true, command.Filters));
        }
        public static string GetTicketStatuses(RestCommand command)
        {
            TicketStatuses ticketStatuses = new TicketStatuses(command.LoginUser);

            ticketStatuses.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(ticketStatuses.GetXml("TicketStatuses", "TicketStatus", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Example #12
0
        public async Task <IActionResult> MyTickets(TicketStatuses ticketStatus, string userName)
        {
            ViewData["Title"] = localizer["myTicketsTitle"];

            var tickets = await ticketsService.GetTicketsByStatusAndUserName(ticketStatus, userName);

            var model = new MyTicketsViewModel
            {
                Tickets      = tickets,
                Events       = await eventsService.GetEventsByTickets(tickets),
                Users        = await usersAndRolesService.GetUsers(),
                ticketStatus = ticketStatus
            };

            return(View(model));
        }
Example #13
0
        public IEnumerable <Ticket> GetTicketsByEventIdAndStatus(int eventId, TicketStatuses status)
        {
            var eventTickets        = context.Tickets.Where(t => t.EventId == eventId && t.Status == status && t.ListingId == null).ToList();
            var listingEventTickets = context.Tickets.Where(t => t.EventId == eventId && t.Status == status && t.ListingId != null);
            var eventListings       = context.Listings.Where(l => l.EventId == eventId).ToList();

            foreach (Listing listing in eventListings)
            {
                var firstTicketInListing = listingEventTickets.FirstOrDefault(t => t.ListingId == listing.Id && t.Status == status);
                if (firstTicketInListing != null)
                {
                    eventTickets.Add(firstTicketInListing);
                }
            }

            return(eventTickets);
        }
Example #14
0
    private void LoadStatuses(int ticketTypeID)
    {
        cmbStatuses.Items.Clear();

        TicketStatuses statuses = new TicketStatuses(UserSession.LoginUser);

        statuses.LoadByTicketTypeID(ticketTypeID);

        foreach (TicketStatus status in statuses)
        {
            cmbStatuses.Items.Add(new RadComboBoxItem(status.Name, status.TicketStatusID.ToString()));
        }
        if (cmbStatuses.Items.Count > 0)
        {
            cmbStatuses.SelectedIndex = 0;
        }
    }
Example #15
0
        private void LoadCustomProperty()
        {
            switch (_refType)
            {
            case ReferenceType.ActionTypes:
                ActionType actionType = (ActionType)ActionTypes.GetActionType(LoginSession.LoginUser, _id);
                textDescription.Text = actionType.Description;
                textName.Text        = actionType.Name;
                break;

            case ReferenceType.PhoneTypes:
                PhoneType phoneType = (PhoneType)PhoneTypes.GetPhoneType(LoginSession.LoginUser, _id);
                textDescription.Text = phoneType.Description;
                textName.Text        = phoneType.Name;
                break;

            case ReferenceType.ProductVersionStatuses:
                ProductVersionStatus productVersionStatus = (ProductVersionStatus)ProductVersionStatuses.GetProductVersionStatus(LoginSession.LoginUser, _id);
                textDescription.Text   = productVersionStatus.Description;
                textName.Text          = productVersionStatus.Name;
                cbDiscontinued.Checked = productVersionStatus.IsDiscontinued;
                cbShipping.Checked     = productVersionStatus.IsShipping;
                break;

            case ReferenceType.TicketSeverities:
                TicketSeverity ticketSeverity = (TicketSeverity)TicketSeverities.GetTicketSeverity(LoginSession.LoginUser, _id);
                textDescription.Text = ticketSeverity.Description;
                textName.Text        = ticketSeverity.Name;
                break;

            case ReferenceType.TicketStatuses:
                TicketStatus ticketStatus = (TicketStatus)TicketStatuses.GetTicketStatus(LoginSession.LoginUser, _id);
                textDescription.Text = ticketStatus.Description;
                textName.Text        = ticketStatus.Name;
                cbClosed.Checked     = ticketStatus.IsClosed;
                break;

            default:
                break;
            }
        }
Example #16
0
    private void LoadAvailableStatuses(int statusID)
    {
        TicketStatuses statuses = new TicketStatuses(UserSession.LoginUser);

        statuses.LoadNotNextStatuses(statusID);

        string postBackControl = this.Request.Params["__EVENTTARGET"];

        if (!string.IsNullOrEmpty(postBackControl) && postBackControl.EndsWith("cmbNewStatus"))
        {
            int.TryParse(cmbNewStatus.SelectedValue, out _nextStatusSelected);
        }

        cmbNewStatus.Items.Clear();
        cmbNewStatus.Items.Add(new RadComboBoxItem("[Select a status]", "-1"));

        foreach (TicketStatus status in statuses)
        {
            cmbNewStatus.Items.Add(new RadComboBoxItem(status.Name, status.TicketStatusID.ToString()));
        }
    }
Example #17
0
        protected override void Seed(BugTracker.Models.ApplicationDbContext context)
        {
            // Seeding Priorities

            var priority1 = new TicketPriority();

            priority1.Name = "Low";

            context.TicketPriority.AddOrUpdate(p => p.Name, priority1);

            var priority2 = new TicketPriority();

            priority2.Name = "Medium";

            context.TicketPriority.AddOrUpdate(p => p.Name, priority2);

            var priority3 = new TicketPriority();

            priority3.Name = "High";

            context.TicketPriority.AddOrUpdate(p => p.Name, priority3);

            // Seeding Statuses

            var status1 = new TicketStatuses();

            status1.Name = "Open";

            context.TicketStatuses.AddOrUpdate(p => p.Name, status1);

            var status2 = new TicketStatuses();

            status2.Name = "Resolved";

            context.TicketStatuses.AddOrUpdate(p => p.Name, status2);

            var status3 = new TicketStatuses();

            status3.Name = "Rejected";

            context.TicketStatuses.AddOrUpdate(p => p.Name, status3);

            // Seeding Types

            var type1 = new TicketTypes();

            type1.Name = "Bug";

            context.TicketTypes.AddOrUpdate(p => p.Name, type1);

            var type2 = new TicketTypes();

            type2.Name = "Feature";

            context.TicketTypes.AddOrUpdate(p => p.Name, type2);

            var type3 = new TicketTypes();

            type3.Name = "Database";

            context.TicketTypes.AddOrUpdate(p => p.Name, type3);

            var type4 = new TicketTypes();

            type4.Name = "Support";

            context.TicketTypes.AddOrUpdate(p => p.Name, type4);

            //Seeding Users And Roles

            var roleManager =
                new RoleManager <IdentityRole>(
                    new RoleStore <IdentityRole>(context));

            //UserManager, used to manage users
            var userManager =
                new UserManager <ApplicationUser>(
                    new UserStore <ApplicationUser>(context));

            //Adding Admin role
            if (!context.Roles.Any(p => p.Name == "Admin"))
            {
                var adminRole = new IdentityRole("Admin");
                roleManager.Create(adminRole);
            }
            //Adding projectmanager role if it doesn't exist.
            if (!context.Roles.Any(p => p.Name == "ProjectManager"))
            {
                var moderatorRole = new IdentityRole("ProjectManager");
                roleManager.Create(moderatorRole);
            }
            //Adding admin role if it doesn't exist.
            if (!context.Roles.Any(p => p.Name == "Developer"))
            {
                var developerRole = new IdentityRole("Developer");
                roleManager.Create(developerRole);
            }
            //Adding submitter role if it doesn't exist.
            if (!context.Roles.Any(p => p.Name == "Submitter"))
            {
                var submitterRole = new IdentityRole("Submitter");
                roleManager.Create(submitterRole);
            }


            ApplicationUser adminUser;

            if (!context.Users.Any(
                    p => p.UserName == "*****@*****.**"))
            {
                adminUser             = new ApplicationUser();
                adminUser.UserName    = "******";
                adminUser.Email       = "*****@*****.**";
                adminUser.DisplayName = "Admin";

                userManager.Create(adminUser, "Password-1");
            }
            else
            {
                adminUser = context
                            .Users
                            .First(p => p.UserName == "*****@*****.**");
            }

            //Make sure the user is on the admin role
            if (!userManager.IsInRole(adminUser.Id, "Admin"))
            {
                userManager.AddToRole(adminUser.Id, "Admin");
            }
        }
Example #18
0
        private void SaveCustomProperty()
        {
            switch (_refType)
            {
            case ReferenceType.ActionTypes:
                ActionType  actionType;
                ActionTypes actionTypes = new ActionTypes(LoginSession.LoginUser);

                if (_id < 0)
                {
                    actionType = actionTypes.AddNewActionType();
                    actionType.OrganizationID = _organizationID;
                    actionType.Position       = actionTypes.GetMaxPosition(_organizationID) + 1;
                }
                else
                {
                    actionTypes.LoadByActionTypeID(_id);
                    actionType = actionTypes[0];
                }
                actionType.Description = textDescription.Text;
                actionType.Name        = textName.Text;
                actionTypes.Save();
                break;

            case ReferenceType.PhoneTypes:
                PhoneType  phoneType;
                PhoneTypes phoneTypes = new PhoneTypes(LoginSession.LoginUser);

                if (_id < 0)
                {
                    phoneType = phoneTypes.AddNewPhoneType();
                    phoneType.OrganizationID = _organizationID;
                    phoneType.Position       = phoneTypes.GetMaxPosition(_organizationID) + 1;
                }
                else
                {
                    phoneTypes.LoadByPhoneTypeID(_id);
                    phoneType = phoneTypes[0];
                }
                phoneType.Description = textDescription.Text;
                phoneType.Name        = textName.Text;
                phoneTypes.Save();
                break;

            case ReferenceType.ProductVersionStatuses:
                ProductVersionStatus   productVersionStatus;
                ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(LoginSession.LoginUser);

                if (_id < 0)
                {
                    productVersionStatus = productVersionStatuses.AddNewProductVersionStatus();
                    productVersionStatus.OrganizationID = _organizationID;
                    productVersionStatus.Position       = productVersionStatuses.GetMaxPosition(_organizationID) + 1;
                }
                else
                {
                    productVersionStatuses.LoadByProductVersionStatusID(_id);
                    productVersionStatus = productVersionStatuses[0];
                }
                productVersionStatus.Description    = textDescription.Text;
                productVersionStatus.Name           = textName.Text;
                productVersionStatus.IsDiscontinued = cbDiscontinued.Checked;
                productVersionStatus.IsShipping     = cbShipping.Checked;
                productVersionStatuses.Save();
                break;

            case ReferenceType.TicketSeverities:
                TicketSeverity   ticketSeverity;
                TicketSeverities ticketSeverities = new TicketSeverities(LoginSession.LoginUser);

                if (_id < 0)
                {
                    ticketSeverity = ticketSeverities.AddNewTicketSeverity();
                    ticketSeverity.OrganizationID = _organizationID;
                    ticketSeverity.Position       = ticketSeverities.GetMaxPosition(_organizationID) + 1;
                }
                else
                {
                    ticketSeverities.LoadByTicketSeverityID(_id);
                    ticketSeverity = ticketSeverities[0];
                }
                ticketSeverity.Description = textDescription.Text;
                ticketSeverity.Name        = textName.Text;
                ticketSeverities.Save();

                break;

            case ReferenceType.TicketStatuses:
                TicketStatus   ticketStatus;
                TicketStatuses ticketStatuses = new TicketStatuses(LoginSession.LoginUser);

                if (_id < 0)
                {
                    ticketStatus = ticketStatuses.AddNewTicketStatus();
                    ticketStatus.OrganizationID = _organizationID;
                    ticketStatus.TicketTypeID   = _ticketTypeID;
                    ticketStatus.Position       = ticketStatuses.GetMaxPosition(_ticketTypeID) + 1;
                }
                else
                {
                    ticketStatuses.LoadByTicketStatusID(_id);
                    ticketStatus = ticketStatuses[0];
                }
                ticketStatus.Description = textDescription.Text;
                ticketStatus.Name        = textName.Text;
                ticketStatus.IsClosed    = cbClosed.Checked;
                ticketStatuses.Save();
                break;

            default:
                break;
            }
        }
Example #19
0
 public async Task ChangeTicketStatus(Ticket ticket, TicketStatuses status)
 {
     ticket.Status = status;
     context.Tickets.Update(ticket);
     await context.SaveChangesAsync();
 }
        private void LoadCustomProperties()
        {
            int oldID = GetSelectedPropertyID();

            ReferenceType refType = GetSelectedPropertyType();

            DataTable table = new DataTable();

            table.Columns.Add("ID", System.Type.GetType("System.Int32"));
            table.Columns.Add("Name");
            table.Columns.Add("Description");
            table.Columns.Add("IsClosed", System.Type.GetType("System.Boolean"));
            table.Columns.Add("IsShipping", System.Type.GetType("System.Boolean"));
            table.Columns.Add("IsDiscontinued", System.Type.GetType("System.Boolean"));

            gridProperties.Columns["IsShipping"].IsVisible     = false;
            gridProperties.Columns["IsDiscontinued"].IsVisible = false;
            gridProperties.Columns["IsClosed"].IsVisible       = false;

            switch (refType)
            {
            case ReferenceType.ActionTypes:
                ActionTypes actionTypes = new ActionTypes(LoginSession.LoginUser);
                actionTypes.LoadAllPositions(OrganizationID);
                foreach (ActionType actionType in actionTypes)
                {
                    DataRow row = table.NewRow();
                    row[0] = actionType.ActionTypeID;
                    row[1] = actionType.Name;
                    row[2] = actionType.Description;
                    row[3] = false;
                    row[4] = false;
                    row[5] = false;
                    table.Rows.Add(row);
                }

                break;

            case ReferenceType.PhoneTypes:
                PhoneTypes phoneTypes = new PhoneTypes(LoginSession.LoginUser);
                phoneTypes.LoadAllPositions(OrganizationID);
                foreach (PhoneType phoneType in phoneTypes)
                {
                    DataRow row = table.NewRow();
                    row[0] = phoneType.PhoneTypeID;
                    row[1] = phoneType.Name;
                    row[2] = phoneType.Description;
                    row[3] = false;
                    row[4] = false;
                    row[5] = false;
                    table.Rows.Add(row);
                }
                break;

            case ReferenceType.ProductVersionStatuses:
                ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(LoginSession.LoginUser);
                productVersionStatuses.LoadAllPositions(OrganizationID);
                foreach (ProductVersionStatus productVersionStatus in productVersionStatuses)
                {
                    DataRow row = table.NewRow();
                    row[0] = productVersionStatus.ProductVersionStatusID;
                    row[1] = productVersionStatus.Name;
                    row[2] = productVersionStatus.Description;
                    row[3] = false;
                    row[4] = productVersionStatus.IsShipping;
                    row[5] = productVersionStatus.IsDiscontinued;
                    table.Rows.Add(row);
                }
                gridProperties.Columns["IsShipping"].IsVisible     = true;
                gridProperties.Columns["IsDiscontinued"].IsVisible = true;
                break;

            case ReferenceType.TicketSeverities:
                TicketSeverities ticketSeverities = new TicketSeverities(LoginSession.LoginUser);
                ticketSeverities.LoadAllPositions(OrganizationID);
                foreach (TicketSeverity ticketSeverity in ticketSeverities)
                {
                    DataRow row = table.NewRow();
                    row[0] = ticketSeverity.TicketSeverityID;
                    row[1] = ticketSeverity.Name;
                    row[2] = ticketSeverity.Description;
                    row[3] = false;
                    row[4] = false;
                    row[5] = false;
                    table.Rows.Add(row);
                }
                break;

            case ReferenceType.TicketStatuses:
                TicketStatuses ticketStatuses = new TicketStatuses(LoginSession.LoginUser);
                ticketStatuses.LoadAllPositions(GetSelectedTicketType());
                foreach (TicketStatus ticketStatus in ticketStatuses)
                {
                    DataRow row = table.NewRow();
                    row[0] = ticketStatus.TicketStatusID;
                    row[1] = ticketStatus.Name;
                    row[2] = ticketStatus.Description;
                    row[3] = ticketStatus.IsClosed;
                    row[4] = false;
                    row[5] = false;
                    table.Rows.Add(row);
                }
                gridProperties.Columns["IsClosed"].IsVisible = true;
                break;

            default:
                break;
            }



            gridProperties.DataSource = table;
            if (gridProperties.Rows.Count > 0)
            {
                gridProperties.Rows[0].IsCurrent = true;
            }
            SetSelectedPropertyID(oldID);
        }
        public TicketStatuses PostTicketsByStatusBeforeDate(Int64 markTicks)
        {
            TicketStatuses stats = new TicketStatuses();
            ArrayList res = new ArrayList();

            res = this.helpDeskService.getNumberOfTicketsByStatusBeforeDate(markTicks);
            Int16 zero = 0;
            Int16 one = 1;
            Int16 two = 2;
            Int16 three = 3;
            Int16 four = 4;
            Int16 five = 5;

            for (int i = 0; i < res.Count; i++)
            {

                if (res[i].Equals(zero))
                {
                    stats.newStatus++;
                }
                else if (res[i].Equals(one))
                {
                    stats.waitingReply++;
                }

                else if (res[i].Equals(two))
                {
                    stats.replied++;
                }

                else if (res[i].Equals(three))
                {
                    stats.resolved++;
                }
                else if (res[i].Equals(four))
                {
                    stats.inProgress++;
                }

                else if (res[i].Equals(five))
                {
                    stats.onHold++;
                }

            }

            return stats;
        }
        public TicketStatuses GetTicketsByPastStatus(Int64 startTicks, Int64 endTicks)
        {
            TicketStatuses stats = new TicketStatuses();
            ArrayList res = new ArrayList();
            //DateTime start = new DateTime(2014, 06, 30);

            //DateTime end = new DateTime(2014, 07, 1);

            res = this.helpDeskService.getNumberOfTicketsByPastStatus(startTicks, endTicks);
            Int16 zero = 0;
            Int16 one = 1;
            Int16 two = 2;
            Int16 three = 3;
            Int16 four = 4;
            Int16 five = 5;

            for (int i = 0; i < res.Count; i++)
            {

                if (res[i].Equals(zero))
                {
                    stats.newStatus++;
                }
                else if (res[i].Equals(one))
                {
                    stats.waitingReply++;
                }

                else if (res[i].Equals(two))
                {
                    stats.replied++;
                }

                else if (res[i].Equals(three))
                {
                    stats.resolved++;
                }
                else if (res[i].Equals(four))
                {
                    stats.inProgress++;
                }

                else if (res[i].Equals(five))
                {
                    stats.onHold++;
                }

            }

            return stats;
        }
        private void CreateTestTicket(ApplicationDbContext context)
        {
            if (!context.Tickets.Any())
            {
                TicketPriorities priority = context.TicketPriorities.First(p => p.PriorityString == nameof(TicketPrioritiesEnum.Medium));
                TicketStatuses   status   = context.TicketStatuses.First(p => p.StatusString == nameof(TicketStatusesEnum.Open));
                TicketTypes      type     = context.TicketTypes.First(p => p.TypeString == nameof(TicketTypesEnum.Feature));

                //! Ran into weird bugs when using ".First()", ".Last()", and ".ElementAt()"
                ApplicationUser author       = context.Users.First(user => user.Email.ToLower() == "*****@*****.**");
                ApplicationUser assignedUser = context.Users.First(user => user.Email.ToLower() == "*****@*****.**");

                Project project = author.Projects.FirstOrDefault() ?? context.Projects.First();

                TicketAttachment attachment = new TicketAttachment()
                {
                    Description = "testing attachment description",
                    FilePath    = "this is a file path",
                    FileUrl     = "this is a file url",
                    UserId      = author.Id,
                };

                TicketComment comment = new TicketComment()
                {
                    Comment = "this is a test comment",
                    UserId  = assignedUser.Id,
                };

                Ticket testTicket = new Ticket()
                {
                    AssignedUser   = assignedUser,
                    AssignedUserId = assignedUser.Id,
                    Author         = author,
                    AuthorId       = author.Id,
                    Title          = "Test Ticket",
                    Description    = "This is a test ticket",

                    PriorityId = priority.Id,
                    Priority   = priority,

                    StatusId = status.Id,
                    Status   = status,

                    TypeId = type.Id,
                    Type   = type,

                    ProjectId = project.Id,
                    Project   = project,

                    Attachments = new List <TicketAttachment>()
                    {
                        attachment
                    },
                    Comments = new List <TicketComment>()
                    {
                        comment
                    },
                };

                context.Tickets.AddOrUpdate(t => t.Title, testTicket);
            }
        }
    public static TypeObject GetTypeObject(SelectedType type, int id)
    {
        TypeObject result = new TypeObject();

        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionType actionType = ActionTypes.GetActionType(UserSession.LoginUser, id);
            result.ID          = actionType.ActionTypeID;
            result.Name        = actionType.Name;
            result.Description = actionType.Description;
            result.IsTimed     = actionType.IsTimed;
            break;

        case SelectedType.PhoneTypes:
            PhoneType phoneType = PhoneTypes.GetPhoneType(UserSession.LoginUser, id);
            result.ID          = phoneType.PhoneTypeID;
            result.Name        = phoneType.Name;
            result.Description = phoneType.Description;
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatus productVersionStatus = ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, id);
            result.ID             = productVersionStatus.ProductVersionStatusID;
            result.Name           = productVersionStatus.Name;
            result.Description    = productVersionStatus.Description;
            result.IsShipping     = productVersionStatus.IsShipping;
            result.IsDiscontinued = productVersionStatus.IsDiscontinued;
            break;

        case SelectedType.TicketSeverities:
            TicketSeverity ticketSeverity = TicketSeverities.GetTicketSeverity(UserSession.LoginUser, id);
            result.ID                = ticketSeverity.TicketSeverityID;
            result.Name              = ticketSeverity.Name;
            result.Description       = ticketSeverity.Description;
            result.IsVisibleOnPortal = ticketSeverity.VisibleOnPortal;
            break;

        case SelectedType.TicketStatuses:
            TicketStatus ticketStatus = TicketStatuses.GetTicketStatus(UserSession.LoginUser, id);
            result.ID              = ticketStatus.TicketStatusID;
            result.Name            = ticketStatus.Name;
            result.Description     = ticketStatus.Description;
            result.IsClosed        = ticketStatus.IsClosed;
            result.IsClosedEmail   = ticketStatus.IsClosedEmail;
            result.IsEmailResponse = ticketStatus.IsEmailResponse;
            result.PauseSla        = ticketStatus.PauseSLA;
            break;

        case SelectedType.TicketTypes:
            TicketType ticketType = TicketTypes.GetTicketType(UserSession.LoginUser, id);
            result.ID                = ticketType.TicketTypeID;
            result.Name              = ticketType.Name;
            result.Description       = ticketType.Description;
            result.IsVisibleOnPortal = ticketType.IsVisibleOnPortal;
            result.IconUrl           = ticketType.IconUrl;
            result.IsActive          = ticketType.IsActive;
            result.ExcludeFromCDI    = ticketType.ExcludeFromCDI;

            if (ticketType.ProductFamilyID == null)
            {
                result.ProductFamilyID = -1;
            }
            else
            {
                result.ProductFamilyID = (int)ticketType.ProductFamilyID;
            }

            break;

        case SelectedType.ActivityTypes:
            ActivityType activityType = ActivityTypes.GetActivityType(UserSession.LoginUser, id);
            result.ID          = activityType.ActivityTypeID;
            result.Name        = activityType.Name;
            result.Description = activityType.Description;
            break;

        default:
            break;
        }

        return(result);
    }
Example #25
0
        public AutomationData GetData()
        {
            AutomationData result = new AutomationData();
            TicketAutomationPossibleActions actions = new TicketAutomationPossibleActions(UserSession.LoginUser);

            actions.LoadActive();
            result.Actions = actions.GetTicketAutomationPossibleActionProxies();


            List <AutoFieldItem> fieldItems = new List <AutoFieldItem>();
            ReportTableFields    fields     = new ReportTableFields(TSAuthentication.GetLoginUser());

            fields.LoadByReportTableID(10);

            CustomFields customs = new CustomFields(fields.LoginUser);

            customs.LoadByReferenceType(TSAuthentication.OrganizationID, ReferenceType.Tickets);

            CustomFields orgfields = new CustomFields(fields.LoginUser);

            orgfields.LoadByReferenceType(TSAuthentication.OrganizationID, ReferenceType.Organizations);
            List <string> orgCustomFields = new List <string>();

            foreach (CustomField c in orgfields)
            {
                orgCustomFields.Add(c.Name + ":" + c.CustomFieldID);
            }


            TicketTypes ticketTypes = new TicketTypes(fields.LoginUser);

            ticketTypes.LoadAllPositions(TSAuthentication.OrganizationID);

            foreach (ReportTableField field in fields)
            {
                fieldItems.Add(new AutoFieldItem(field));
            }

            List <AutoFieldItem> customFieldsItems = new List <AutoFieldItem>();

            foreach (CustomField custom in customs)
            {
                TicketType ticketType = ticketTypes.FindByTicketTypeID(custom.AuxID);
                if (ticketType == null)
                {
                    fieldItems.Add(new AutoFieldItem(custom));
                    customFieldsItems.Add(new AutoFieldItem(custom));
                }
                else
                {
                    fieldItems.Add(new AutoFieldItem(custom, string.Format("{0} ({1})", custom.Name, ticketType.Name)));
                    customFieldsItems.Add(new AutoFieldItem(custom, string.Format("{0} ({1})", custom.Name, ticketType.Name)));
                }
            }
            result.CustomFields = customFieldsItems.ToArray();

            ReportTableField actionsViewDescription = ReportTableFields.GetReportTableField(fields.LoginUser, 6);

            actionsViewDescription.Alias = "Action Text";
            fieldItems.Add(new AutoFieldItem(actionsViewDescription));

            ReportTableField actionsViewName = ReportTableFields.GetReportTableField(fields.LoginUser, 5);

            fieldItems.Add(new AutoFieldItem(actionsViewName));

            ReportTableField actionsViewType = ReportTableFields.GetReportTableField(fields.LoginUser, 18);

            fieldItems.Add(new AutoFieldItem(actionsViewType));

            AutoFieldItem afiDayOfWeekCreated = new AutoFieldItem();

            afiDayOfWeekCreated.Alias         = "Day of Week Created";
            afiDayOfWeekCreated.DataType      = "list";
            afiDayOfWeekCreated.FieldID       = 101001;
            afiDayOfWeekCreated.FieldName     = "Day of Week Created";
            afiDayOfWeekCreated.IsCustom      = false;
            afiDayOfWeekCreated.IsVisible     = true;
            afiDayOfWeekCreated.ListValues    = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
            afiDayOfWeekCreated.LookupTableID = null;
            afiDayOfWeekCreated.Size          = 0;
            afiDayOfWeekCreated.Description   = "";
            afiDayOfWeekCreated.TableID       = -2;
            afiDayOfWeekCreated.RefType       = ReferenceType.Tickets;
            afiDayOfWeekCreated.AuxID         = null;
            afiDayOfWeekCreated.OtherTrigger  = "ticketsview.dayofweekcreated";
            fieldItems.Add(afiDayOfWeekCreated);

            AutoFieldItem afiHourOfDayCreated = new AutoFieldItem();

            afiHourOfDayCreated.Alias         = "Hour of Day Created";
            afiHourOfDayCreated.DataType      = "text";
            afiHourOfDayCreated.FieldID       = 101002;
            afiHourOfDayCreated.FieldName     = "Hour of Day Created";
            afiHourOfDayCreated.IsCustom      = false;
            afiHourOfDayCreated.IsVisible     = true;
            afiHourOfDayCreated.ListValues    = null;
            afiHourOfDayCreated.LookupTableID = null;
            afiHourOfDayCreated.Size          = 0;
            afiHourOfDayCreated.Description   = "";
            afiHourOfDayCreated.TableID       = -2;
            afiHourOfDayCreated.RefType       = ReferenceType.Tickets;
            afiHourOfDayCreated.AuxID         = null;
            afiHourOfDayCreated.OtherTrigger  = "ticketsview.hourofdaycreated";
            fieldItems.Add(afiHourOfDayCreated);

            AutoFieldItem afiMinSinceLastAction = new AutoFieldItem();

            afiMinSinceLastAction.Alias         = "Minutes Since last Action Added";
            afiMinSinceLastAction.DataType      = "text";
            afiMinSinceLastAction.FieldID       = 101003;
            afiMinSinceLastAction.FieldName     = "Minutes Since last Action Added";
            afiMinSinceLastAction.IsCustom      = false;
            afiMinSinceLastAction.IsVisible     = true;
            afiMinSinceLastAction.ListValues    = null;
            afiMinSinceLastAction.LookupTableID = null;
            afiMinSinceLastAction.Size          = 0;
            afiMinSinceLastAction.Description   = "";
            afiMinSinceLastAction.TableID       = -2;
            afiMinSinceLastAction.RefType       = ReferenceType.Tickets;
            afiMinSinceLastAction.AuxID         = null;
            afiMinSinceLastAction.OtherTrigger  = "ticketsview.minutessincelastactionadded";
            fieldItems.Add(afiMinSinceLastAction);

            AutoFieldItem afiHoursSinceAction = new AutoFieldItem();

            afiHoursSinceAction.Alias         = "Hours Since Last Action Added";
            afiHoursSinceAction.DataType      = "text";
            afiHoursSinceAction.FieldID       = 101004;
            afiHoursSinceAction.FieldName     = "Hours Since Last Action Added";
            afiHoursSinceAction.IsCustom      = false;
            afiHoursSinceAction.IsVisible     = true;
            afiHoursSinceAction.ListValues    = null;
            afiHoursSinceAction.LookupTableID = null;
            afiHoursSinceAction.Size          = 0;
            afiHoursSinceAction.Description   = "";
            afiHoursSinceAction.TableID       = -2;
            afiHoursSinceAction.RefType       = ReferenceType.Tickets;
            afiHoursSinceAction.AuxID         = null;
            afiHoursSinceAction.OtherTrigger  = "ticketsview.hourssincelastactionadded";
            fieldItems.Add(afiHoursSinceAction);

            AutoFieldItem afiCurrentDayOfWeek = new AutoFieldItem();

            afiCurrentDayOfWeek.Alias         = "Current Day of Week";
            afiCurrentDayOfWeek.DataType      = "list";
            afiCurrentDayOfWeek.FieldID       = 101005;
            afiCurrentDayOfWeek.FieldName     = "Current Day of Week";
            afiCurrentDayOfWeek.IsCustom      = false;
            afiCurrentDayOfWeek.IsVisible     = true;
            afiCurrentDayOfWeek.ListValues    = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
            afiCurrentDayOfWeek.LookupTableID = null;
            afiCurrentDayOfWeek.Size          = 0;
            afiCurrentDayOfWeek.Description   = "";
            afiCurrentDayOfWeek.TableID       = -2;
            afiCurrentDayOfWeek.RefType       = ReferenceType.Tickets;
            afiCurrentDayOfWeek.AuxID         = null;
            afiCurrentDayOfWeek.OtherTrigger  = "ticketsview.currentdayofweek";
            fieldItems.Add(afiCurrentDayOfWeek);

            AutoFieldItem afiCurrentHourOfDay = new AutoFieldItem();

            afiCurrentHourOfDay.Alias         = "Current Hour of Day";
            afiCurrentHourOfDay.DataType      = "text";
            afiCurrentHourOfDay.FieldID       = 101006;
            afiCurrentHourOfDay.FieldName     = "Current Hour of Day";
            afiCurrentHourOfDay.IsCustom      = false;
            afiCurrentHourOfDay.IsVisible     = true;
            afiCurrentHourOfDay.ListValues    = null;
            afiCurrentHourOfDay.LookupTableID = null;
            afiCurrentHourOfDay.Size          = 0;
            afiCurrentHourOfDay.Description   = "";
            afiCurrentHourOfDay.TableID       = -2;
            afiCurrentHourOfDay.RefType       = ReferenceType.Tickets;
            afiCurrentHourOfDay.AuxID         = null;
            afiCurrentHourOfDay.OtherTrigger  = "ticketsview.currenthourofday";
            fieldItems.Add(afiCurrentHourOfDay);

            AutoFieldItem afiAssignedUserIsAvailable = new AutoFieldItem();

            afiAssignedUserIsAvailable.Alias         = "Assigned User Is Available";
            afiAssignedUserIsAvailable.DataType      = "bit";
            afiAssignedUserIsAvailable.FieldID       = 101007;
            afiAssignedUserIsAvailable.FieldName     = "Assigned User Is Available";
            afiAssignedUserIsAvailable.IsCustom      = false;
            afiAssignedUserIsAvailable.IsVisible     = true;
            afiAssignedUserIsAvailable.ListValues    = null;
            afiAssignedUserIsAvailable.LookupTableID = null;
            afiAssignedUserIsAvailable.Size          = 0;
            afiAssignedUserIsAvailable.Description   = "";
            afiAssignedUserIsAvailable.TableID       = -2;
            afiAssignedUserIsAvailable.RefType       = ReferenceType.Tickets;
            afiAssignedUserIsAvailable.AuxID         = null;
            afiAssignedUserIsAvailable.OtherTrigger  = "ticketsview.assigneduseravailable";
            fieldItems.Add(afiAssignedUserIsAvailable);

            AutoFieldItem afiAssignedUserIsBusy = new AutoFieldItem();

            afiAssignedUserIsBusy.Alias         = "Assigned User Is Busy";
            afiAssignedUserIsBusy.DataType      = "bit";
            afiAssignedUserIsBusy.FieldID       = 101008;
            afiAssignedUserIsBusy.FieldName     = "Assigned User Is Busy";
            afiAssignedUserIsBusy.IsCustom      = false;
            afiAssignedUserIsBusy.IsVisible     = true;
            afiAssignedUserIsBusy.ListValues    = null;
            afiAssignedUserIsBusy.LookupTableID = null;
            afiAssignedUserIsBusy.Size          = 0;
            afiAssignedUserIsBusy.Description   = "";
            afiAssignedUserIsBusy.TableID       = -2;
            afiAssignedUserIsBusy.RefType       = ReferenceType.Tickets;
            afiAssignedUserIsBusy.AuxID         = null;
            afiAssignedUserIsBusy.OtherTrigger  = "ticketsview.assignedusernotavailable";
            fieldItems.Add(afiAssignedUserIsBusy);

            AutoFieldItem afiAgentRatings = new AutoFieldItem();

            afiAgentRatings.Alias         = "Agent Rating";
            afiAgentRatings.DataType      = "list";
            afiAgentRatings.FieldID       = 101009;
            afiAgentRatings.FieldName     = "AgentRating";
            afiAgentRatings.IsCustom      = false;
            afiAgentRatings.IsVisible     = true;
            afiAgentRatings.ListValues    = new string[] { "Positive", "Negative", "Neutral" };
            afiAgentRatings.LookupTableID = null;
            afiAgentRatings.Size          = 0;
            afiAgentRatings.Description   = "";
            afiAgentRatings.TableID       = -2;
            afiAgentRatings.RefType       = ReferenceType.Tickets;
            afiAgentRatings.AuxID         = null;
            afiAgentRatings.OtherTrigger  = "ticketsview.AgentRating";
            fieldItems.Add(afiAgentRatings);

            AutoFieldItem afiCDIValue = new AutoFieldItem();

            afiCDIValue.Alias         = "Customer CDI Value";
            afiCDIValue.DataType      = "text";
            afiCDIValue.FieldID       = 101010;
            afiCDIValue.FieldName     = "Customer CDI Value";
            afiCDIValue.IsCustom      = false;
            afiCDIValue.IsVisible     = true;
            afiCDIValue.ListValues    = null;
            afiCDIValue.LookupTableID = null;
            afiCDIValue.Size          = 0;
            afiCDIValue.Description   = "";
            afiCDIValue.TableID       = -2;
            afiCDIValue.RefType       = ReferenceType.Tickets;
            afiCDIValue.AuxID         = null;
            afiCDIValue.OtherTrigger  = "organizations.cdivalue";
            fieldItems.Add(afiCDIValue);

            AutoFieldItem afiCDITrend = new AutoFieldItem();

            afiCDITrend.Alias         = "Customer CDI Trend";
            afiCDITrend.DataType      = "text";
            afiCDITrend.FieldID       = 101011;
            afiCDITrend.FieldName     = "Customer CDI Trend";
            afiCDITrend.IsCustom      = false;
            afiCDITrend.IsVisible     = true;
            afiCDITrend.ListValues    = new string[] { "1", "0", "-1" };;
            afiCDITrend.LookupTableID = null;
            afiCDITrend.Size          = 0;
            afiCDITrend.Description   = "";
            afiCDITrend.TableID       = -2;
            afiCDITrend.RefType       = ReferenceType.Tickets;
            afiCDITrend.AuxID         = null;
            afiCDITrend.OtherTrigger  = "organizations.cditrend";
            fieldItems.Add(afiCDITrend);

            AutoFieldItem afiServiceLevelName = new AutoFieldItem();

            afiServiceLevelName.Alias         = "Service Level Name";
            afiServiceLevelName.DataType      = "text";
            afiServiceLevelName.FieldID       = 101012;
            afiServiceLevelName.FieldName     = "Service Level Name";
            afiServiceLevelName.IsCustom      = false;
            afiServiceLevelName.IsVisible     = true;
            afiServiceLevelName.ListValues    = null;
            afiServiceLevelName.LookupTableID = null;
            afiServiceLevelName.Size          = 0;
            afiServiceLevelName.Description   = "";
            afiServiceLevelName.TableID       = -2;
            afiServiceLevelName.RefType       = ReferenceType.Tickets;
            afiServiceLevelName.AuxID         = null;
            afiServiceLevelName.OtherTrigger  = "organizations.SLAName";
            fieldItems.Add(afiServiceLevelName);

            AutoFieldItem afiServiceExpirationDate = new AutoFieldItem();

            afiServiceExpirationDate.Alias         = "Service Expiration Date";
            afiServiceExpirationDate.DataType      = "datetime";
            afiServiceExpirationDate.FieldID       = 101013;
            afiServiceExpirationDate.FieldName     = "Service Expiration Date";
            afiServiceExpirationDate.IsCustom      = false;
            afiServiceExpirationDate.IsVisible     = true;
            afiServiceExpirationDate.ListValues    = null;
            afiServiceExpirationDate.LookupTableID = null;
            afiServiceExpirationDate.Size          = 0;
            afiServiceExpirationDate.Description   = "";
            afiServiceExpirationDate.TableID       = -2;
            afiServiceExpirationDate.RefType       = ReferenceType.Tickets;
            afiServiceExpirationDate.AuxID         = null;
            afiServiceExpirationDate.OtherTrigger  = "organizations.serviceexpirationdate";
            fieldItems.Add(afiServiceExpirationDate);

            AutoFieldItem afiCustomerIsActive = new AutoFieldItem();

            afiCustomerIsActive.Alias         = "Customer Is Active";
            afiCustomerIsActive.DataType      = "bit";
            afiCustomerIsActive.FieldID       = 101014;
            afiCustomerIsActive.FieldName     = "Customer Is Active";
            afiCustomerIsActive.IsCustom      = false;
            afiCustomerIsActive.IsVisible     = true;
            afiCustomerIsActive.ListValues    = null;
            afiCustomerIsActive.LookupTableID = null;
            afiCustomerIsActive.Size          = 0;
            afiCustomerIsActive.Description   = "";
            afiCustomerIsActive.TableID       = -2;
            afiCustomerIsActive.RefType       = ReferenceType.Tickets;
            afiCustomerIsActive.AuxID         = null;
            afiCustomerIsActive.OtherTrigger  = "organizations.active";
            fieldItems.Add(afiCustomerIsActive);

            AutoFieldItem afiCustomerCustomValue = new AutoFieldItem();

            afiCustomerCustomValue.Alias         = "Customer Custom Value";
            afiCustomerCustomValue.DataType      = "text";
            afiCustomerCustomValue.FieldID       = -999;
            afiCustomerCustomValue.FieldName     = "Customer Custom Value";
            afiCustomerCustomValue.IsCustom      = false;
            afiCustomerCustomValue.IsVisible     = true;
            afiCustomerCustomValue.ListValues    = orgCustomFields.ToArray();
            afiCustomerCustomValue.LookupTableID = null;
            afiCustomerCustomValue.Size          = 0;
            afiCustomerCustomValue.Description   = "";
            afiCustomerCustomValue.TableID       = -2;
            afiCustomerCustomValue.RefType       = ReferenceType.Tickets;
            afiCustomerCustomValue.AuxID         = null;
            afiCustomerCustomValue.OtherTrigger  = "organizations.customvalue";
            fieldItems.Add(afiCustomerCustomValue);

            AutoFieldItem afiCustomerServiceExpired = new AutoFieldItem();

            afiCustomerServiceExpired.Alias         = "Customer Service Expired";
            afiCustomerServiceExpired.DataType      = "bit";
            afiCustomerServiceExpired.FieldID       = 101015;
            afiCustomerServiceExpired.FieldName     = "Customer Service Expired";
            afiCustomerServiceExpired.IsCustom      = false;
            afiCustomerServiceExpired.IsVisible     = true;
            afiCustomerServiceExpired.ListValues    = null;
            afiCustomerServiceExpired.LookupTableID = null;
            afiCustomerServiceExpired.Size          = 0;
            afiCustomerServiceExpired.Description   = "";
            afiCustomerServiceExpired.TableID       = -2;
            afiCustomerServiceExpired.RefType       = ReferenceType.Tickets;
            afiCustomerServiceExpired.AuxID         = null;
            afiCustomerServiceExpired.OtherTrigger  = "organizations.serviceexpired";
            fieldItems.Add(afiCustomerServiceExpired);

            result.Fields = fieldItems.ToArray();

            Users users = new Users(UserSession.LoginUser);

            users.LoadByOrganizationID(UserSession.LoginUser.OrganizationID, true);
            List <AutocompleteItem> userItems = new List <AutocompleteItem>();

            foreach (User user in users)
            {
                userItems.Add(new AutocompleteItem(user.DisplayName, user.UserID.ToString()));
            }
            result.Users = userItems.ToArray();

            Groups groups = new Groups(UserSession.LoginUser);

            groups.LoadByOrganizationID(UserSession.LoginUser.OrganizationID);
            List <AutocompleteItem> groupItems = new List <AutocompleteItem>();

            foreach (Group group in groups)
            {
                groupItems.Add(new AutocompleteItem(group.Name, group.GroupID.ToString()));
            }
            result.Groups = groupItems.ToArray();

            TicketSeverities severities = new TicketSeverities(UserSession.LoginUser);

            severities.LoadByOrganizationID(UserSession.LoginUser.OrganizationID);
            List <AutocompleteItem> severityItems = new List <AutocompleteItem>();

            foreach (TicketSeverity severity in severities)
            {
                severityItems.Add(new AutocompleteItem(severity.Name, severity.TicketSeverityID.ToString()));
            }
            result.Severities = severityItems.ToArray();

            List <AutocompleteItem> statusItems = new List <AutocompleteItem>();

            List <AutocompleteItem> ticketTypeItems = new List <AutocompleteItem>();

            foreach (TicketType ticketType in ticketTypes)
            {
                ticketTypeItems.Add(new AutocompleteItem(ticketType.Name, ticketType.TicketTypeID.ToString()));


                TicketStatuses statuses = new TicketStatuses(UserSession.LoginUser);
                statuses.LoadAllPositions(ticketType.TicketTypeID);

                foreach (TicketStatus status in statuses)
                {
                    statusItems.Add(new AutocompleteItem(ticketType.Name + " - " + status.Name, status.TicketStatusID.ToString()));
                }
            }
            result.Statuses    = statusItems.ToArray();
            result.TicketTypes = ticketTypeItems.ToArray();
            return(result);
        }
    public static RadComboBoxItemData[] GetReplaceTypeComboData(int id, SelectedType type, int ticketTypeID)
    {
        //IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;
        List <RadComboBoxItemData> list = new List <RadComboBoxItemData>();

        /*string[] s = context["FilterString"].ToString().Split(',');
         * SelectedType type = (SelectedType)int.Parse(s[0]);
         * int ticketTypeID = int.Parse(s[1]);
         * int id = int.Parse(s[2]);*/

        BaseCollection collection  = null;
        string         nameColName = "Name";
        string         idColName   = "ID";

        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionTypes actionTypes = new ActionTypes(UserSession.LoginUser);
            actionTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = actionTypes;
            idColName  = "ActionTypeID";
            break;

        case SelectedType.PhoneTypes:
            PhoneTypes phoneTypes = new PhoneTypes(UserSession.LoginUser);
            phoneTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = phoneTypes;
            idColName  = "PhoneTypeID";
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(UserSession.LoginUser);
            productVersionStatuses.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = productVersionStatuses;
            idColName  = "ProductVersionStatusID";
            break;

        case SelectedType.TicketSeverities:
            TicketSeverities ticketSeverities = new TicketSeverities(UserSession.LoginUser);
            ticketSeverities.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = ticketSeverities;
            idColName  = "TicketSeverityID";
            break;

        case SelectedType.TicketStatuses:
            TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
            TicketType     ticketType     = TicketTypes.GetTicketType(UserSession.LoginUser, ticketTypeID);
            if (ticketType.OrganizationID == UserSession.LoginUser.OrganizationID)
            {
                ticketStatuses.LoadAllPositions(ticketTypeID);
                collection = ticketStatuses;
                idColName  = "TicketStatusID";
            }
            break;

        case SelectedType.TicketTypes:
            TicketTypes ticketTypes = new TicketTypes(UserSession.LoginUser);
            ticketTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            collection = ticketTypes;
            idColName  = "TicketTypeID";
            break;

        case SelectedType.ActivityTypes:
            ActivityTypes activityTypes = new ActivityTypes(UserSession.LoginUser);
            activityTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            //Load base items
            //Get default activity types
            foreach (ActivityTypeEnum activity in Enum.GetValues(typeof(ActivityTypeEnum)))
            {
                var value = Enum.Parse(typeof(ActivityTypeEnum), activity.ToString());
                //results.Add(new ActivityTypesDropDown() { Name = activity.ToString(), Value = (int)value });
                RadComboBoxItemData itemData = new RadComboBoxItemData();
                itemData.Text  = activity.ToString();
                itemData.Value = ((int)value).ToString();
                list.Add(itemData);
            }

            collection = activityTypes;
            idColName  = "ActivityTypeID";
            break;

        default:
            break;
        }

        foreach (DataRow row in collection.Table.Rows)
        {
            int i = (int)row[idColName];
            if (id != i)
            {
                RadComboBoxItemData itemData = new RadComboBoxItemData();
                itemData.Text  = row[nameColName].ToString();
                itemData.Value = i.ToString();
                list.Add(itemData);
            }
        }

        if (list.Count < 1)
        {
            RadComboBoxItemData noData = new RadComboBoxItemData();
            noData.Text  = "[No types to display.]";
            noData.Value = "-1";
            list.Add(noData);
        }

        return(list.ToArray());
    }
    public static string GetTypesHtml(SelectedType type, string arg)
    {
        Organization organization = Organizations.GetOrganization(UserSession.LoginUser, UserSession.LoginUser.OrganizationID);
        DataTable    table        = new DataTable();

        table.Columns.Add("ID");
        table.Columns.Add("Name");
        table.Columns.Add("Description");
        string result = "";

        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionTypes actionTypes = new ActionTypes(UserSession.LoginUser);
            actionTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            table.Columns.Add("Is Timed");
            foreach (ActionType actionType in actionTypes)
            {
                table.Rows.Add(new string[] { actionType.ActionTypeID.ToString(), actionType.Name, actionType.Description, actionType.IsTimed.ToString() });
            }
            break;

        case SelectedType.PhoneTypes:
            PhoneTypes phoneTypes = new PhoneTypes(UserSession.LoginUser);
            phoneTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            foreach (PhoneType phoneType in phoneTypes)
            {
                table.Rows.Add(new string[] { phoneType.PhoneTypeID.ToString(), phoneType.Name, phoneType.Description });
            }
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(UserSession.LoginUser);
            productVersionStatuses.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            table.Columns.Add("Is Shipping");
            table.Columns.Add("Is Discontinued");
            foreach (ProductVersionStatus productVersionStatus in productVersionStatuses)
            {
                table.Rows.Add(new string[] { productVersionStatus.ProductVersionStatusID.ToString(), productVersionStatus.Name, productVersionStatus.Description, productVersionStatus.IsShipping.ToString(), productVersionStatus.IsDiscontinued.ToString() });
            }
            break;

        case SelectedType.TicketSeverities:
            table.Columns.Add("Visible on Portal");
            TicketSeverities ticketSeverities = new TicketSeverities(UserSession.LoginUser);
            ticketSeverities.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            foreach (TicketSeverity ticketSeverity in ticketSeverities)
            {
                table.Rows.Add(new string[] { ticketSeverity.TicketSeverityID.ToString(), ticketSeverity.Name, ticketSeverity.Description, ticketSeverity.VisibleOnPortal.ToString() });
            }
            break;

        case SelectedType.TicketStatuses:
            TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
            ticketStatuses.LoadAllPositions(int.Parse(arg));

            table.Columns.Add("Is Closed");
            table.Columns.Add("Closed Email");
            table.Columns.Add("Email Response");
            table.Columns.Add("Pause SLA");

            foreach (TicketStatus ticketStatus in ticketStatuses)
            {
                table.Rows.Add(new string[] { ticketStatus.TicketStatusID.ToString(), ticketStatus.Name, ticketStatus.Description, ticketStatus.IsClosed.ToString(), ticketStatus.IsClosedEmail.ToString(), ticketStatus.IsEmailResponse.ToString(), ticketStatus.PauseSLA.ToString() });
            }
            break;

        case SelectedType.TicketTypes:
            table.Columns.Add("Icon");
            table.Columns.Add("Visible on Portal");
            string icon = "<img src=\"../{0}\" />";
            if (organization.UseProductFamilies)
            {
                TicketTypesView ticketTypes = new TicketTypesView(UserSession.LoginUser);
                ticketTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
                table.Columns.Add("Product Line");
                table.Columns.Add("Active");
                foreach (TicketTypesViewItem ticketType in ticketTypes)
                {
                    table.Rows.Add(new string[] { ticketType.TicketTypeID.ToString(), ticketType.Name, ticketType.Description, string.Format(icon, ticketType.IconUrl), ticketType.IsVisibleOnPortal.ToString(), ticketType.ProductFamilyName });
                }
            }
            else
            {
                TicketTypes ticketTypes = new TicketTypes(UserSession.LoginUser);
                ticketTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
                table.Columns.Add("Active");
                foreach (TicketType ticketType in ticketTypes)
                {
                    table.Rows.Add(new string[] { ticketType.TicketTypeID.ToString(), ticketType.Name, ticketType.Description, string.Format(icon, ticketType.IconUrl), ticketType.IsVisibleOnPortal.ToString() });
                }
            }
            break;

        case SelectedType.ActivityTypes:
            ActivityTypes activityTypes = new ActivityTypes(UserSession.LoginUser);
            activityTypes.LoadAllPositions(UserSession.LoginUser.OrganizationID);
            foreach (ActivityType activityType in activityTypes)
            {
                table.Rows.Add(new string[] { activityType.ActivityTypeID.ToString(), activityType.Name, activityType.Description });
            }
            break;

        default:
            break;
        }

        return(BuildTable(table));
    }
    public static string UpdateType(SelectedType type,
                                    string arg,
                                    int?id,
                                    string name,
                                    string description,
                                    bool isTimed,
                                    bool isClosed,
                                    bool isClosedEmail,
                                    bool isEmailResponse,
                                    bool pauseSla,
                                    bool isShipping,
                                    bool isDiscontinued,
                                    string productFamilyID,
                                    string iconUrl,
                                    bool isVisibleOnPortal,
                                    bool isActive,
                                    bool ExcludeFromCDI)
    {
        if (!UserSession.CurrentUser.IsSystemAdmin)
        {
            return("");
        }
        switch (type)
        {
        case SelectedType.ActionTypes:
            ActionType actionType = id == null ? (new ActionTypes(UserSession.LoginUser)).AddNewActionType() : ActionTypes.GetActionType(UserSession.LoginUser, (int)id);
            actionType.IsTimed     = isTimed;
            actionType.Name        = name;
            actionType.Description = description;
            if (id == null)
            {
                actionType.Position = actionType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                actionType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            actionType.Collection.Save();
            actionType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.PhoneTypes:
            PhoneType phoneType = id == null ? (new PhoneTypes(UserSession.LoginUser)).AddNewPhoneType() : PhoneTypes.GetPhoneType(UserSession.LoginUser, (int)id);
            phoneType.Name        = name;
            phoneType.Description = description;
            if (id == null)
            {
                phoneType.Position = phoneType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                phoneType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            phoneType.Collection.Save();
            phoneType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.ProductVersionStatuses:
            ProductVersionStatus productVersionStatus = id == null ? (new ProductVersionStatuses(UserSession.LoginUser)).AddNewProductVersionStatus() : ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, (int)id);
            productVersionStatus.IsDiscontinued = isDiscontinued;
            productVersionStatus.IsShipping     = isShipping;
            productVersionStatus.Name           = name;
            productVersionStatus.Description    = description;
            if (id == null)
            {
                productVersionStatus.Position = productVersionStatus.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                productVersionStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            productVersionStatus.Collection.Save();
            productVersionStatus.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketSeverities:
            TicketSeverity ticketSeverity = id == null ? (new TicketSeverities(UserSession.LoginUser)).AddNewTicketSeverity() : TicketSeverities.GetTicketSeverity(UserSession.LoginUser, (int)id);
            ticketSeverity.Name        = name;
            ticketSeverity.Description = description;
            if (id == null)
            {
                ticketSeverity.Position = ticketSeverity.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                ticketSeverity.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            ticketSeverity.VisibleOnPortal = isVisibleOnPortal;
            ticketSeverity.Collection.Save();
            ticketSeverity.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketStatuses:
            if (isEmailResponse == true)
            {
                TicketStatuses statuses = new TicketStatuses(UserSession.LoginUser);
                statuses.LoadByTicketTypeID(int.Parse(arg));
                foreach (TicketStatus status in statuses)
                {
                    status.IsEmailResponse = false;
                }
                statuses.Save();
            }

            TicketStatus ticketStatus = id == null ? (new TicketStatuses(UserSession.LoginUser)).AddNewTicketStatus() : TicketStatuses.GetTicketStatus(UserSession.LoginUser, (int)id);
            ticketStatus.TicketTypeID    = int.Parse(arg);
            ticketStatus.IsClosed        = isClosed;
            ticketStatus.IsClosedEmail   = isClosedEmail;
            ticketStatus.IsEmailResponse = isEmailResponse;
            ticketStatus.PauseSLA        = pauseSla;
            ticketStatus.Name            = name;
            ticketStatus.Description     = description;
            if (id == null)
            {
                ticketStatus.Position = ticketStatus.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                ticketStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            ticketStatus.Collection.Save();
            ticketStatus.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketTypes:
            TicketType ticketType = id == null ? (new TicketTypes(UserSession.LoginUser)).AddNewTicketType() : TicketTypes.GetTicketType(UserSession.LoginUser, (int)id);
            ticketType.Name              = name;
            ticketType.Description       = description;
            ticketType.IconUrl           = iconUrl;
            ticketType.IsVisibleOnPortal = isVisibleOnPortal;
            ticketType.IsActive          = isActive;
            ticketType.ExcludeFromCDI    = ExcludeFromCDI;
            if (id == null)
            {
                ticketType.Position = ticketType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                ticketType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            if (productFamilyID == "-1")
            {
                ticketType.ProductFamilyID = null;
            }
            else
            {
                ticketType.ProductFamilyID = Convert.ToInt32(productFamilyID);
            }

            ticketType.Collection.Save();
            ticketType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            if (id == null)
            {
                try
                {
                    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
                    command.CommandText = "UPDATE Users SET MenuItems = MenuItems + ',mniTicketType_" + ticketType.TicketTypeID.ToString() + "' WHERE UserID IN (SELECT UserID WHERE OrganizationID = @OrganizationID)";
                    command.Parameters.AddWithValue("OrganizationID", UserSession.LoginUser.OrganizationID);
                    SqlExecutor.ExecuteNonQuery(UserSession.LoginUser, command);
                }
                catch (Exception ex)
                {
                    ExceptionLogs.LogException(UserSession.LoginUser, ex, "Ticket Type Creation - menu item");
                }

                TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
                ticketStatus                = ticketStatuses.AddNewTicketStatus();
                ticketStatus.Name           = "New";
                ticketStatus.Description    = "New";
                ticketStatus.Position       = 0;
                ticketStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
                ticketStatus.TicketTypeID   = ticketType.TicketTypeID;
                ticketStatus.IsClosed       = false;
                ticketStatus.IsClosedEmail  = false;

                ticketStatus                = ticketStatuses.AddNewTicketStatus();
                ticketStatus.Name           = "Closed";
                ticketStatus.Description    = "Closed";
                ticketStatus.Position       = 30;
                ticketStatus.OrganizationID = UserSession.LoginUser.OrganizationID;
                ticketStatus.TicketTypeID   = ticketType.TicketTypeID;
                ticketStatus.IsClosed       = true;
                ticketStatus.IsClosedEmail  = false;
                ticketStatus.Collection.Save();
                ticketStatus.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);


/*          TicketNextStatuses ticketNextStatuses = new TicketNextStatuses(UserSession.LoginUser);
 *        ticketNextStatuses.AddNextStatus(ticketStatuses[0], ticketStatuses[1], 0);
 *        ticketNextStatuses.AddNextStatus(ticketStatuses[1], ticketStatuses[0], 1);
 *        ticketNextStatuses.Save();*/
            }

            break;

        case SelectedType.ActivityTypes:
            ActivityType activityType = id == null ? (new ActivityTypes(UserSession.LoginUser)).AddNewActivityType() : ActivityTypes.GetActivityType(UserSession.LoginUser, (int)id);
            activityType.Name        = name;
            activityType.Description = description;
            if (id == null)
            {
                activityType.Position = activityType.Collection.GetMaxPosition(UserSession.LoginUser.OrganizationID) + 1;
            }
            if (id == null)
            {
                activityType.OrganizationID = UserSession.LoginUser.OrganizationID;
            }
            activityType.Collection.Save();
            activityType.Collection.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        default:
            break;
        }


        return(GetTypesHtml(type, arg));
    }
    public static string ReplaceType(SelectedType type, int oldID, int newID, string arg)
    {
        if (!UserSession.CurrentUser.IsSystemAdmin)
        {
            return("");
        }
        switch (type)
        {
        case SelectedType.ActionTypes:
            if (ActionTypes.GetActionType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (ActionTypes.GetActionType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Actions(UserSession.LoginUser)).ReplaceActionType(oldID, newID);
            ActionTypes actionTypes = new ActionTypes(UserSession.LoginUser);
            actionTypes.DeleteFromDB(oldID);
            actionTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.PhoneTypes:
            if (PhoneTypes.GetPhoneType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (PhoneTypes.GetPhoneType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new PhoneNumbers(UserSession.LoginUser)).ReplacePhoneType(oldID, newID);
            PhoneTypes phoneTypes = new PhoneTypes(UserSession.LoginUser);
            phoneTypes.DeleteFromDB(oldID);
            phoneTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.ProductVersionStatuses:
            if (ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (ProductVersionStatuses.GetProductVersionStatus(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new ProductVersions(UserSession.LoginUser)).ReplaceProductVersionStatus(oldID, newID);
            ProductVersionStatuses productVersionStatuses = new ProductVersionStatuses(UserSession.LoginUser);
            productVersionStatuses.DeleteFromDB(oldID);
            productVersionStatuses.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketSeverities:
            if (TicketSeverities.GetTicketSeverity(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (TicketSeverities.GetTicketSeverity(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Tickets(UserSession.LoginUser)).ReplaceTicketSeverity(oldID, newID);
            TicketSeverities ticketSeverities = new TicketSeverities(UserSession.LoginUser);
            ticketSeverities.DeleteFromDB(oldID);
            ticketSeverities.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        case SelectedType.TicketStatuses:
            TicketStatus oldStatus = TicketStatuses.GetTicketStatus(UserSession.LoginUser, oldID);
            if (oldStatus.OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (TicketStatuses.GetTicketStatus(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Tickets(UserSession.LoginUser)).ReplaceTicketStatus(oldID, newID);
            TicketStatuses ticketStatuses = new TicketStatuses(UserSession.LoginUser);
            ticketStatuses.DeleteFromDB(oldID);
            ticketStatuses.ValidatePositions(oldStatus.TicketTypeID);
            break;

        case SelectedType.TicketTypes:
            if (TicketTypes.GetTicketType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            if (TicketTypes.GetTicketType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            (new Tickets(UserSession.LoginUser)).ReplaceTicketType(oldID, newID);
            TicketTypes ticketTypes = new TicketTypes(UserSession.LoginUser);

            CustomFields customFields = new CustomFields(UserSession.LoginUser);
            customFields.LoadByTicketTypeID(UserSession.LoginUser.OrganizationID, oldID);

            ticketTypes.DeleteFromDB(oldID);
            ticketTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);

            int?crmLinkFieldId = null;

            foreach (CustomField customField in customFields)
            {
                try
                {
                    crmLinkFieldId = CRMLinkFields.FindIdByCustomFieldId(customField.CustomFieldID, UserSession.LoginUser);
                }
                catch (Exception ex)
                {
                    crmLinkFieldId = null;
                }

                if (crmLinkFieldId != null && crmLinkFieldId > 0)
                {
                    CRMLinkFields crmLinkFieldsDelete = new CRMLinkFields(UserSession.LoginUser);
                    crmLinkFieldsDelete.DeleteFromDB((int)crmLinkFieldId);
                }
            }

            break;

        case SelectedType.ActivityTypes:
            if (ActivityTypes.GetActivityType(UserSession.LoginUser, oldID).OrganizationID != UserSession.LoginUser.OrganizationID)
            {
                return("");
            }
            var types = Enum.GetValues(typeof(ActivityTypeEnum));
            if (newID > types.Length)
            {
                if (ActivityTypes.GetActivityType(UserSession.LoginUser, newID).OrganizationID != UserSession.LoginUser.OrganizationID)
                {
                    return("");
                }
            }
            (new Notes(UserSession.LoginUser)).ReplaceActivityType(oldID, newID);
            ActivityTypes activityTypes = new ActivityTypes(UserSession.LoginUser);
            activityTypes.DeleteFromDB(oldID);
            activityTypes.ValidatePositions(UserSession.LoginUser.OrganizationID);
            break;

        default:
            break;
        }
        return(GetTypesHtml(type, arg));
    }
Example #30
0
        private void ImportOrg(int orgID, LoginUser loginUser)
        {
            string existingImportID = GetImportID(orgID);

            if (!string.IsNullOrWhiteSpace(existingImportID))
            {
                MessageBox.Show("This company has already been imported");
                return;
            }

            try
            {
                _importID         = orgID.ToString() + "-" + Guid.NewGuid().ToString();
                _logs             = new Logs(orgID.ToString() + " - Org.txt");
                _usersAndContacts = new Users(loginUser);
                _usersAndContacts.LoadContactsAndUsers(orgID, false);

                _badProducts           = new Products(GetCorrupteLoginUser());
                _badProductVersions    = new ProductVersions(GetCorrupteLoginUser());
                _badGroups             = new Groups(GetCorrupteLoginUser());
                _badUsers              = new Users(GetCorrupteLoginUser());
                _badTicketTypes        = new TicketTypes(GetCorrupteLoginUser());
                _badTicketStatuses     = new TicketStatuses(GetCorrupteLoginUser());
                _badTicketSeverities   = new TicketSeverities(GetCorrupteLoginUser());
                _badTicketKBCategories = new KnowledgeBaseCategories(GetCorrupteLoginUser());
                _badProducts.LoadByOrganizationID(orgID);
                _badProductVersions.LoadByParentOrganizationID(orgID);
                _badGroups.LoadByOrganizationID(orgID);
                _badUsers.LoadByOrganizationID(orgID, false);
                _badTicketTypes.LoadByOrganizationID(orgID);
                _badTicketStatuses.LoadByOrganizationID(orgID);
                _badTicketSeverities.LoadByOrganizationID(orgID);
                _badTicketKBCategories.LoadCategories(orgID);

                _goodProducts           = new Products(loginUser);
                _goodProductVersions    = new ProductVersions(loginUser);
                _goodGroups             = new Groups(loginUser);
                _goodUsers              = new Users(loginUser);
                _goodTicketTypes        = new TicketTypes(loginUser);
                _goodTicketStatuses     = new TicketStatuses(loginUser);
                _goodTicketSeverities   = new TicketSeverities(loginUser);
                _goodTicketKBCategories = new KnowledgeBaseCategories(loginUser);

                _goodProducts.LoadByOrganizationID(orgID);
                _goodProductVersions.LoadByParentOrganizationID(orgID);
                _goodGroups.LoadByOrganizationID(orgID);
                _goodUsers.LoadByOrganizationID(orgID, false);
                _goodTicketTypes.LoadByOrganizationID(orgID);
                _goodTicketStatuses.LoadByOrganizationID(orgID);
                _goodTicketSeverities.LoadByOrganizationID(orgID);
                _goodTicketKBCategories.LoadCategories(orgID);


                _exceptionOcurred = false;
                if (cbCompanies.Checked)
                {
                    RecoverCompanies(orgID, loginUser);
                }
                //RecoverContacts(orgID);
                if (cbProducts.Checked)
                {
                    RecoverProducts(orgID, loginUser);
                }
                // RecoverAssets(orgID);
                if (cbOldActions.Checked)
                {
                    RecoverActionsFromOldTickets(orgID, loginUser);
                }
                if (cbTickets.Checked)
                {
                    RecoverTickets(orgID, loginUser);
                }

                if (_exceptionOcurred)
                {
                    SaveOrgResults(orgID, "Finished with exceptions", _importID);
                }
                else
                {
                    SaveOrgResults(orgID, "Success", _importID);
                }
                SqlExecutor.ExecuteNonQuery(loginUser, "update organizations set LastIndexRebuilt='1/1/2000' where OrganizationID=" + orgID.ToString());
                MessageBox.Show("Import Complete");
            }
            catch (Exception ex)
            {
                SaveOrgResults(orgID, "Failure: " + ex.Message, _importID);
                ExceptionLogs.LogException(GetCorrupteLoginUser(), ex, "recover");
            }
        }