Exemple #1
0
        public IHttpActionResult GetCustodyInfo([FromUri] GetCustodyInfoRequest obj)
        {
            try
            {
                // Send object to business layer
                CustodyController core = new CustodyController();

                // Verify at least object arrives with data
                if (obj == null)
                {
                    throw new NotEnoughAttributesException("No se ha recibido ningún parámetro");
                }

                // Verify for parameters needed
                if (obj.code == null || obj.idProduct == null || obj.restrictive == null)
                {
                    throw new NotEnoughAttributesException("No se han recibido todos los parámetros requeridos");
                }

                // Check params's integrity
                if (obj.code.GetType() != typeof(string) ||
                    obj.idProduct.GetType() != typeof(int) ||
                    obj.restrictive.GetType() != typeof(int))
                {
                    throw new NotEnoughAttributesException("Los tipos de datos no coinciden");
                }

                // Call action
                ActionResponse action = core.GetCustodyInfoAction(obj.code, obj.idProduct.Value, obj.restrictive.Value);

                if (action.code == (int)CodeStatusEnum.OK)
                {
                    return(ResponseOk(action.data));
                }                                                                              // OK
                else
                {
                    return(ResponseError(action.code, action.message));
                }                                                           // NOK
            }
            catch (NotValidDataException e)
            {
                logger.Error(e.Message);
                return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message));
            }
            catch (NotEnoughAttributesException e)
            {
                logger.Error(e.Message);
                return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(ResponseError((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema"));
            }
        }
Exemple #2
0
        public IHttpActionResult GetCustodyByCode([FromBody] RegisterRequest obj)
        {
            try
            {
                CustodyController oCustody = new CustodyController();

                // Check for data
                if (obj == null)
                {
                    throw new NotEnoughAttributesException("No se ha recibido ningún parámetro");
                }

                // Find Custody object linked to code received
                Custody custody = oCustody.FindCustodyByCode(obj.idProduct.Value, obj.code, obj.codeType);
                if (custody == null)
                {
                    throw new NotValidDataException("No hay ninguna custodia vinculada al código proporcionado");
                }

                // OK

                /*output.code = 0;
                 * output.message = "OK";
                 * output.result = custody.value;*/
                ActionResponse output = new ActionResponse();

                return(Ok(output));
            }
            catch (NotValidDataException e)
            {
                logger.Error(e.Message);
                return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message));
            }
            catch (NotEnoughAttributesException e)
            {
                logger.Error(e.Message);
                return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message));
            }
            catch (Exception ex)
            {
                logger.Fatal(ex.Message);
                return(ResponseError((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema"));
            }
        }
Exemple #3
0
        public IHttpActionResult CustodyRequestFromPlatform()
        {
            try
            {
                // Parameters sent by platform (GET)
                var request = Request;

                string ani        = functions.GetQueryString(request, "ani");
                string text       = functions.GetQueryString(request, "text");
                string nc         = functions.GetQueryString(request, "nc");
                string op         = functions.GetQueryString(request, "op");
                string id         = functions.GetQueryString(request, "id");
                string cfield1    = functions.GetQueryString(request, "cfield1");
                string lista      = functions.GetQueryString(request, "lista");
                string campEnvio1 = functions.GetQueryString(request, "campEnvio1");
                string campEnvio2 = functions.GetQueryString(request, "campEnvio2");
                string campCobro  = functions.GetQueryString(request, "campCobro");

                // Custom params
                string idProduct = functions.GetQueryString(request, "idProduct");
                string value     = functions.GetQueryString(request, "value"); // value to be stored


                // Check for vital data
                if (idProduct == null || ani == null || value == null)
                {
                    throw new NotEnoughAttributesException("No se han recibido todos los parámetros requeridos");
                }


                // Create object to send it to business layer and process it
                CustodyRequest req = new CustodyRequest();
                req.idProduct  = (int)Int32.Parse(idProduct);
                req.value      = value;
                req.valChannel = ani;
                req.sendSms    = true;

                // Business's logic controllers, core
                CustodyController core   = new CustodyController();
                ActionResponse    action = core.CustodyRequestFromPlatformAction(req.idProduct.Value, ani, value);

                if (action.code == (int)CodeStatusEnum.OK)
                {
                    return(ResponseOk(action.data));
                }                                                                              // OK
                else
                {
                    return(ResponseError(action.code, action.message));
                }                                                           // NOK
            }
            catch (NotValidDataException e)
            {
                logger.Error(e.Message);
                return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message));
            }
            catch (NotEnoughAttributesException e)
            {
                logger.Error(e.Message);
                return(ResponseError((int)CodeStatusEnum.BAD_REQUEST, e.Message));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(ResponseError((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema"));
            }
        }