示例#1
0
        //
        // GET: /GUID/

        public JsonResult GetGuid()
        {
            string guidString = Guid.NewGuid().ToString();
            guidString=guidString.Substring(0, guidString.Length-4);

            ResponseBasic response = new ResponseBasic()
            {
                Result = guidString,
                ErrorInfo="Success"
            };
            return Json(response, JsonRequestBehavior.AllowGet);
        }
        public HttpResponseMessage Notify(JObject jnotification)
        {
            var request = Request;
            Guid Id = Guid.Empty;
            var responseBasic = new ResponseBasic();
            HttpStatusCode returnCode = HttpStatusCode.OK;
            try
            {
                responseBasic.ResultInfo = "invalid jsonnotificaction";
                NotificationBase notification = JsonConvert.DeserializeObject<NotificationBase>(jnotification.ToString());
                responseBasic.ResultInfo = "valid jsonnotificaction";
                _log.InfoFormat("Received notification id {0} : Notification type {1} ", notification.Id, notification.TypeRef);
                bool isValid = notification != null;

                Id = notification.Id;
              
                if (isValid)
                {
                    _log.InfoFormat("Id {0} Placed on bus", notification.Id);
                    var n = new NotificationProcessingAudit();
                    n.DateInserted = DateTime.Now;
                    n.Id = notification.Id;
                    n.Status=NotificationProcessingStatus.Pending;
                    n.Type = notification.TypeRef;
                    n.JsonNotification = JsonConvert.SerializeObject(notification);
                    _notificationProcessing.Add(n);
                    responseBasic.Result = "Notification Processed";


                }
            }
            catch (Exception ex)
            {
                responseBasic.Result = "Processing Failed";
                responseBasic.ErrorInfo = ex.Message;
                _log.Error("Failed to process Notification", ex);
            }
            HttpResponseMessage response = Request.CreateResponse(returnCode, responseBasic);
            _log.InfoFormat("ResponseMessage : NotificationId = {0}  : response code = {1}  : Response Result = {2}", Id, returnCode, responseBasic.Result);
            return response;
        }
 public JsonResult Procces(string masterDataCollective, string jsonDTO)
 {
     MasterBaseDTO data = _masterDataDTODeserialize.DeserializeMasterDataDTO(masterDataCollective, jsonDTO);
     ResponseBasic response = null;
     if (data == null)
     {
         response = new ResponseBasic { Result = "Invalid", ErrorInfo = "Failed" };
     }
     else
     {
         try
         {
             MasterDataDTOSaveCollective ct = GetMasterDataCollective(masterDataCollective);
             _publishMasterData.Publish(data, ct);
             response = new ResponseBasic { Result = "OK", ErrorInfo = "Success" };
         }
         catch (Exception ex)
         {
             _log.InfoFormat("ERROR Processing MasterData : {0} with {1} Exception {2} ", masterDataCollective, jsonDTO,ex.Message);
         }
     }
     return Json(response);
    
 }
