Ejemplo n.º 1
0
        public ReservationsViewModel()
        {
            _eventContext = ContextFactory.GetEventContext();
            _ticketContext = ContextFactory.GetTicketContext();
            IsLoggedIn = true;
            AppMessages.TicketAddedMessage.Register(this, OnTicketAdded);

            LoadData();

            _deleteCommand = new RelayCommand(OnDelete);
            _searchEventsCommand = new RelayCommand(OnSearchEvents);
            _editCommand = new RelayCommand(OnEdit);
        }
        public EditTicketReservationViewModel(Event selectedEvent)
        {
            _saveChangesCommand = new RelayCommand(OnSaveChanges);
            _generateSeatCommand = new RelayCommand(OnGenerateSeatNumber);
            _context = ContextFactory.GetTicketContext();
            _eventTicketContext = ContextFactory.GetEventTicketContext();
            _teamContext = ContextFactory.GetTeamContext();
            SelectedEvent = selectedEvent;

            MemberList = _teamContext.Members;
            TicketTypes = _context.TicketTypes;
            PaymentMethodsList = _context.PaymentMethods;

            WebContext.Current.Authentication.LoggedIn += (s, e) => UpdateForUsersRole();
            WebContext.Current.Authentication.LoggedOut += (s, e) => UpdateForUsersRole();
            UpdateForUsersRole();

            LoadData();
        }
Ejemplo n.º 3
0
        private void Copy(TicketPart source, ContentItemPermissionPart sourcePermissionPart, task destination, TicketContext context)
        {
            destination.name     = source.Record.Title.Length > 50 ? source.Record.Title.Substring(0, 50) : source.Record.Title;
            destination.date_due = source.Record.DueDate;

            // status
            if (source.Record.StatusRecord != null)
            {
                var status = context.StatusList.FirstOrDefault(c => c.Id == source.Record.StatusRecord.Id);
                if (status != null)
                {
                    destination.status = status.Name;
                }
            }

            // priority
            if (source.Record.PriorityRecord != null)
            {
                var priority = context.Priorities.FirstOrDefault(c => c.Id == source.Record.PriorityRecord.Id);
                if (priority != null)
                {
                    destination.priority = priority.Name;
                }
            }

            CommonPart commonPart = source.As <CommonPart>();

            if (commonPart != null && commonPart.ModifiedUtc.HasValue)
            {
                destination.date_modified = commonPart.ModifiedUtc;
            }

            destination.assigned_user_id = this.GetAssigneeUserExternalId(sourcePermissionPart);
            destination.created_by       = this.GetOwnerUserExternalId(commonPart);
        }
