Task <bool> IRequestHandler <UpdateWorkInstructionRequest, bool> .Handle(UpdateWorkInstructionRequest request, CancellationToken cancellationToken)
        {
            var existingWorkInstruction = WorkInstructionService.Get(request.WorkInstruction.Id);

            if (existingWorkInstruction == null)
            {
                throw new ApplicationException($"UpdateWorkInstructionHandler: WorkInstruction with Id {request.WorkInstruction.Id} does not exist.");
            }

            var checkDuplicate = WorkInstructionService.Get(request.WorkInstruction.Id);

            if (checkDuplicate != null)
            {
                throw new ApplicationException($"UpdateWorkInstructionHandler: WorkInstruction with Id  {request.WorkInstruction.Id} already exist.");
            }

            //AutoMapper to Map the fields
            Mapper.Map(request.WorkInstruction.Id, existingWorkInstruction);

            using (var ts = new TransactionScope())
            {
                var updatedQuestionTagMap = WorkInstructionService.Update(existingWorkInstruction);

                ts.Complete();
            }
            return(Task.FromResult(true));
        }
Ejemplo n.º 2
0
        Task <bool> IRequestHandler <UpdateChecklistWorkInstructionRequest, bool> .Handle(UpdateChecklistWorkInstructionRequest request, CancellationToken cancellationToken)
        {
            var existingChecklistWorkInstruction = WorkInstructionService.Get(request.ChecklistWorkInstruction.Id);

            if (existingChecklistWorkInstruction == null)
            {
                throw new ApplicationException($"UpdateChecklistWorkInstructionHandler: ChecklistWorkInstruction with Id {request.ChecklistWorkInstruction.Id} does not exist.");
            }

            //AutoMapper to Map the fields
            Mapper.Map(request.ChecklistWorkInstruction, existingChecklistWorkInstruction);

            using (var ts = new TransactionScope())
            {
                var updatedChecklistEquipment = WorkInstructionService.Update(existingChecklistWorkInstruction);

                ts.Complete();
            }
            return(Task.FromResult(true));
        }