示例#4
0
        public async Task <ResponseBasic> ManageUsersInRole(UsersInRoleModel model)
        {
            ResponseBasic response = new ResponseBasic();
            var           role     = await this.RoleManager.FindByIdAsync(model.Id);

            int rows = 0;

            if (role == null)
            {
                response.Mensagge = "El Role No Existe";
                response.Errors.Add(new ErrorMessage("", "El Role No Ha Sido Encontrado"));
                return(response);
            }

            foreach (string user in model.EnrolledUsers)
            {
                var appUser = await this.UserManager.FindByIdAsync(user);

                if (appUser == null)
                {
                    response.Errors.Add(new ErrorMessage("", String.Format("Usuario: {0} No Existe", user)));
                    continue;
                }

                if (!this.UserManager.IsInRole(user, role.Name))
                {
                    IdentityResult result = await UserManager.AddToRoleAsync(user, role.Name);

                    if (!result.Succeeded)
                    {
                        response.Errors.Add(new ErrorMessage("", String.Format("Usuario: {0} No Se Le Ha Agregado El Role", user)));
                    }
                    rows++;
                }
            }

            foreach (string user in model.RemovedUsers)
            {
                var appUser = await this.UserManager.FindByIdAsync(user);


                if (appUser == null)
                {
                    response.Errors.Add(new ErrorMessage("", String.Format("Usuario: {0} No Existe", user)));
                    continue;
                }


                IdentityResult result = await this.UserManager.RemoveFromRoleAsync(user, role.Name);

                if (!result.Succeeded)
                {
                    response.Errors.Add(new ErrorMessage("", String.Format("Usuario: {0} No Se Le Ha Agregado El Role", user)));
                }
                rows++;
            }

            response.RowAffected = rows;

            if (response.Errors.Count == 0)
            {
                response.Mensagge = "Operación Realizada Con Exito";
                return(response);
            }
            response.Mensagge = "Operacón Realizada Con Errores";
            return(response);
        }
        public HttpResponseMessage Run(JObject jcommand)
        {

            Guid commandId = Guid.Empty;
            var responseBasic = new ResponseBasic();
            HttpStatusCode returnCode = HttpStatusCode.OK;
            try
            {
                responseBasic.ResultInfo = "invalid jsoncommand";
                DocumentCommand command = JsonConvert.DeserializeObject<DocumentCommand>(jcommand.ToString());
                responseBasic.ResultInfo = "valid jsoncommand";
                _log.InfoFormat("Received command id {0} : command type {1} : document id {2}", command.CommandId, command.CommandTypeRef, command.DocumentId);
                bool isValid = command != null;

                commandId = command.CommandId;
                //if (isValid && !_costCentreApplicationService.IsCostCentreActive(command.CommandGeneratedByCostCentreApplicationId))
                //{
                //    isValid = false;
                //    returnCode = HttpStatusCode.NotAcceptable;
                //    responseBasic.Result = "Inactive CostCentre Application Id ";
                //    _log.InfoFormat("Cost centre is not active for command id {0} cost centre application id {1}", command.CommandId, command.CommandGeneratedByCostCentreApplicationId);
                //}
                if (isValid)
                {
                    _log.InfoFormat("CommandId {0} Placed on bus", command.CommandId);
                    var message = new BusMessage
                    {
                        CommandType = command.CommandTypeRef,
                        MessageId = command.CommandId,
                        BodyJson = JsonConvert.SerializeObject(command),
                        SendDateTime = DateTime.Now.ToString(),
                        IsSystemMessage = command.IsSystemCommand
                    };
                    var commandProcessingAudit = new CommandProcessingAudit
                    {
                        CommandType = command.CommandTypeRef,
                        CostCentreApplicationId = command.CommandGeneratedByCostCentreApplicationId,
                        CostCentreCommandSequence = command.CommandSequence,
                        DateInserted = DateTime.Now,
                        Id = command.CommandId,
                        JsonCommand = message.BodyJson,
                        RetryCounter = 0,
                        Status = CommandProcessingStatus.OnQueue,
                        SendDateTime = message.SendDateTime,
                        DocumentId = command.DocumentId,
                        ParentDocumentId = command.PDCommandId
                    };

                    _busPublisher.Publish(message);
                    AuditCCHit(command.CommandGeneratedByCostCentreId, "CommandProcessing",
                               string.Format("Publish : {0} Command {1} of Type {2}",
                                             CommandProcessingStatus.OnQueue.ToString(), command.CommandId.ToString(),
                                             message.CommandType), CommandProcessingStatus.OnQueue.ToString());
                    _commandProcessingAuditRepository.AddCommand(commandProcessingAudit);
                    responseBasic.Result = "Command Processed";


                }
            }
            catch (Exception ex)
            {
                responseBasic.Result = "Processing Failed";
                responseBasic.ErrorInfo = ex.Message;
                _log.Error("Failed to process command", ex);
            }
            HttpResponseMessage response = Request.CreateResponse(returnCode, responseBasic);
            _log.InfoFormat("ResponseMessage : commandId = {0}  : response code = {1}  : Response Result = {2}", commandId, returnCode, responseBasic.Result);
            return response;
        }
示例#6
0
        public JsonResult SetItemsPerpage(int pagesize)
        {
            ResponseBasic response = new ResponseBasic();
            try
            {
                DistributorWebHelper.SetItemPerPage(pagesize);
            }
            catch (Exception ex)
            {
               

            }
            return Json(response, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);

        }