Ejemplo n.º 4
0
        private void CopyOrchardTicketsToSuiteCRM(TicketContext context, CopyOrchardProjectToSuiteViewModel.ProjectIdentifiers syncSettings)
        {
            if (syncSettings.OrchardCollaborationProjectId == null)
            {
                throw new ArgumentNullException("OrchardCollaborationProjectId must not be null");
            }

            if (string.IsNullOrEmpty(syncSettings.SuiteCRMId))
            {
                throw new ArgumentNullException("SuiteCRMId must not be null");
            }

            var orchardTickets = this.searchTicketService.SearchByDatabase(new PagerParametersWithSortFields()
            {
                PageSize = 0
            }, new PostedTicketSearchViewModel {
                ProjectId = syncSettings.OrchardCollaborationProjectId
            });
            List <project_task> suiteCRMTasks = new List <project_task>();

            if (!string.IsNullOrEmpty(syncSettings.SuiteCRMId))
            {
                suiteCRMTasks.AddRange(context.ProjectTaskUnitOfWork.GetProjectTasks(syncSettings.SuiteCRMId));
            }

            foreach (var ticket in orchardTickets)
            {
                var suiteCRMTaskPart = ticket.As <SuiteCRMTaskPart>();

                if (suiteCRMTaskPart == null)
                {
                    continue;
                }

                TicketPart ticketPart = ticket.As <TicketPart>();
                ContentItemPermissionPart permissionPart = ticket.As <ContentItemPermissionPart>();

                if (ticketPart == null)
                {
                    continue;
                }

                if (!syncSettings.SyncSubTasks && ticketPart.Record.Parent != null)
                {
                    continue;
                }

                project_task suiteCRMProjectTask = null;

                if (!string.IsNullOrEmpty(suiteCRMTaskPart.ExternalId))
                {
                    suiteCRMProjectTask = suiteCRMTasks.FirstOrDefault(c => c.id == suiteCRMTaskPart.ExternalId);
                }

                if (suiteCRMProjectTask == null)
                {
                    suiteCRMProjectTask            = new project_task();
                    suiteCRMProjectTask.project_id = syncSettings.SuiteCRMId;
                    context.ProjectTaskUnitOfWork.Add(suiteCRMProjectTask);
                }

                CommonPart commonPart = ticketPart.As <CommonPart>();
                DateTime?  lastOrchardTicketChangeDate = commonPart.ModifiedUtc ?? commonPart.CreatedUtc;
                if (!syncSettings.DoNotOverrideNewerValues ||
                    suiteCRMProjectTask.date_modified == null ||
                    (lastOrchardTicketChangeDate.HasValue &&
                     suiteCRMProjectTask.date_modified.Value <= lastOrchardTicketChangeDate.Value))
                {
                    this.Copy(ticketPart, permissionPart, suiteCRMProjectTask, context);
                    context.ProjectTaskUnitOfWork.Save();
                }

                suiteCRMTaskPart.ExternalId   = suiteCRMProjectTask.id;
                suiteCRMTaskPart.LastSyncTime = DateTime.UtcNow;
                suiteCRMTaskPart.TaskType     = SuiteCRMTaskPart.SuiteCRMProjectTaskTypeValue;
                this.services.ContentManager.Publish(ticket.ContentItem);
            }
        }
Ejemplo n.º 5
0
        private void CopySuiteCRMTasksToOrchardTickets(TicketContext context, CopyOrchardProjectToSuiteViewModel.ProjectIdentifiers syncSettings)
        {
            if (syncSettings.OrchardCollaborationProjectId == null)
            {
                throw new ArgumentNullException("OrchardCollaborationProjectId must not be null");
            }

            if (string.IsNullOrEmpty(syncSettings.SuiteCRMId))
            {
                throw new ArgumentNullException("SuiteCRMId must not be null");
            }

            List <project_task> suiteCRMTasks = context.ProjectTaskUnitOfWork.GetProjectTasks(syncSettings.SuiteCRMId).ToList();
            var orchardTickets = this.searchTicketService.SearchByDatabase(
                new PagerParametersWithSortFields()
            {
                PageSize = 0
            },
                new PostedTicketSearchViewModel {
                ProjectId = syncSettings.OrchardCollaborationProjectId
            })
                                 .Select(c => c.As <SuiteCRMTaskPart>())
                                 .Where(c => c != null)
                                 .ToList();

            foreach (var suiteCRMTask in suiteCRMTasks)
            {
                var     orchardTicket  = orchardTickets.FirstOrDefault(c => c.ExternalId == suiteCRMTask.id);
                dynamic ticketSnapshot = null;

                ContentItem ticketContentItem = null;
                bool        isNew             = false;
                if (orchardTicket == null)
                {
                    isNew             = true;
                    ticketContentItem = this.services.ContentManager.Create("Ticket");
                }
                else
                {
                    ticketContentItem = orchardTicket.ContentItem;
                    ticketSnapshot    = this.streamService.TakeSnapshot(ticketContentItem);
                }

                TicketPart          ticketPart          = ticketContentItem.As <TicketPart>();
                SuiteCRMTaskPart    taskPart            = ticketContentItem.As <SuiteCRMTaskPart>();
                AttachToProjectPart attachToProjectPart = ticketContentItem.As <AttachToProjectPart>();

                // the values will be overridde in case user doesn't care about update time (item.DoNotOverrideNewerValues == false) or
                // the target modified date is less than source modified date
                DateTime?  lastSuiteCRMChangeDate = suiteCRMTask.date_modified ?? suiteCRMTask.date_entered;
                CommonPart commonPart             = ticketPart.As <CommonPart>();
                if (!syncSettings.DoNotOverrideNewerValues ||
                    isNew ||
                    (lastSuiteCRMChangeDate.HasValue && commonPart.ModifiedUtc <= lastSuiteCRMChangeDate.Value))
                {
                    if (attachToProjectPart != null)
                    {
                        attachToProjectPart.Record.Project = new ProjectPartRecord {
                            Id = syncSettings.OrchardCollaborationProjectId.Value
                        };
                    }

                    this.Copy(suiteCRMTask, ticketPart, context);
                    this.services.ContentManager.Publish(ticketContentItem);
                    this.streamService.WriteChangesToStreamActivity(ticketContentItem, ticketSnapshot, null);
                }

                taskPart.ExternalId   = suiteCRMTask.id;
                taskPart.LastSyncTime = DateTime.UtcNow;
                taskPart.TaskType     = SuiteCRMTaskPart.SuiteCRMProjectTaskTypeValue;
            }
        }
