Пример #1
0
        /*
         *      Update
         *      ------
         *      1. Update `WorkOrderTemplate`
         *      2. Remove and save all `TemplateHardwareCollection`
         *      3. Map `IsMaintainable` and `ChecklistId` to `TemplateDoors`
         *      4. Remove and save all `TemplateDoors`
         *      5. Save new `WorkOrder` instances
         */
        public async Task <WorkorderTemplate> UpdateWordorderTemplate(
            string projectId,
            WorkorderTemplate template,
            IEnumerable <WorkorderTemplateDoor> templateDoors,
            IEnumerable <WorkorderTemplateHardwareCollection> hardwareCollections,
            IEnumerable <Workorder> workorders,
            string userId
            )
        {
            template.ProjectId = projectId;

            template.DoorCount = (templateDoors != null) ? templateDoors.Count() : 0;

            template.ModifiedDate     = DateTime.Now;
            template.LastModifiedUser = userId;

            template = await dataUnitOfWork.WorkorderTemplateRepository.UpdateWordorderTemplate(template);

            if (template != null)
            {
                if (templateDoors != null)
                {
                    if (hardwareCollections != null)
                    {
                        // Remove all hardware-collections, and  re-create them from the request
                        await objectLocator.WorkorderTemplateHardwareCollectionService.DeleteHardwareCollections(template.Id);

                        hardwareCollections = await objectLocator.WorkorderTemplateHardwareCollectionService.CreateHardwareCollections(hardwareCollections, template.Id, projectId);

                        templateDoors = objectLocator.WorkorderTemplateDoorService.SetHardwareOwnership(templateDoors, hardwareCollections);

                        // Remove all template doors, and  re-create them from the request
                        await objectLocator.WorkorderTemplateDoorService.DeleteWorkorderTemplateDoors(template.Id);

                        var isDoorCreationSuccess = await objectLocator.WorkorderTemplateDoorService.CreateWorkorderTemplateDoors(templateDoors, projectId, template.Id);
                    }

                    if (workorders != null)
                    {
                        // Remove all unstarted workorder instances, and  re-create them from the request
                        await objectLocator.WorkorderService.DeletePreviewWorkorders(projectId, template.Id, userId);

                        var newWorkorders = workorders.Where(x => x.IsPreviewOnly);
                        await objectLocator.WorkorderService.CreateWorkorders(newWorkorders, userId, template.Id, projectId);
                    }
                }
            }

            return(template);
        }
Пример #2
0
        /*
         *      Creation
         *      --------
         *      1. Save `WorkOrderTemplate`
         *      2. Save `TemplateHardwareCollection`
         *      3. Map `IsMaintainable` and `ChecklistId` to `TemplateDoors`
         *      4. Save `TemplateDoors`
         *      5. Save `WorkOrder` instances
         */
        public async Task <WorkorderTemplate> CreateWordorderTemplate(
            string projectId,
            WorkorderTemplate template,
            IEnumerable <WorkorderTemplateDoor> templateDoors,
            IEnumerable <WorkorderTemplateHardwareCollection> hardwareCollections,
            IEnumerable <Workorder> workorders,
            string userId
            )
        {
            template.ProjectId = projectId;

            template.DoorCount = (templateDoors != null) ? templateDoors.Count() : 0;

            template.ModifiedDate     = DateTime.Now;
            template.LastModifiedUser = userId;

            template = await dataUnitOfWork.WorkorderTemplateRepository.CreateWorkorderTemplate(template);

            if (template != null)
            {
                if (templateDoors != null)
                {
                    if (hardwareCollections != null)
                    {
                        hardwareCollections = await objectLocator.WorkorderTemplateHardwareCollectionService.CreateHardwareCollections(hardwareCollections, template.Id, projectId);

                        templateDoors = objectLocator.WorkorderTemplateDoorService.SetHardwareOwnership(templateDoors, hardwareCollections);

                        var isDoorCreationSuccess = await objectLocator.WorkorderTemplateDoorService.CreateWorkorderTemplateDoors(templateDoors, projectId, template.Id);
                    }

                    if (workorders != null)
                    {
                        await objectLocator.WorkorderService.CreateWorkorders(workorders, userId, template.Id, projectId);
                    }
                }
            }

            return(template);
        }
Пример #3
0
        public async Task <Workorder> CreateWordorderForDoor(string projectId, string companyId, string doorNr, string userId)
        {
            var projectDoor = await ObjectsLocator.DoorService.GetDoorByDoorNo(projectId, doorNr);

            if (projectDoor != null)
            {
                var __template = new WorkorderTemplate
                {
                    IsAdHoc   = true,
                    DoorCount = 1,

                    ProjectId        = projectId,
                    CompanyId        = companyId,
                    LastModifiedUser = userId,
                    ModifiedDate     = DateTime.UtcNow,

                    Name = $"Ad-hoc / {projectDoor.DoorNo} / {DateTime.UtcNow.ToString("dd.mm.yyyy")}",

                    RemindBeforeDays     = -1,
                    NotificationMailSent = true,
                };

                var template = await ObjectsLocator.WorkorderTemplateService.CreateWordorderTemplate(
                    projectId,
                    __template,
                    new List <WorkorderTemplateDoor>
                {
                    new WorkorderTemplateDoor
                    {
                        ProjectId = projectId,
                        Door      = projectDoor,
                    }
                },
                    new List <WorkorderTemplateHardwareCollection> {
                },
                    new List <Workorder>
                {
                    new Workorder
                    {
                        ProjectId                    = projectId,
                        IsPreviewOnly                = false,
                        DueNotificationMailSent      = false,
                        ReminderNotificationMailSent = false,

                        StartDate        = DateTime.UtcNow,
                        LastModifiedUser = userId,
                        ModifiedDate     = DateTime.UtcNow,
                    }
                },
                    userId
                    );

                var __workorder = await ObjectsLocator.WorkorderService.GetFirstWorkorderByTemplateId(template.Id);

                var workorder = await ObjectsLocator.WorkorderService.StartWorkorder(__workorder.Id, userId);

                //var workorderDoor = await ObjectsLocator.WorkorderDoorService.GetFirstDoorInWorkorder(workorder.Id);

                //return workorderDoor;

                return(workorder);
            }

            return(null);
        }
Пример #4
0
 public async Task <WorkorderTemplate> UpdateWordorderTemplate(WorkorderTemplate workorderTemplate)
 {
     return(await dataUnitOfWork.WorkorderTemplateRepository.UpdateWordorderTemplate(workorderTemplate));
 }