示例#7
0
        public JsonResult SavePurchaseOrder(PurchaseOrderViewModel model)
        {
            ResponseBasic response= new ResponseBasic();
            try
            {
                var user = this.User.Identity.Name;
                model.Username = user;
                _purchaseOrderViewModelBuilder.Save(model);
                response.Result = "Ok";
                response.ResultInfo = "Purchase order saved and approved successfully";
            }catch(Exception ex)
            {
                response.Result = "Fail";
                response.ErrorInfo = ex.Message;

            }
            return Json(response, "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet);
            
        }
       public HttpResponseMessage Post(JObject jcommand)
       {
           
           var responseBasic = new ResponseBasic();
           responseBasic.Status = false;
           HttpStatusCode returnCode = HttpStatusCode.OK;
           try
           {
              
               responseBasic.ResultInfo = "invalid jsoncommand";
               string json = jcommand.ToString();
               CommandEnvelope envelope = JsonConvert.DeserializeObject<CommandEnvelope>(json);
               responseBasic.ResultInfo = "valid jsoncommand";
                bool isValid = envelope != null;
                _log.Info("responseBasic.ResultInfo " + responseBasic.ResultInfo);
               if (isValid)
               {
                   if (!_costCentreApplicationService.IsCostCentreActive(envelope.GeneratedByCostCentreApplicationId))
                   {
                       responseBasic.Status=false;
                       returnCode = HttpStatusCode.OK;
                       responseBasic.Result = "Inactive CostCentre Application Id";
                       _log.InfoFormat("Cost centre is not active for envelope id {0} ccId {1} ccid",envelope.Id, envelope.GeneratedByCostCentreApplicationId,envelope.GeneratedByCostCentreId);
                     return Request.CreateResponse(returnCode, responseBasic);
                   }
                   _log.InfoFormat("EnvelopeId {0} " ,envelope.Id.ToString());
               
                   envelope.EnvelopeArrivedAtServerTick = DateTime.Now.Ticks;

                   var message = new EnvelopeBusMessage
                                 {
                                     DocumentTypeId = envelope.DocumentTypeId,
                                     MessageId = envelope.Id,
                                     BodyJson = JsonConvert.SerializeObject(envelope),
                                     SendDateTime = DateTime.Now.ToString(),
                                     IsSystemMessage = envelope.IsSystemEnvelope
                                 };
                   var envelopeProcessingAudit = new CommandEnvelopeProcessingAudit
                                                 {

                                                     GeneratedByCostCentreApplicationId =
                                                         envelope.GeneratedByCostCentreApplicationId,
                                                    
                                                     DateInserted = DateTime.Now,
                                                     Id = envelope.Id,
                                                     JsonEnvelope = message.BodyJson,
                                                     RetryCounter = 0,
                                                     Status = EnvelopeProcessingStatus.OnQueue,
                                                     SendDateTime = message.SendDateTime,
                                                     DocumentId = envelope.DocumentId,
                                                     ParentDocumentId = envelope.ParentDocumentId,
                                                     DocumentType = (DocumentType) envelope.DocumentTypeId,
                                                     EnvelopeGeneratedTick = envelope.EnvelopeGeneratedTick,
                                                     EnvelopeArrivalAtServerTick = envelope.EnvelopeArrivedAtServerTick,
                                                     EnvelopeProcessOnServerTick = 0,
                                                     GeneratedByCostCentreId = envelope.GeneratedByCostCentreId,
                                                     RecipientCostCentreId = envelope.RecipientCostCentreId,
                                                     LastExecutedCommand = 0,
                                                     NumberOfCommand = envelope.CommandsList.Count

                                                 };
                   envelopeProcessingAudit.DocumentTypeName = envelopeProcessingAudit.DocumentType.ToString();
                   if (_commandEnvelopeProcessingAuditRepository.IsConnected())
                   {
                       var exist = _commandEnvelopeProcessingAuditRepository.GetById(envelope.Id);
                       if (exist == null)
                       {
                           _commandEnvelopeProcessingAuditRepository.AddCommand(envelopeProcessingAudit);
                           _busPublisher.Publish(message);
                       }
                       else
                       {
                           _log.InfoFormat("EnvelopeId {0}  Already Published", envelope.Id.ToString());
                       }
                       _log.InfoFormat("EnvelopeId {0}  Published", envelope.Id.ToString());
                       responseBasic.Status = true;
                       responseBasic.Result = "Envelope Processed";
                       _log.Info("  responseBasic.Result " + responseBasic.Result);
                   }
                   else
                   {
                       responseBasic.Result = "Processing Failed";
                       responseBasic.ErrorInfo = "Mongo down";
                       _log.Info("   responseBasic.ErrorInfo " + responseBasic.ErrorInfo);
                   }
               }
           }
           catch (Exception ex)
           {
               responseBasic.Result = "Processing Failed";
               responseBasic.ErrorInfo = ex.Message;
               _log.Info("   responseBasic.Result" + responseBasic.Result);
               _log.Info("   responseBasic.ErrorInfo " + responseBasic.ErrorInfo);
               
                
           }
           HttpResponseMessage response = Request.CreateResponse(returnCode, responseBasic);

           return response;
       }
示例#9
0
        private ResponseBasic ProcessMessage(string commandType, string jsoncommand, string sendDateTime, string source)
        {
            string result = "";
            string errorInfo = "";
            Guid ccId = Guid.Empty;
            _log.InfoFormat("Processing command : {0} with {1} from source {2} ", commandType, jsoncommand, source);
            try
            {
                DateTime _sendDateTime = _commandDeserialize.DeserializeSendDateTime(sendDateTime);
                ICommand deserializedCommand = _commandDeserialize.DeserializeCommand(commandType, jsoncommand);

                bool isValid = deserializedCommand != null;
                result = isValid ? "OK" : "Invalid";
                _log.InfoFormat("Deserialization is valid " + result);
                errorInfo = isValid ? "" : "Failed to deserialize " + commandType;

                if (isValid && !_costCentreApplicationService.IsCostCentreActive(deserializedCommand.CommandGeneratedByCostCentreApplicationId))
                {
                    isValid = false;
                    result = "Invalid";
                    errorInfo = "Inactive CostCentre Application Id ";
                }
                if (isValid && !QHealth.IsQueueHealthy)
                {
                    isValid = false;
                    result = "Invalid";
                    errorInfo = "Message Q not available";
                }

                if (isValid)
                {
                    ccId = deserializedCommand.CommandGeneratedByCostCentreId;
                    deserializedCommand.SendDateTime = _sendDateTime;
                    _log.Info("Client SendDateTime " + sendDateTime);
                    _log.InfoFormat("CommandId {0} Placed on bus", deserializedCommand.CommandId);
                    var message = new BusMessage
                    {
                        CommandType = commandType,
                        MessageId = deserializedCommand.CommandId,
                        BodyJson = jsoncommand,
                        SendDateTime = sendDateTime
                    };
                    var commandProcessingAudit = new CommandProcessingAudit
                                                                        {
                                                                            CommandType = commandType,
                                                                            CostCentreApplicationId = deserializedCommand.CommandGeneratedByCostCentreApplicationId,
                                                                            CostCentreCommandSequence = deserializedCommand.CommandSequence,
                                                                            DateInserted = DateTime.Now,
                                                                            Id = deserializedCommand.CommandId,
                                                                            JsonCommand = jsoncommand,
                                                                            RetryCounter = 0,
                                                                            Status = CommandProcessingStatus.OnQueue,
                                                                            SendDateTime=sendDateTime,
                                                                            DocumentId = deserializedCommand.DocumentId,
                                                                            ParentDocumentId=deserializedCommand.PDCommandId
                                                                        };

                   
                    _busPublisher.Publish(message);
                    AuditCCHit(deserializedCommand.CommandGeneratedByCostCentreId, "CommandProcessing", string.Format("Publish : {0} Command {1} of Type {2}", CommandProcessingStatus.OnQueue.ToString(), deserializedCommand.CommandId.ToString(), message.CommandType), CommandProcessingStatus.OnQueue.ToString());
                   _commandProcessingAuditRepository.AddCommand(commandProcessingAudit);
                }
                else
                    _log.Error(errorInfo);
            }
            catch (Exception ex)
            {
                result = "Invalid";
                _log.InfoFormat("ERROR Processing command : {0}", commandType);
                _log.Error(ex);
            }

            ResponseBasic responce = new ResponseBasic { Result = result, ErrorInfo = errorInfo };
            _log.Info("Final responce " + JsonConvert.SerializeObject(responce));
            AuditCCHit(ccId, "slprocess", "CommandType : " + commandType, result);
            return responce;
        }