Ejemplo n.º 6
0
 public TicketRepository(TicketContext context,
                         Page <Ticket> page)
 {
     _context = context;
     _page    = page;
 }
Ejemplo n.º 7
0
        public IEnumerable <SuiteCRMTaskDetailViewModel> CopyOrchardTicketsToSuite(CopyOrchardTasksToSuiteViewModel model)
        {
            List <SuiteCRMTaskDetailViewModel> returnValue = new List <SuiteCRMTaskDetailViewModel>();

            using (var connection = Helper.GetConnection(this.services, this.Logger))
                using (SuiteCRMTaskUnitOfWork taskRepository = new SuiteCRMTaskUnitOfWork(connection))
                    using (SuiteCRMEmailAddressBeanUnitOfWork suiteCRMEmailAddressBeanUnitOfWork = new SuiteCRMEmailAddressBeanUnitOfWork(taskRepository))
                        using (SuiteCRMEmailAddressUnitOfWork suiteCRMEmailAddressUnitOfWork = new SuiteCRMEmailAddressUnitOfWork(taskRepository))
                            using (SuiteCRMProjectTaskUnitOfWork projectTasksRepository = new SuiteCRMProjectTaskUnitOfWork(taskRepository))
                                using (var suiteCRMTransaction = taskRepository.BeginTransaction())
                                {
                                    TicketContext context = new TicketContext();
                                    context.ProjectTaskUnitOfWork = projectTasksRepository;
                                    context.Priorities            = this.priorityRepository.Table.ToList();
                                    context.StatusList            = this.statusRepository.Table.ToList();

                                    try
                                    {
                                        var taskIds           = model.Tasks.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)).Select(c => c.SuiteCRMId).ToArray();
                                        var suiteTasks        = taskRepository.GetTasks(taskIds);
                                        var suiteProjectTasks = projectTasksRepository.GetTasks(taskIds);
                                        var orchardTickets    = this.services
                                                                .ContentManager
                                                                .GetMany <SuiteCRMTaskPart>(
                                            model.Tasks.Where(c => c.OrchardCollaborationTicketId.HasValue).Select(c => c.OrchardCollaborationTicketId.Value),
                                            VersionOptions.Published,
                                            new QueryHints().ExpandParts <TicketPart>());

                                        foreach (var item in model.Tasks)
                                        {
                                            if (item.OrchardCollaborationTicketId == null)
                                            {
                                                continue;
                                            }

                                            var ticket = orchardTickets.FirstOrDefault(c => c.Id == item.OrchardCollaborationTicketId.Value);

                                            var        suiteCRMTaskPart = ticket.As <SuiteCRMTaskPart>();
                                            TicketPart ticketPart       = ticket.As <TicketPart>();
                                            ContentItemPermissionPart permissionPart      = ticket.As <ContentItemPermissionPart>();
                                            AttachToProjectPart       attachToProjectPart = ticket.As <AttachToProjectPart>();
                                            SuiteCRMProjectPart       projectPart         = null;

                                            if (!this.IsSyncingTicketValid(item, ticket, out projectPart))
                                            {
                                                continue;
                                            }

                                            project_task suiteCRMProjectTask = null;
                                            task         suiteCRMTask        = null;

                                            if (!string.IsNullOrEmpty(suiteCRMTaskPart.ExternalId) && item.IsProjectTask)
                                            {
                                                suiteCRMProjectTask = suiteProjectTasks.FirstOrDefault(c => c.id == suiteCRMTaskPart.ExternalId);
                                            }

                                            if (!string.IsNullOrEmpty(suiteCRMTaskPart.ExternalId) && !item.IsProjectTask)
                                            {
                                                suiteCRMTask = suiteTasks.FirstOrDefault(c => c.id == suiteCRMTaskPart.ExternalId);
                                            }

                                            if (suiteCRMProjectTask == null && item.IsProjectTask)
                                            {
                                                suiteCRMProjectTask            = new project_task();
                                                suiteCRMProjectTask.project_id = item.SuiteCRMId;
                                                projectTasksRepository.Add(suiteCRMProjectTask);
                                            }

                                            if (suiteCRMTask == null && !item.IsProjectTask)
                                            {
                                                suiteCRMTask = new task();
                                                taskRepository.Add(suiteCRMTask);
                                            }

                                            CommonPart commonPart = ticketPart.As <CommonPart>();
                                            DateTime?  lastOrchardTicketChangeDate = commonPart.ModifiedUtc ?? commonPart.CreatedUtc;
                                            if (suiteCRMProjectTask != null &&
                                                (
                                                    !item.DoNotOverrideNewerValues ||
                                                    suiteCRMProjectTask.date_modified == null ||
                                                    (lastOrchardTicketChangeDate.HasValue &&
                                                     suiteCRMProjectTask.date_modified.Value <= lastOrchardTicketChangeDate.Value)
                                                ))
                                            {
                                                this.Copy(ticketPart, permissionPart, suiteCRMProjectTask, context);
                                                suiteCRMProjectTask.project_id = projectPart.ExternalId;
                                                projectTasksRepository.Save();
                                            }

                                            if (suiteCRMTask != null &&
                                                (
                                                    !item.DoNotOverrideNewerValues ||
                                                    suiteCRMTask.date_modified == null ||
                                                    (lastOrchardTicketChangeDate.HasValue &&
                                                     suiteCRMTask.date_modified.Value <= lastOrchardTicketChangeDate.Value)
                                                ))
                                            {
                                                this.Copy(ticketPart, permissionPart, suiteCRMTask, context);

                                                // set  contact
                                                if (string.IsNullOrEmpty(suiteCRMTask.created_by) && commonPart.Owner != null)
                                                {
                                                    var emailAddress = suiteCRMEmailAddressUnitOfWork.GetByEmail(commonPart.Owner.Email);
                                                    if (emailAddress != null)
                                                    {
                                                        var contact = suiteCRMEmailAddressBeanUnitOfWork.GetBeanIdOfEmailAddress(Helper.ContactsModuleName, new[] { emailAddress.id }).FirstOrDefault();

                                                        if (contact != null)
                                                        {
                                                            suiteCRMTask.parent_id   = contact.id;
                                                            suiteCRMTask.parent_type = Helper.ContactsModuleName;
                                                        }
                                                    }
                                                }

                                                projectTasksRepository.Save();
                                            }

                                            suiteCRMTaskPart.ExternalId   = item.IsProjectTask ? suiteCRMProjectTask.id : suiteCRMTask.id;
                                            suiteCRMTaskPart.LastSyncTime = DateTime.UtcNow;
                                            suiteCRMTaskPart.TaskType     = item.IsProjectTask ? SuiteCRMTaskPart.SuiteCRMProjectTaskTypeValue : SuiteCRMTaskPart.SuiteCRMTaskTypeValue;
                                            this.services.ContentManager.Publish(ticket.ContentItem);

                                            SuiteCRMTaskDetailViewModel returnValueItem = new SuiteCRMTaskDetailViewModel();
                                            returnValueItem.OrchardCollaborationTicket = ticket.ContentItem;
                                            returnValueItem.IsSync         = true;
                                            returnValueItem.IsProjectTask  = item.IsProjectTask;
                                            returnValueItem.LastSyncTime   = suiteCRMTaskPart.LastSyncTime;
                                            returnValueItem.SuiteCRMTaskId = suiteCRMTaskPart.ExternalId;
                                            returnValue.Add(returnValueItem);
                                        }

                                        suiteCRMTransaction.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        suiteCRMTransaction.Rollback();
                                        throw ex;
                                    }
                                }

            return(returnValue);
        }
 public AantekeningViewComponent(TicketContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
 public TicketContextSeedData(TicketContext context, UserManager<FubarUser> userManager)
 {
     _context = context;
     _userManager = userManager;
 }
 public TicketController(TicketContext context, IUriService service)
 {
     this.context    = context;
     this.uriService = service;
 }
Ejemplo n.º 11
0
 public TicketController(TicketContext context)
 {
     _context = context;
 }
 //initialize context
 public TicketingHomeController(TicketContext context)
 {
     Context = context;
 }
Ejemplo n.º 13
0
 public MainWindow()
 {
     InitializeComponent();
     db = new TicketContext();
 }
Ejemplo n.º 14
0
 public BookingController(IBus bus, TicketContext context)
 {
     //clientService = _clientService;
     _bus     = bus;
     _context = context;
 }
Ejemplo n.º 15
0
 public UserUpdateMessageConsumerFromSettings(TicketContext ticketContext, IMapper mapper)
 {
     _ticketContext = ticketContext;
     _mapper        = mapper;
 }
Ejemplo n.º 16
0
 public StatusController(TicketContext context)
 {
     _context = context;
 }
Ejemplo n.º 17
0
 public TicketCategoryRepository(TicketContext context) : base(context, context.TicketCategories)
 {
     _ticketContext = context;
 }
Ejemplo n.º 18
0
        public static Task Initialize()
        {
            return Task.Run(() =>
            {

                _database = new RailwayDataModelContainer();

                Clients = new ClientContext();
                Employees = new EmployeeContext();
                Stations = new StationContext();
                Seats = new SeatContext();
                Tickets = new TicketContext();
                TrainWagons = new TrainWagonContext();
                Trains = new TrainContext();
                Routes = new RouteContext();
                VoyageRoutes = new VoyageRouteContext();
                Voyages = new VoyageContext();
                Wagons = new WagonContext();
                WagonSeats = new WagonSeatContext();

                Clients.Repository = _database.ClientSet;
                Employees.Repository = _database.EmployeeSet;
                Stations.Repository = _database.StationSet;
                Seats.Repository = _database.SeatSet;
                Tickets.Repository = _database.TicketSet;
                TrainWagons.Repository = _database.TrainWagonSet;
                Trains.Repository = _database.TrainSet;
                VoyageRoutes.Repository = _database.VoyageRouteSet;
                Routes.Repository = _database.RouteSet;
                Voyages.Repository = _database.VoyageSet;
                Wagons.Repository = _database.WagonSet;
                WagonSeats.Repository = _database.WagonSeatSet;

                DataBase.Database.Connection.OpenAsync();
            });
        }
Ejemplo n.º 19
0
        public void PrintInside()
        {
            const string asterics  = "*****************************************************";
            const string line      = "_____________________________________________________";
            const string please    = "Por favor espere su turno";
            const string lblNumber = "SU NÚMERO ES";
            const string lblDate   = "Fecha:";

            try
            {
                using (var db = new TicketContext(TicketServer, TicketDatabase))
                {
                    using (var trans = db.Database.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
                    {
                        try
                        {
                            var sql    = @"SELECT t.idturno AS IdTurno, t.numero AS Numero, t.fechaTurno AS Fecha, c.letra AS Letra, c.nombre AS Tipo From turnos t INNER JOIN colas c ON c.idcola = t.idcola WHERE  t.idterminal = @terminal AND t.ticketImpreso = '0' Order by t.idturno DESC";
                            var result = db.Database.SqlQuery <Turno>(sql,
                                                                      new MySqlParameter("terminal", TicketTerminal))
                                         .ToList();
                            if (result.Count > 0)
                            {
                                var turnoId = result[0].IdTurno;
                                sql = @"update turnos set ticketImpreso ='1' WHERE idturno = @turno";
                                db.Database.ExecuteSqlCommand(sql,
                                                              new MySqlParameter("turno", turnoId));
                                sql = @"SELECT texto From ticket WHERE visible = '1'  Order by orden ASC";
                                result[0].Textos = db.Database.SqlQuery <string>(sql).ToList();
                                trans.Commit();

                                var turno   = result[0];
                                var printer = new RawPrinter();
                                printer.SetAlign(RawPrinter.Align.Center);
                                printer.DrawLine(RawPrinter.SizeH1 + asterics);
                                printer.DrawLine(RawPrinter.SizeH2 + turno.IdTurno);
                                printer.DrawLine(RawPrinter.SizeH2 + lblNumber);
                                printer.DrawLine(RawPrinter.SizeH4 + turno.Letra + turno.Numero);
                                printer.DrawLine(RawPrinter.SizeH4 + turno.Letra + turno.Numero);
                                printer.DrawLine(asterics);
                                printer.DrawLine(RawPrinter.SizeH1 + asterics);
                                printer.DrawLine(RawPrinter.SizeH1 + please);
                                printer.DrawLine(RawPrinter.SizeH1 + lblDate + " " + turno.Fecha);
                                printer.DrawLine(RawPrinter.SizeH1 + line);
                                foreach (var txt in turno.Textos)
                                {
                                    printer.DrawLine(RawPrinter.SizeH1 + txt);
                                }

                                printer.BarCodeModelA("14159265");
                                printer.BarCodeModelB("14159265");
                                printer.Print();
                            }
                            trans.Rollback();
                        }
                        catch (Exception)
                        {
                            trans.Rollback();
                        }
                    }
                }
            }
            catch (Exception)
            {
                Task.Delay(500).Wait();
            }
        }
Ejemplo n.º 20
0
 public HomeController(TicketContext ctx) => context = ctx;
Ejemplo n.º 21
0
 public TicketsController(TicketContext context, ITicketRepository repo, IUnitOfWork unitOfWork)
 {
     _context    = context;
     _repo       = repo;
     _unitOfWork = unitOfWork;
 }
Ejemplo n.º 22
0
        public IEnumerable <SuiteCRMProjectDetailViewModel> CopySuiteCRMProjectsToOrchard(CopyOrchardProjectToSuiteViewModel model)
        {
            List <SuiteCRMProjectDetailViewModel> returnValue = new List <SuiteCRMProjectDetailViewModel>();

            using (var connection = Helper.GetConnection(this.services, this.Logger))
                using (SuiteCRMProjectUnitOfWork projectRepository = new SuiteCRMProjectUnitOfWork(connection))
                    using (SuiteCRMProjectTaskUnitOfWork projectTasksRepository = new SuiteCRMProjectTaskUnitOfWork(projectRepository))
                    {
                        var suiteProjects   = projectRepository.GetProjects(model.Projects.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)).Select(c => c.SuiteCRMId).ToArray());
                        var orchardProjects = this.services
                                              .ContentManager
                                              .GetMany <SuiteCRMProjectPart>(
                            model.Projects.Where(c => c.OrchardCollaborationProjectId.HasValue).Select(c => c.OrchardCollaborationProjectId.Value),
                            VersionOptions.Published,
                            new QueryHints().ExpandParts <ProjectPart>());

                        foreach (var item in model.Projects.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)))
                        {
                            var suiteCRMProject = suiteProjects.FirstOrDefault(c => c.id.ToLower() == item.SuiteCRMId.ToLower());

                            if (suiteCRMProject == null)
                            {
                                continue;
                            }

                            ContentItem orchardProject  = null;
                            dynamic     projectSnapshot = null;
                            bool        isNew           = false;
                            if (item.OrchardCollaborationProjectId.HasValue)
                            {
                                var part = orchardProjects.FirstOrDefault(c => c.Id == item.OrchardCollaborationProjectId.Value);
                                if (part != null)
                                {
                                    orchardProject  = part.ContentItem;
                                    projectSnapshot = this.streamService.TakeSnapshot(orchardProject);
                                }
                                else
                                {
                                    isNew          = true;
                                    orchardProject = this.services.ContentManager.New("ProjectItem");
                                }
                            }
                            else
                            {
                                isNew          = true;
                                orchardProject = this.services.ContentManager.New("ProjectItem");
                            }

                            if (isNew)
                            {
                                ProjectDashboardEditorPart editorPart = orchardProject.As <ProjectDashboardEditorPart>();
                                var portletTemplates = this.projectService.GetPortletsTemplates();
                                editorPart.PortletList = this.projectService.GetDefaultPortletIds(portletTemplates).ToArray();
                                this.services.ContentManager.Create(orchardProject);
                            }

                            // by building editor, we can be sure that the default values will be set
                            this.services.ContentManager.BuildEditor(orchardProject);

                            SuiteCRMProjectPart suiteCRMProjectPart = orchardProject.As <SuiteCRMProjectPart>();
                            ProjectPart         projectPart         = orchardProject.As <ProjectPart>();
                            suiteCRMProjectPart.ExternalId   = suiteCRMProject.id;
                            suiteCRMProjectPart.LastSyncTime = DateTime.UtcNow;

                            // the values will be overridde in case user doesn't care about update time (item.DoNotOverrideNewerValues == false) or
                            // the target modified date is less than source modified date
                            DateTime?  lastSuiteCRMChangeDate = suiteCRMProject.date_modified ?? suiteCRMProject.date_entered;
                            CommonPart commonPart             = orchardProject.As <CommonPart>();
                            if (!item.DoNotOverrideNewerValues ||
                                isNew ||
                                (lastSuiteCRMChangeDate.HasValue && commonPart.ModifiedUtc <= lastSuiteCRMChangeDate.Value))
                            {
                                this.Copy(suiteCRMProject, projectPart);
                                this.services.ContentManager.Publish(orchardProject);
                                item.OrchardCollaborationProjectId = orchardProject.Id;
                                this.streamService.WriteChangesToStreamActivity(orchardProject, projectSnapshot, null);
                            }

                            if (item.SyncTasks)
                            {
                                TicketContext context = new TicketContext();
                                context.ProjectTaskUnitOfWork = projectTasksRepository;
                                context.Priorities            = this.priorityRepository.Table.ToList();
                                context.StatusList            = this.statusRepository.Table.ToList();
                                this.CopySuiteCRMTasksToOrchardTickets(context, item);
                            }

                            SuiteCRMProjectDetailViewModel projectModel = new SuiteCRMProjectDetailViewModel();
                            projectModel.SuiteCRMProject             = this.Convert(suiteCRMProject);
                            projectModel.LastSyncTime                = suiteCRMProjectPart.LastSyncTime;
                            projectModel.OrchardCollaborationProject = orchardProject;
                            projectModel.OrchardCollaborationTitle   = projectPart.Title;

                            returnValue.Add(projectModel);
                        }
                    }

            return(returnValue);
        }
