public void Execute(AddExternalDocRefCommand command)
        {
            _log.InfoFormat("Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString());
            try
            {
                if (!DocumentExists(command.DocumentId))
                    return;

                tblDocument doc = _cokeDataContext.tblDocument.FirstOrDefault(s => s.Id == command.DocumentId);
                doc.ExtDocumentReference = command.ExternalDocRef;
                _cokeDataContext.SaveChanges();
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Error Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString());
                _log.Error("AddExternalDocRefCommandHandler exception", ex);
                throw;
            }
        }
 private void RouteExternalRef(CommandRouteOnRequestDTO commandRouteItems,ICommand cmd)
 {
     if(cmd is CreateMainOrderCommand)
     {
         var cmdorder = cmd as CreateMainOrderCommand;
         commandRouteItems.RouteOnRequest.CommandType = CommandType.AddExternalDocRef.ToString();
         var command = new AddExternalDocRefCommand();
         command.CommandId = Guid.NewGuid();
         command.DocumentId = cmdorder.DocumentId;
         command.CommandCreatedDateTime = DateTime.Now;
         command.SendDateTime = DateTime.Now;
         command.PDCommandId = cmdorder.PDCommandId;
         command.CommandGeneratedByCostCentreApplicationId = Guid.Empty;
         command.ExternalDocRef = cmdorder.ExtDocumentReference;
         commandRouteItems.RouteOnRequest.Id = 0;
         commandRouteItems.RouteOnRequest.DocumentId = cmdorder.DocumentId;
         commandRouteItems.RouteOnRequest.DateAdded = DateTime.Now;
         commandRouteItems.RouteOnRequest.CommandGeneratedByCostCentreApplicationId = Guid.Empty;
         commandRouteItems.RouteOnRequest.DocumentParentId = cmdorder.DocumentId;
         commandRouteItems.RouteOnRequest.CommandId = command.CommandId;
         commandRouteItems.RouteOnRequest.JsonCommand = JsonConvert.SerializeObject(command);
         _commandRoutingOnRequestRepository.Add(commandRouteItems.RouteOnRequest);
         var ccAdded = new List<Guid>();
         foreach (var rc in commandRouteItems.CommandRouteCentres.Distinct())
         {
             if (ccAdded.Any(n => n == rc.CostCentreId))
                 continue;
             ccAdded.Add(rc.CostCentreId);
             rc.Id = Guid.NewGuid();
             rc.CommandRouteOnRequestId = commandRouteItems.RouteOnRequest.Id;
             _commandRoutingOnRequestRepository.AddRoutingCentre(rc);
         }
     }
 }
        private AddExternalDocRefCommand GetExternalCommnandRef(ICommand cmd)
        {
            if (cmd is CreateMainOrderCommand)
            {
                var cmdorder = cmd as CreateMainOrderCommand;
               
                var command = new AddExternalDocRefCommand();
                command.CommandId = Guid.NewGuid();
                command.DocumentId = cmdorder.DocumentId;
                command.CommandCreatedDateTime = DateTime.Now;
                command.SendDateTime = DateTime.Now;
                command.PDCommandId = cmdorder.PDCommandId;
                command.CommandGeneratedByCostCentreApplicationId = Guid.Empty;
                command.ExternalDocRef = cmdorder.ExtDocumentReference;

                return command;
            }
            return null;
        }