/// <summary>
 /// Assigns the basic data.
 /// </summary>
 /// <param name="ticketPresenter">The ticket presenter.</param>
 private void AssignBasicData(TicketPresenter ticketPresenter)
 {
     ticketPresenter.AssignPriorityList(this.lookupService.RetrievePriorityListItem(SessionData.Instance.UserInfo.Developer.DeveloperID));
     ticketPresenter.AssignDeveloperList(this.lookupService.RetrieveDeveloperListItem(SessionData.Instance.UserInfo.Developer.DeveloperID));
     var clients = this.lookupService.RetrieveClients(null, false, SessionData.Instance.UserInfo.Developer.DeveloperID);
     ticketPresenter.AssignClientList(clients.Sort());
     ticketPresenter.AssignProjectsList(ticketPresenter.IncludeInactive ? this.lookupService.RetrieveTicketProjectListItem(null, null, null, false, SessionData.Instance.UserInfo.Developer.DeveloperID) : this.lookupService.RetrieveTicketProjectListItem(null, null, false, false, SessionData.Instance.UserInfo.Developer.DeveloperID));
     ticketPresenter.AssignStatusList(this.ticketService.ListTicketsStatus());
     ticketPresenter.AssignAlertList(this.lookupService.RetrieveTicketAlertList());
     ticketPresenter.AssignTypeList(this.lookupService.RetrieveTicketTypeList());
     ticketPresenter.AssignTagList(this.lookupService.RetrieveTagList());
 }
        /// <summary>
        /// Validates the added ticket details.
        /// </summary>
        /// <param name="presenter">The presenter.</param>
        /// <param name="isUpdateTicket">if set to <c>true</c> [is update ticket].</param>
        private static void ValidateAddedTicketDetails(TicketPresenter presenter, bool isUpdateTicket)
        {
            if (!string.IsNullOrWhiteSpace(presenter.PortalName))
            {
                if (!isUpdateTicket)
                {
                    if (string.IsNullOrWhiteSpace(presenter.TicketDescription))
                    {
                        presenter.ValidationErrors.Add(TicketDescription, Resources.TicketDescriptionErrorMessage);
                    }
                }

                if (presenter.SelectedDeveloper == null)
                {
                    presenter.ValidationErrors.Add(Developer, Resources.DeveloperNotSelectd);
                }

                if (presenter.DueDate != null)
                {
                    if (Convert.ToDateTime(presenter.DueDate).Date < DateTime.Now.Date)
                    {
                        presenter.ValidationErrors.Add(DueDate, Resources.DueDateErrorMessage);
                    }
                }
            }
        }
 /// <summary>
 /// Assigns the data.
 /// </summary>
 /// <param name="ticketPresenter">The ticket presenter.</param>
 private void AssignData(TicketPresenter ticketPresenter)
 {
     if (SessionData.Instance.UserInfo != null && SessionData.Instance.UserInfo.Developer != null)
     {
         this.AssignBasicData(ticketPresenter);
     }
 }
        public ActionResult ValidateDetails(TicketPresenter presenter, bool isUpdateTicket)
        {
            ModelState.Clear();
            if (presenter != null)
            {
                Validate(presenter, isUpdateTicket);
            }

            return new JsonResult { Data = presenter, MaxJsonLength = int.MaxValue };
        }
 private static void Validate(TicketPresenter presenter, bool isUpdateTicket)
 {
     if (presenter.PortalName != null && presenter.PortalName.Equals(Resources.TicketDetails))
     {
         if (string.IsNullOrWhiteSpace(presenter.Comment.Description))
         {
             presenter.ValidationErrors.Add(TicketComments, Resources.EmptyCommentsErrorMessage);
         }
     }
     else
     {
         ValidateAddedTicketDetails(presenter, isUpdateTicket);
     }
 }
        public ActionResult AddTicketComments(TicketPresenter ticketPresenter)
        {
            if (ticketPresenter != null && ticketPresenter.TicketDetails != null && ticketPresenter.TicketDetail.TicketId > 0 && SessionData.Instance.UserInfo != null && SessionData.Instance.UserInfo.Developer != null)
            {
                if (!string.IsNullOrEmpty(ticketPresenter.CommentAttachmentId))
                {
                    var attachmentIds = ticketPresenter.CommentAttachmentId.Split(',');
                    foreach (var attachmentId in attachmentIds)
                    {
                        var attachmentsids = attachmentId.Split('~');
                        var attachments = new FileAttachment { FileAttachmentId = Convert.ToInt32(attachmentsids[0]), FileName = attachmentsids[1] };
                        ticketPresenter.Comment.FileAttachments.Add(attachments);
                    }
                }

                ticketPresenter.Comment.DeveloperId = SessionData.Instance.UserInfo.Developer.DeveloperID;
                ticketPresenter.Comment.TicketId = ticketPresenter.TicketDetail.TicketId;
                ticketPresenter.Comment.DeveloperName = SessionData.Instance.UserInfo.FirstName + SessionData.Instance.UserInfo.LastName;
                this.ticketService.PostComment(ticketPresenter.Comment, SessionData.Instance.UserInfo.Developer.DeveloperID);

                var updatedTicketInfo = this.ticketService.RetrieveTicketDetails(ticketPresenter.Comment.TicketId.ToString(), SessionData.Instance.UserInfo.Developer.DeveloperID.ToString());

                if (updatedTicketInfo != null)
                {
                    ticketPresenter.AssignTicketComment(updatedTicketInfo.Comments);
                }

                return this.PartialView(TicketCommentsContainer, ticketPresenter);
            }

            return this.Json(string.Empty);
        }
        /// <summary>
        /// Saves the ticket.
        /// </summary>
        /// <param name="ticketPresenter">The ticket presenter.</param>
        /// <param name="isUpdateTicket">if set to <c>true</c> [is update ticket].</param>
        /// <returns>
        /// save details
        /// </returns>
        public ActionResult SaveTicket(TicketPresenter ticketPresenter, bool isUpdateTicket)
        {
            if (ticketPresenter != null)
            {
                if (!isUpdateTicket)
                {
                    ticketPresenter.TicketDetails.CommentDescription = ticketPresenter.TicketDescription;
                }

                if (ticketPresenter.DueDate == null)
                {
                    ticketPresenter.TicketDetails.DueDate = null;
                }
                else
                {
                    ticketPresenter.TicketDetails.DueDate = ticketPresenter.DueDate;
                }

                ticketPresenter.TicketDetails.AddedByDeveloperId = SessionData.Instance.UserInfo.Developer.DeveloperID;
                ticketPresenter.TicketDetails.StatusId = ticketPresenter.SelectedStatus;
                ticketPresenter.TicketDetails.Priority = ticketPresenter.SelectedPriority;

                string developerIds = Convert.ToString(ticketPresenter.SelectedDeveloper, CultureInfo.CurrentCulture);

                var ticketDeveloperArray = developerIds.Split(',');
                foreach (var ticketDeveloper in ticketDeveloperArray)
                {
                    ticketPresenter.TicketDetails.DeveloperIds.Add(ticketDeveloper);
                }

                var projectIds = Convert.ToString(ticketPresenter.SelectedProject, CultureInfo.CurrentCulture);

                if (projectIds != null)
                {
                    var ticketProjectArray = projectIds.Split(',');
                    foreach (var ticketProject in ticketProjectArray)
                    {
                        ticketPresenter.TicketDetails.ProjectIds.Add(ticketProject);
                    }
                }

                var clientIds = Convert.ToString(ticketPresenter.SelectedClient, CultureInfo.CurrentCulture);

                if (clientIds != null)
                {
                    var ticketClientArray = clientIds.Split(',');
                    foreach (var ticketClient in ticketClientArray)
                    {
                        ticketPresenter.TicketDetails.ClientIds.Add(ticketClient);
                    }
                }

                if (developerIds.Equals(DefaultDeveloperId))
                {
                    developerIds = null;
                }

                if (ticketPresenter.AttachmentIds != null)
                {
                    var attachmentIds = ticketPresenter.AttachmentIds.Split(',');
                    foreach (var attachmentId in attachmentIds)
                    {
                        var attachmentsids = attachmentId.Split('~');
                        var attachments = new FileAttachment { FileAttachmentId = Convert.ToInt32(attachmentsids[0]), FileName = attachmentsids[1] };
                        ticketPresenter.TicketDetails.FileAttachments.Add(attachments);
                    }
                }

                if (ticketPresenter.TagIds != null)
                {
                    var tagIdsArray = ticketPresenter.TagIds.Split(',');
                    foreach (var tag in tagIdsArray)
                    {
                        ticketPresenter.TicketDetails.Tags.Add(tag);
                    }
                }

                if (!isUpdateTicket)
                {
                    this.ticketService.Insert(SessionData.Instance.UserInfo.Developer.DeveloperID, ticketPresenter.TicketDetails);
                }

                if (ticketPresenter.TicketId != null)
                {
                    ticketPresenter.TicketDetails.TicketId = (int)ticketPresenter.TicketId;
                    this.ticketService.UpdateTicketDetail(SessionData.Instance.UserInfo.Developer.DeveloperID, ticketPresenter.TicketDetails);
                }

                return this.Json(ticketPresenter);
            }

            return this.Json(string.Empty);
        }
        /// <summary>
        /// Downloads the attachment.
        /// </summary>
        /// <param name="ticketPresenter">The ticket presenter.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="attachmentId">The attachment identifier.</param>
        /// <returns>
        /// return view
        /// </returns>
        public ActionResult DownloadAttachment(TicketPresenter ticketPresenter, string fileName, string attachmentId)
        {
            try
            {
                var actualFileName = fileName.Replace('>', '&').Replace('<', '#');
                var fileNameWithId = string.Concat(attachmentId, "_", actualFileName);
                var fileLocation = Path.Combine(ApplicationSettings.Instance.TicketMediaBaseUrl.ToString(), fileNameWithId);
                if (System.IO.File.Exists(fileLocation))
                {
                    var tempPath = Path.Combine(ApplicationSettings.Instance.TicketMediaBaseUrl.ToString(), "Temp");
                    if (!Directory.Exists(tempPath))
                    {
                        Directory.CreateDirectory(tempPath);
                    }
                    else
                    {
                        DirectoryInfo downloadedMessageInfo = new DirectoryInfo(Path.Combine(ApplicationSettings.Instance.TicketMediaBaseUrl.ToString(), "Temp"));
                        foreach (var file in downloadedMessageInfo.GetFiles())
                        {
                            file.Delete();
                        }
                    }

                    System.IO.File.Copy(fileLocation, Path.Combine(tempPath, actualFileName));
                    var path = Path.Combine(tempPath, actualFileName);
                    return this.File(path, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(path));
                }
            }
            catch (Exception ex)
            {
                var e = ex;
            }

            return this.Json(false);
        }
        /// <summary>
        /// Tickets the details.
        /// </summary>
        /// <param name="tabName">Name of the tab.</param>
        /// <param name="ticketId">The ticket identifier.</param>
        /// <param name="developerId">The developer identifier.</param>
        /// <returns>
        /// view of ticket details
        /// </returns>
        public ActionResult TicketDetails(string tabName, int ticketId, string developerId)
        {
            var ticketPresenter = new TicketPresenter { TicketId = ticketId };
            ticketPresenter.TicketId = ticketId;
            if (ticketId == 0)
            {
                return this.Redirect(Url.AccountAction());
            }

            if (!string.IsNullOrEmpty(developerId))
            {
                this.AddBreadcrumbItem(Resources.TeamMemberDashboard, this.RetrieveTeamMemberDashboardAddress(Url.TeamDashboardAction(), developerId));
                ticketPresenter.PortalName = Resources.TeamMemberDashboard;
                ticketPresenter.SelectedDeveloper = developerId;
            }

            this.AddBreadcrumbItem(Resources.TicketDetails, string.Empty);
            var ticketInfos = this.ticketService.RetrieveTicketDetails(ticketId.ToString(), SessionData.Instance.UserInfo.Developer.DeveloperID.ToString());
            this.AssignData(ticketPresenter);
            ticketPresenter.Offset = DefaultValue;
            if (!string.IsNullOrEmpty(ticketInfos.AssigneeName))
            {
                if (!string.IsNullOrEmpty(Convert.ToString(ticketId)))
                {
                    ticketPresenter.TicketDetail.TicketId = ticketId;
                    this.AddBreadcrumbItem(string.Format(CultureInfo.CurrentCulture, CommonUrlFormat, Resources.TeamMemberDashboard, tabName), this.RetrieveTeamMemberDashboardAddress(this.Url.TeamDashboardAction(), developerId));
                }

                ticketPresenter.AssignTicketDetail(ticketInfos);
                ticketPresenter.DueDate = ticketInfos.DueDate;
                ticketPresenter.AssignTicketComment(ticketInfos.Comments);
                ticketPresenter.SelectedPriority = ticketInfos.Priority;
                ticketPresenter.SelectedStatus = ticketInfos.StatusId;
                ticketPresenter.TagIds = ticketInfos.TicketTags;
            }
            else
            {
                return this.RedirectToAction("Index", "TeamDashboard");
            }

            return this.View(ticketPresenter);
        }
        /// <summary>
        /// Indexes this instance.
        /// </summary>
        /// <param name="developerId">The developer identifier.</param>
        /// <returns>
        /// view of ticket
        /// </returns>
        public ActionResult Index(string developerId)
        {
            TicketPresenter ticketPresenter = new TicketPresenter();
            developerId = SessionData.Instance.UserInfo.Developer.DeveloperID.ToString();
            if (!string.IsNullOrEmpty(developerId))
            {
                this.AddBreadcrumbItem(Resources.TeamMemberDashboard, this.RetrieveTeamMemberDashboardAddress(Url.TeamDashboardAction(), developerId));
                ticketPresenter.PortalName = Resources.TeamMemberDashboard;
                ticketPresenter.SelectedDeveloperid = developerId;
            }

            this.AddBreadcrumbItem(Resources.CreateTicket, string.Empty);
            this.AssignData(ticketPresenter);
            ticketPresenter.SelectedPriority = 2;
            ticketPresenter.DueDate = DateTime.Now.AddDays(1);
            return this.View(ticketPresenter);
        }