Ejemplo n.º 23
0
 public static TicketContext GetTicketContext()
 {
     return _ticketContext ?? (_ticketContext = new TicketContext());
 }
Ejemplo n.º 24
0
        public IEnumerable <SuiteCRMProjectDetailViewModel> CopyOrchardProjectsToSuite(CopyOrchardProjectToSuiteViewModel model)
        {
            List <SuiteCRMProjectDetailViewModel> returnValue = new List <SuiteCRMProjectDetailViewModel>();

            using (var connection = Helper.GetConnection(this.services, this.Logger))
                using (SuiteCRMProjectUnitOfWork projectRepository = new SuiteCRMProjectUnitOfWork(connection))
                    using (SuiteCRMProjectTaskUnitOfWork projectTasksRepository = new SuiteCRMProjectTaskUnitOfWork(projectRepository))
                        using (var suiteCRMTransaction = projectRepository.BeginTransaction())
                        {
                            try
                            {
                                var suiteProjects   = projectRepository.GetProjects(model.Projects.Where(c => !string.IsNullOrEmpty(c.SuiteCRMId)).Select(c => c.SuiteCRMId).ToArray());
                                var orchardProjects = this.services
                                                      .ContentManager
                                                      .GetMany <SuiteCRMProjectPart>(
                                    model.Projects.Where(c => c.OrchardCollaborationProjectId.HasValue).Select(c => c.OrchardCollaborationProjectId.Value),
                                    VersionOptions.Published,
                                    new QueryHints().ExpandParts <ProjectPart>());

                                foreach (var item in model.Projects.Where(c => c.OrchardCollaborationProjectId.HasValue))
                                {
                                    var suiteCRMProjectPart = orchardProjects.FirstOrDefault(c => c.Id == item.OrchardCollaborationProjectId.Value);

                                    if (suiteCRMProjectPart == null)
                                    {
                                        continue;
                                    }

                                    var orchardProject = suiteCRMProjectPart.As <ProjectPart>();

                                    project suiteCRMProject = null;
                                    if (!string.IsNullOrEmpty(item.SuiteCRMId))
                                    {
                                        suiteCRMProject = suiteProjects.FirstOrDefault(c => c.id == item.SuiteCRMId);

                                        if (suiteCRMProject == null)
                                        {
                                            suiteCRMProject = new project();
                                            projectRepository.Add(suiteCRMProject);
                                        }
                                    }
                                    else
                                    {
                                        suiteCRMProject = new project();
                                        projectRepository.Add(suiteCRMProject);
                                    }

                                    // the values will be overridde in case user doesn't care about update time (item.DoNotOverrideNewerValues == false) or
                                    // the target modified date is smaller than source modified date
                                    CommonPart commonPart = orchardProject.As <CommonPart>();
                                    DateTime?  lastOrchardTicketChangeDate = commonPart.ModifiedUtc ?? commonPart.CreatedUtc;
                                    if (!item.DoNotOverrideNewerValues ||
                                        suiteCRMProject.date_modified == null ||
                                        (lastOrchardTicketChangeDate.HasValue &&
                                         suiteCRMProject.date_modified.Value <= lastOrchardTicketChangeDate.Value))
                                    {
                                        this.Copy(orchardProject, suiteCRMProject);
                                        projectRepository.Save();
                                    }

                                    suiteCRMProjectPart.LastSyncTime = DateTime.UtcNow;
                                    suiteCRMProjectPart.ExternalId   = suiteCRMProject.id;
                                    item.SuiteCRMId = suiteCRMProject.id;

                                    if (item.SyncTasks)
                                    {
                                        TicketContext context = new TicketContext();
                                        context.ProjectTaskUnitOfWork = projectTasksRepository;
                                        context.Priorities            = this.priorityRepository.Table.ToList();
                                        context.StatusList            = this.statusRepository.Table.ToList();
                                        this.CopyOrchardTicketsToSuiteCRM(context, item);
                                    }

                                    this.services.ContentManager.Publish(suiteCRMProjectPart.ContentItem);

                                    SuiteCRMProjectDetailViewModel projectModel = new SuiteCRMProjectDetailViewModel();
                                    projectModel.OrchardCollaborationProject = suiteCRMProjectPart.ContentItem;
                                    projectModel.IsSync                    = true;
                                    projectModel.LastSyncTime              = suiteCRMProjectPart.LastSyncTime;
                                    projectModel.SuiteCRMProject           = this.Convert(suiteCRMProject);
                                    projectModel.OrchardCollaborationTitle = orchardProject.Record.Title;
                                    returnValue.Add(projectModel);
                                }

                                suiteCRMTransaction.Commit();
                            }
                            catch (Exception ex)
                            {
                                suiteCRMTransaction.Rollback();
                                throw ex;
                            }
                        }

            return(returnValue);
        }
Ejemplo n.º 25
0
 public FubarRepository(TicketContext context, ILogger<FubarRepository> logger)
 {
     _context = context;
     _logger = logger;
 }
Ejemplo n.º 26
0
 public UserRepo(TicketContext context)
 {
     _context = context;
 }