Пример #1
0
        public WSLog Imponer(DB.ViewModels.ImponerWSRequest data)
        {
            DateTime fechaInicio = DateTime.Now;
            DateTime fechaFin    = DateTime.Now;
            string   USER        = ConfigurationManager.AppSettings["USER_WSOCASA"];

            string PASSWORD = ConfigurationManager.AppSettings["PASSWORD_WSOCASA"];

            string json = "{\"security\":{\"login\":\""
                          + USER + "\",\"password\":\""
                          + PASSWORD + "\"},\"pedidos\":[" + this.GetPedidoJSON(data) + "]}";

            string url = ConfigurationManager.AppSettings["WSOCASA"] + "imponer";

            string response = "";

            WSLog wsExternos = new WSLog()
            {
                FechaLlamada   = fechaInicio,
                FechaRespuesta = fechaFin,
                JSONRequest    = json,
                JSONResponse   = response,
                Servicio       = "Imponer",
                Url            = url
            };

            try
            {
                ServiceCaller sc = new ServiceCaller();

                HttpWebResponse webResponse = sc.POST(url, json);

                using (var reader = new System.IO.StreamReader(webResponse.GetResponseStream()))
                {
                    response = reader.ReadToEnd();
                }

                if (response == "")
                {
                    response = "(Vacio)";
                }

                wsExternos.JSONResponse   = response;
                wsExternos.FechaRespuesta = DateTime.Now;
                wsExternos.Estado         = "OK";

                return(wsExternos);
            }
            catch (Exception ex)
            {
                wsExternos.JSONResponse = ex.Message;
                wsExternos.Estado       = "ERROR";
                return(wsExternos);
            }
        }
Пример #2
0
        public object BeforeDo(ref Message request, IClientChannel channel, InstanceContext instanceContext,
                               U9ActionCorrelationState u9ActionCorrelationState)
        {
            if (WebOperationContext.Current == null)
            {
                throw new WebFaultException(HttpStatusCode.BadRequest);
            }
            WSLog wsLog = new WSLog();

            try
            {
                string actionName =
                    OperationContext.Current.IncomingMessageProperties["HttpOperationName"] as string;
                if (string.IsNullOrEmpty(actionName))
                {
                    return(null);
                }
                Type       hostType = OperationContext.Current.Host.Description.ServiceType;
                MethodInfo method   = hostType.GetMethod(actionName);
                if (method == null)
                {
                    return(null);
                }
                //日志属性
                WSLogAttribute attribute =
                    method.GetCustomAttribute(typeof(WSLogAttribute)) as
                    WSLogAttribute;
                if (attribute == null)
                {
                    return(null);
                }
                string logID = WebOperationContext.Current.IncomingRequest.Headers[HeaderLogIDName];
                if (!string.IsNullOrWhiteSpace(logID))
                {
                    wsLog.LogID = long.Parse(logID);
                }
                Uri requestUri = request.Headers.To;
                wsLog.RequestUrl        = requestUri.AbsoluteUri;
                wsLog.EnterpriseID      = PlatformContext.Current.EnterpriseID;
                wsLog.ClassName         = hostType.FullName;
                wsLog.MethodName        = actionName;
                wsLog.MethodDescription = attribute.MethodDescription;
                wsLog.StartTime         = DateTime.Now;
                ReturnMessage <object> returnMessage = new ReturnMessage <object>();
                wsLog.RequestContent = this.MessageToString(ref request, false, ref returnMessage);
                //发送调用前日志
                wsLog.DoBeforeCallLog();
            }
            catch (Exception ex)
            {
                Logger.Error("日志记录异常:{0}", ex);
            }
            return(wsLog);
        }
Пример #3
0
        public override object Do(object obj)
        {
            CreateCallWSLogSV bpObj    = (CreateCallWSLogSV)obj;
            WSLogDTOData      wsLogDTO = bpObj.WSLogDTO;

            if (wsLogDTO == null)
            {
                return(null);
            }
            WSLog wsLog = null;

            using (ISession s = Session.Open())
            {
                if (wsLogDTO.LogID > 0)
                {
                    wsLog = WSLog.Finder.FindByID(wsLogDTO.LogID);
                    if (wsLog == null)
                    {
                        throw new ApplicationExceptionBase(string.Format("LogID:{0} 未找到相应的日志记录", wsLogDTO.LogID));
                    }
                }
                if (wsLog == null)
                {
                    wsLog = WSLog.Create();
                    //RequestUrl	请求地址
                    wsLog.RequestUrl = wsLogDTO.RequestUrl;
                    //ClassName	类名
                    wsLog.ClassName = wsLogDTO.ClassName;
                    //MethodName	方法名
                    wsLog.MethodName = wsLogDTO.MethodName;
                    //MethodDescription 方法描述
                    wsLog.MethodDescription = wsLogDTO.MethodDescription;
                    //RequestContent	请求内容
                    wsLog.RequestContent = wsLogDTO.RequestContent;
                }
                //StartTime	开始时间
                wsLog.StartTime = wsLogDTO.StartTime;
                //EndTime	结束时间
                wsLog.EndTime = wsLogDTO.EndTime;
                //ElapsedSecond	历时(秒)
                wsLog.ElapsedSecond = wsLogDTO.ElapsedSecond;
                //ResponseContent	返回内容
                wsLog.ResponseContent = wsLogDTO.ResponseContent;
                //CallResult	调用结果
                wsLog.CallResult = wsLogDTO.CallResult ? CallResultEnum.Success : CallResultEnum.Failure;
                //ErrorMessage	错误信息
                wsLog.ErrorMessage = wsLogDTO.ErrorMessage;
                //CallCount 请求次数
                wsLog.CallCount++;
                s.Commit();
            }
            return(wsLog.ID);
        }
Пример #4
0
        public override object Do(object obj)
        {
            CreateWSLogSV bpObj    = (CreateWSLogSV)obj;
            WSLogDTO      wsLogDTO = bpObj.WSLogDTO;

            if (wsLogDTO == null)
            {
                return(null);
            }
            using (ISession s = Session.Open())
            {
                WSLog wsLog = null;
                if (wsLogDTO.LogID > 0)
                {
                    wsLog = WSLog.Finder.FindByID(wsLogDTO.LogID);
                }
                if (wsLog == null)
                {
                    wsLog = WSLog.Create();
                    //RequestUrl	请求地址
                    wsLog.RequestUrl = wsLogDTO.RequestUrl;
                    //ClassName	类名
                    wsLog.ClassName = wsLogDTO.ClassName;
                    //MethodName	方法名
                    wsLog.MethodName = wsLogDTO.MethodName;
                    //MethodDescription 方法描述
                    wsLog.MethodDescription = wsLogDTO.MethodDescription;
                    //RequestContent	请求内容
                    wsLog.RequestContent = wsLogDTO.RequestContent;
                }
                //StartTime	开始时间
                wsLog.StartTime = wsLogDTO.StartTime;
                //EndTime	结束时间
                wsLog.EndTime = wsLogDTO.EndTime;
                //ElapsedSecond	历时(秒)
                wsLog.ElapsedSecond = wsLogDTO.ElapsedSecond;
                //ResponseContent	返回内容
                wsLog.ResponseContent = wsLogDTO.ResponseContent;
                //CallResult	调用结果
                wsLog.CallResult = wsLogDTO.CallResult;
                //ErrorMessage	错误信息
                wsLog.ErrorMessage = wsLogDTO.ErrorMessage;
                //CallCount 请求次数
                wsLog.CallCount++;

                s.Commit();
            }

            return(null);
        }
Пример #5
0
 private void GetDbConfig( WSLog.imcTestRun itr)
 {
     string[] ss = itr.getDBconfig(tUser.Text.Trim(), MyMD5.getMd5Hash(tPass.Text));
     try
     {
         string[] sss = ss[0].Split('@')[1].Split(':');
         string address = sss[0];
         int port = int.Parse(sss[1]);
         string data = sss[2];
         string user = ss[1];
         string pass = ss[2];
         OB = new OrcaleDB(address, port, data, user, pass);
     }
     catch { MessageBox.Show("DB Config Failed!"); return; }
 }
Пример #6
0
        public WSLog Consultar(string nroSeguimiento)
        {
            try
            {
                string USER = ConfigurationManager.AppSettings["USER_WSOCASA"];

                DateTime fechaInicio = DateTime.Now;

                string PASSWORD = ConfigurationManager.AppSettings["PASSWORD_WSOCASA"];

                string json = "{\"security\":{\"login\":\""
                              + USER + "\",\"password\":\""
                              + PASSWORD + "\"},\"pedidos\":[{\"nroseguimiento\":\""
                              + nroSeguimiento + "\"}]}";

                string url = ConfigurationManager.AppSettings["WSOCASA"] + "consultar";

                string response = "";

                ServiceCaller sc = new ServiceCaller();

                HttpWebResponse webResponse = sc.POST(url, json);

                using (var reader = new System.IO.StreamReader(webResponse.GetResponseStream()))
                {
                    response = reader.ReadToEnd();
                }

                DateTime fechaFin = DateTime.Now;

                WSLog wsExternos = new WSLog()
                {
                    FechaLlamada   = fechaInicio,
                    FechaRespuesta = fechaFin,
                    JSONRequest    = json,
                    JSONResponse   = response,
                    Servicio       = "Consultar",
                    Url            = url
                };

                return(wsExternos);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
        public GenericResponse <ConsultarWSResponse> ConsultarSeguimiento(string nroSeguimiento)
        {
            GenericResponse <ConsultarWSResponse> response = new GenericResponse <ConsultarWSResponse>();

            response.Code = 200;

            try
            {
                WSExterno.OCASA wsocasa = new WSExterno.OCASA();

                WSLog wsExternos = wsocasa.Consultar(nroSeguimiento);

                Database db = new Database();
                db.WSLog.Add(wsExternos);
                db.SaveChanges();

                string jsonResponse = wsExternos.JSONResponse;

                var consultarResponse = ConsultarWSResponse.Map(jsonResponse);

                response.Result = consultarResponse;
            }
            catch (Exception ex)
            {
                response.Code  = 500;
                response.Error = "Ocurrio un error al comunicarse con OCASA";

                var message      = ex.Message;
                var messageInner = ex.InnerException != null ? ex.InnerException.Message : "";

                DB.Database db2 = new DB.Database();
                db2.Log.Add(new DB.Log()
                {
                    Fecha = DateTime.Now, Ubicacion = UBICACION_LOG, Mensaje = message, Detalle = messageInner
                });

                db2.SaveChanges();
            }

            return(response);
        }
Пример #8
0
        public override object Do(object obj)
        {
            CreateBeforeCallWSLogSV bpObj    = (CreateBeforeCallWSLogSV)obj;
            WSLogDTOData            wsLogDTO = bpObj.WSLogDTO;

            if (wsLogDTO == null)
            {
                return(null);
            }
            WSLog wsLog = null;

            using (ISession s = Session.Open())
            {
                if (wsLogDTO.LogID > 0)
                {
                    wsLog = WSLog.Finder.FindByID(wsLogDTO.LogID);
                }
                else
                {
                    wsLog = WSLog.Create();
                    //RequestUrl	请求地址
                    wsLog.RequestUrl = wsLogDTO.RequestUrl;
                    //ClassName	类名
                    wsLog.ClassName = wsLogDTO.ClassName;
                    //MethodName	方法名
                    wsLog.MethodName = wsLogDTO.MethodName;
                    //MethodDescription 方法描述
                    wsLog.MethodDescription = wsLogDTO.MethodDescription;
                    //RequestContent	请求内容
                    wsLog.RequestContent = wsLogDTO.RequestContent;
                }
                //StartTime	开始时间
                wsLog.StartTime = wsLogDTO.StartTime;
                //CallCount 请求次数
                wsLog.CallCount++;
                s.InList(wsLog);
                s.Commit();
            }
            return(wsLog.ID);
        }
Пример #9
0
        //public void SaveModel()
        //{
        //  SaveFile(_modelFile.FullName);
        //}

        public void Verify()
        {
            if (this.Generator != null)
            {
                if (((INHydrateGenerator)this.Generator).RootController != null)
                {
                    var processKey = UIHelper.ProgressingStarted();
                    try
                    {
                        this.Enabled = false;
                        this.lvwError.ClearMessages();
                        var mList = ((INHydrateGenerator)this.Generator).RootController.Verify();
                        this.lvwError.AddMessages(mList);
                        UIHelper.ProgressingComplete(processKey);

                        var text = "Verification is complete.";
                        if (mList.Count > 0)
                        {
                            text += "\r\nThere are " + mList.Count + " error(s) and warning(s).";
                        }
                        MessageBox.Show(text, "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        UIHelper.ProgressingComplete(processKey);
                        WSLog.LogError(ex);
                        var F = new ErrorForm("An error occurred during the verification process.", ex.ToString());
                        F.ShowDialog();
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                    }
                    finally
                    {
                        UIHelper.ProgressingComplete(processKey);
                        this.Enabled = true;
                    }
                }
            }
        }
Пример #10
0
        public override object Do(object obj)
        {
            CreateAfterCallWSLogSV bpObj    = (CreateAfterCallWSLogSV)obj;
            WSLogDTOData           wsLogDTO = bpObj.WSLogDTO;

            if (wsLogDTO == null)
            {
                return(null);
            }
            if (wsLogDTO.LogID <= 0)
            {
                throw new ApplicationExceptionBase("LogID 不能为空");
            }
            WSLog wsLog = WSLog.Finder.FindByID(wsLogDTO.LogID);

            if (wsLog == null)
            {
                throw new ApplicationExceptionBase(string.Format("LogID:{0} 未找到相应的日志记录", wsLogDTO.LogID));
            }
            using (ISession s = Session.Open())
            {
                //EndTime	结束时间
                wsLog.EndTime = wsLogDTO.EndTime;
                //ElapsedSecond	历时(秒)
                wsLog.ElapsedSecond = wsLogDTO.ElapsedSecond;
                //ResponseContent	返回内容
                wsLog.ResponseContent = wsLogDTO.ResponseContent;
                //CallResult	调用结果
                wsLog.CallResult = wsLogDTO.CallResult ? CallResultEnum.Success : CallResultEnum.Failure;
                //ErrorMessage	错误信息
                wsLog.ErrorMessage = wsLogDTO.ErrorMessage;
                s.InList(wsLog);
                s.Commit();
            }
            return(wsLog.ID);
        }
Пример #11
0
        public GenericResponse <RecepcionResponse> Guardar(GuardarRecepcionRequest data)
        {
            GenericResponse <RecepcionResponse> response = new GenericResponse <RecepcionResponse>();

            try
            {
                response.Code = 200;

                Database db = new Database();

                Pedidos ingreso = new Pedidos();
                ingreso.CodigoBarra      = data.NroSeguimiento;
                ingreso.IdDestinatario   = data.IdDestinatario;
                ingreso.EscaneoDePieza   = data.EscaneoSeguridad;
                ingreso.ImprimirEtiqueta = data.ImprimirEtiqueta;

                ingreso.Estado           = Constants.Pedidos.ID_INGRESADO;
                ingreso.EstadoFecha      = DateTime.Now;
                ingreso.EstadoPor        = data.IdUsuario;
                ingreso.FechaImposicion  = DateTime.Now;
                ingreso.IdSector         = data.IdSectorDestinatario;
                ingreso.IdDireccion      = data.IdDireccionDestinatario;
                ingreso.IdProveedor      = data.IdProveedor;
                ingreso.IdCanalizacion   = data.Canalizacion.Id;
                ingreso.IdTipoDeProducto = data.IdTipoProducto;
                ingreso.NroRemito        = data.NroRemitoProveedor;
                ingreso.NroSeguimiento   = data.NroSeguimiento;
                ingreso.Observacion      = data.Observacion;
                ingreso.NroOrdeDeCompra  = data.NroOrdenCompraProveedor;
                ingreso.UsuarioCreador   = data.IdUsuario;


                if (string.IsNullOrEmpty(data.IdRemitente))
                {
                    data.IdRemitente = ConfigurationManager.AppSettings["ID_USUARIO_REMITENTE_MESA"];
                    Destinatarios usuarioRemitente = db.Destinatarios.Where(x => x.Id == data.IdRemitente).FirstOrDefault();

                    data.IdSectorRemitente    = usuarioRemitente.IdSector;
                    data.IdSucursalRemitente  = usuarioRemitente.IdSucursal;
                    data.IdDireccionRemitente = usuarioRemitente.IdBandeja;
                }

                ingreso.IdRemitente          = (string.IsNullOrEmpty(data.IdRemitente) ? "-" : data.IdRemitente);
                ingreso.IdSectorRemitente    = (string.IsNullOrEmpty(data.IdSectorRemitente) ? "-" : data.IdSectorRemitente);
                ingreso.IdSucursalRemitente  = (string.IsNullOrEmpty(data.IdSucursalRemitente) ? "-" : data.IdSucursalRemitente);
                ingreso.IdDireccionRemitente = (string.IsNullOrEmpty(data.IdDireccionRemitente) ? "-" : data.IdDireccionRemitente);

                if (data.IdArchivo != 0)
                {
                    Archivos archivo = db.Archivos.First(x => x.Id == data.IdArchivo);
                    ingreso.Archivos.Add(archivo);
                }



                if (data.Canalizacion.Id != ConfigurationManager.AppSettings["ID_CANALIZACION_RETIRA_COLABORADOR"] &&
                    data.Canalizacion.Id != ConfigurationManager.AppSettings["ID_CANALIZACION_RETIRA_TERCERO"] &&
                    data.Canalizacion.Id != ConfigurationManager.AppSettings["ID_CANALIZACION_RETIRA_LABORAL"])
                {
                    WSExterno.OCASA wsocasa = new WSExterno.OCASA();

                    ImponerWSRequest dataRequest = new ImponerWSRequest();

                    dataRequest.NroSeguimiento = data.NroSeguimiento;
                    dataRequest.Fecha          = DateTime.Now.ToString("dd/MM/yyyy");
                    dataRequest.TipoProducto   = data.IdTipoProducto.ToString();

                    dataRequest.Proveedor                = new ImponerWSRequest.ImponerProveedorWSRequest();
                    dataRequest.Proveedor.Id             = data.IdProveedor.ToString();
                    dataRequest.Proveedor.NroOrdenCompra = data.NroOrdenCompraProveedor;
                    dataRequest.Proveedor.NroRemito      = data.NroRemitoProveedor;
                    dataRequest.Proveedor.RazonSocial    = data.RazonSocialProveedor;
                    dataRequest.Proveedor.Cuit           = data.CuitProveedor;

                    dataRequest.Remitente          = new ImponerWSRequest.ImponerRemitenteWSRequest();
                    dataRequest.Remitente.Id       = data.IdRemitente;
                    dataRequest.Remitente.Sector   = data.IdSectorRemitente;
                    dataRequest.Remitente.Sucursal = data.IdSucursalRemitente;
                    dataRequest.Remitente.Bandeja  = data.IdDireccionRemitente;

                    dataRequest.Destinatario          = new ImponerWSRequest.ImponerDestinatarioWSRequest();
                    dataRequest.Destinatario.Id       = data.IdDestinatario;
                    dataRequest.Destinatario.Bandeja  = data.IdDireccionDestinatario;
                    dataRequest.Destinatario.Sector   = data.IdSectorDestinatario;
                    dataRequest.Destinatario.Sucursal = data.IdSucursalDestinatario;

                    dataRequest.Observacion  = data.Observacion;
                    dataRequest.Canalizacion = data.Canalizacion.Id.ToString();

                    WSLog wsExternos = wsocasa.Imponer(dataRequest);

                    ImponerWSResponse responseWs = ImponerWSResponse.Map(wsExternos.JSONResponse);

                    db.WSLog.Add(wsExternos);
                    db.SaveChanges();

                    if (wsExternos.Estado != "ERROR")
                    {
                        var codebar = responseWs.Pedidos[0].CodigoBarra;

                        if (string.IsNullOrEmpty(codebar))
                        {
                            codebar = ingreso.NroSeguimiento;
                        }

                        ingreso.CodigoBarra = codebar;
                    }

                    string jsonResponse = wsExternos.JSONResponse;
                }

                ingreso = db.Pedidos.Add(ingreso);
                db.SaveChanges();

                if (data.Canalizacion.Id == ConfigurationManager.AppSettings["ID_CANALIZACION_RETIRA_COLABORADOR"] ||
                    data.Canalizacion.Id == ConfigurationManager.AppSettings["ID_CANALIZACION_RETIRA_TERCERO"] ||
                    data.Canalizacion.Id == ConfigurationManager.AppSettings["ID_CANALIZACION_RETIRA_LABORAL"])
                {
                    Engresos egreso = new Engresos
                    {
                        Fecha = DateTime.Now
                    };
                    egreso = db.Engresos.Add(egreso);

                    db.SaveChanges();

                    EgresoPedidos egreped = new EgresoPedidos
                    {
                        IdEgreso = egreso.Id,
                        IdPedido = ingreso.Id
                    };

                    db.EgresoPedidos.Add(egreped);

                    ingreso.Estado      = Constants.Pedidos.ID_DISPONIBLE_PARA_RETIRO;
                    ingreso.EstadoFecha = DateTime.Now;
                    ingreso.EstadoPor   = data.IdUsuario;

                    ingreso.CodigoBarra = ingreso.Id.ToString().PadLeft(13, '0');

                    db.SaveChanges();
                }

                response.Result = new RecepcionResponse()
                {
                    NroSeguimiento = ingreso.NroSeguimiento, IdIngreso = ingreso.Id, CodigoBarra = ingreso.CodigoBarra
                };
            }
            catch (Exception ex)
            {
                response.Code  = 500;
                response.Error = ex.Message;

                var message      = ex.Message;
                var messageInner = ex.InnerException != null ? ex.InnerException.Message : "";

                DB.Database db2 = new DB.Database();
                db2.Log.Add(new DB.Log()
                {
                    Fecha = DateTime.Now, Ubicacion = UBICACION_LOG, Mensaje = message, Detalle = messageInner
                });

                db2.SaveChanges();
            }

            return(response);
        }
Пример #12
0
        public string NotificarNuevoEstado(int estado, string codigoBarra, string email = "usuario@servicio", string fecha = null)
        {
            WSLog log = new WSLog();

            try
            {
                Database db = new Database();

                log = new WSLog()
                {
                    FechaLlamada = DateTime.Now, FechaRespuesta = DateTime.Now, JSONRequest = "estado: " + estado.ToString() + "; codigoBarra: " + codigoBarra + "; email: " + email + "; fecha: " + fecha, JSONResponse = "En proceso", Servicio = "NotificacionEstado", Url = "http://externo"
                };
                db.WSLog.Add(log);
                db.SaveChanges();

                DateTime fechaOperacion = DateTime.Now;
                if (!string.IsNullOrEmpty(fecha))
                {
                    fechaOperacion = DateTime.Parse(fecha);
                }

                Pedidos pedido = db.Pedidos.Where(x => x.CodigoBarra == codigoBarra).FirstOrDefault();

                if (pedido != null)
                {
                    if (estado == Constants.Pedidos.ID_CANCELADO && pedido.Estado != Constants.Pedidos.ID_DISPONIBLE_PARA_RETIRO)//quieren Cancelar y está Disponible para retiro
                    {
                        log.JSONResponse = "El pedido no se encuentra en estado para ser cancelado.";
                    }
                    else
                    {
                        pedido.Estado = estado;

                        Usuarios usuario = db.Usuarios.Where(x => x.email == email).FirstOrDefault();
                        if (usuario == null)
                        {
                            usuario = new Usuarios()
                            {
                                email    = email,
                                password = "******"
                            };
                            db.Usuarios.Add(usuario);
                            db.SaveChanges();
                        }

                        pedido.CanceladoPor     = usuario.id;
                        pedido.FechaCancelacion = fechaOperacion;

                        pedido.EstadoFecha = fechaOperacion;
                        pedido.EstadoPor   = usuario.id;

                        log.JSONResponse = "Pedido modificado: " + pedido.Id;
                    }

                    log.FechaRespuesta = DateTime.Now;
                    db.SaveChanges();

                    return(log.JSONResponse);
                }
                else
                {
                    log.FechaRespuesta = DateTime.Now;
                    log.JSONResponse   = "El pedido " + codigoBarra + " no se encuentra en el sistema";
                    db.SaveChanges();

                    throw new Exception(log.JSONResponse);
                }
            }
            catch (Exception ex)
            {
                var message      = ex.Message;
                var messageInner = ex.InnerException != null ? ex.InnerException.Message : "";

                Database db2 = new Database();
                db2.Log.Add(new Log()
                {
                    Fecha = DateTime.Now, Ubicacion = "WS", Mensaje = message, Detalle = messageInner
                });

                log.JSONResponse   = "Error al cambiar estado:" + message;
                log.FechaRespuesta = DateTime.Now;

                db2.SaveChanges();

                return("Error al cambiar estado:" + message);
            }
        }
Пример #13
0
        public string NotificarPedido(Pedido pedido)
        {
            WSLog log = new WSLog();

            try
            {
                Database db = new Database();

                log = new WSLog()
                {
                    FechaLlamada = DateTime.Now, FechaRespuesta = DateTime.Now, JSONRequest = pedido.ToString(), JSONResponse = "En proceso", Servicio = "Notificacion", Url = "http://externo"
                };
                db.WSLog.Add(log);
                db.SaveChanges();

                Pedidos ingreso = new Pedidos();

                ingreso.CodigoBarra = pedido.CodigoBarra;
                ingreso.Observacion = pedido.Observacion;
                //RF
                ingreso.Estado = Constants.Pedidos.ID_DISPONIBLE_PARA_RETIRO; //Disponible para retiro

                Usuarios usuario = db.Usuarios.Where(x => x.email == "usuario@servicio").FirstOrDefault();
                if (usuario != null)
                {
                    ingreso.EstadoPor = usuario.id;
                }
                ingreso.EstadoFecha = DateTime.Now;


                Direcciones direccion = db.Direcciones.Where(x => x.Id == pedido.Destinatario.Bandeja).FirstOrDefault();

                if (direccion != null)
                {
                    ingreso.IdDireccion = direccion.Id;
                }
                else
                {
                    direccion             = new Direcciones();
                    direccion.Id          = pedido.Destinatario.Bandeja;
                    direccion.Descripcion = pedido.Destinatario.DescripcionBandeja;

                    db.Direcciones.Add(direccion);

                    db.SaveChanges();

                    ingreso.IdDireccion = direccion.Id;
                }

                Sectores sector = db.Sectores.Where(x => x.Id == pedido.Destinatario.Sector).FirstOrDefault();

                if (sector != null)
                {
                    ingreso.IdSector = sector.Id;
                }
                else
                {
                    sector             = new Sectores();
                    sector.Id          = pedido.Destinatario.Sector;
                    sector.Descripcion = pedido.Destinatario.DescripcionSector;

                    db.Sectores.Add(sector);

                    db.SaveChanges();

                    ingreso.IdSector = sector.Id;
                }

                DB.Destinatarios destinatario = db.Destinatarios.Where(x => x.Id == pedido.Destinatario.Id).FirstOrDefault();

                if (destinatario != null)
                {
                    ingreso.IdDestinatario = destinatario.Id;
                }
                else
                {
                    destinatario                           = new DB.Destinatarios();
                    destinatario.Id                        = pedido.Destinatario.Id;
                    destinatario.IdBandeja                 = pedido.Destinatario.Bandeja;
                    destinatario.IdSector                  = pedido.Destinatario.Sector;
                    destinatario.IdCentroDeCostos          = pedido.Destinatario.CentroDeCostos;
                    destinatario.NombreDeUsuario           = pedido.Destinatario.Nombre;
                    destinatario.IdSucursal                = pedido.Destinatario.Sucursal;
                    destinatario.DescripcionBandeja        = pedido.Destinatario.DescripcionBandeja;
                    destinatario.DescripcionCentroDeCostos = pedido.Destinatario.DescripcionCentroCostos;
                    destinatario.DescripcionSector         = pedido.Destinatario.DescripcionSector;

                    db.Destinatarios.Add(destinatario);

                    db.SaveChanges();

                    ingreso.Destinatarios = destinatario;
                }

                ingreso.NroOrdeDeCompra  = pedido.NroDeOrdenCompra;
                ingreso.UsuarioCreador   = 2;
                ingreso.IdTipoDeProducto = int.Parse(pedido.TipoProducto);
                ingreso.IdProveedor      = int.Parse(pedido.Proveedor.Id);

                ingreso.NroSeguimiento       = pedido.NroSeguimiento;
                ingreso.IdCanalizacion       = pedido.Destinatario.Canalizacion;
                ingreso.IdRemitente          = pedido.Remitente.Id;
                ingreso.IdSectorRemitente    = pedido.Remitente.Sector;
                ingreso.IdDireccionRemitente = pedido.Remitente.Bandeja;
                ingreso.IdSucursalRemitente  = pedido.Remitente.Sucursal;

                ingreso.NroRemito        = "";
                ingreso.EscaneoDePieza   = false;
                ingreso.ImprimirEtiqueta = false;
                ingreso.FechaImposicion  = DateTime.Now;

                ingreso.AutorizadoRetirar = pedido.AutorizadoRetirar;

                log.FechaRespuesta = DateTime.Now;

                db.Pedidos.Add(ingreso);

                db.SaveChanges();

                log.JSONResponse = "Pedido: " + ingreso.Id;

                db.SaveChanges();

                if (pedido.Destinatario.Canalizacion == "3" || pedido.Destinatario.Canalizacion == "5")
                {
                    DB.Engresos egreso = new DB.Engresos();
                    egreso.Fecha = DateTime.Now;
                    egreso       = db.Engresos.Add(egreso);

                    db.SaveChanges();

                    DB.EgresoPedidos egreped = new DB.EgresoPedidos();
                    egreped.IdEgreso = egreso.Id;
                    egreped.IdPedido = ingreso.Id;

                    db.EgresoPedidos.Add(egreped);

                    db.SaveChanges();
                }

                return("Pedido: " + ingreso.Id);
            }
            catch (Exception ex)
            {
                var message      = ex.Message;
                var messageInner = ex.InnerException != null ? ex.InnerException.Message : "";

                Database db2 = new Database();
                db2.Log.Add(new Log()
                {
                    Fecha = DateTime.Now, Ubicacion = "WS", Mensaje = message, Detalle = messageInner
                });

                log.JSONResponse   = "Error al generar Pedido:" + message;
                log.FechaRespuesta = DateTime.Now;

                db2.SaveChanges();

                return("Error al generar Pedido:" + message);
            }
        }
Пример #14
0
        public GenericResponse <bool> Cancel(string codeBar, int idUsuario)
        {
            try
            {
                Database db = new Database();

                WSExterno.OCASA wsocasa = new WSExterno.OCASA();

                WSLog wsExternos = wsocasa.Cancelar(codeBar);

                db.WSLog.Add(wsExternos);
                db.SaveChanges();

                string  jsonResponse = wsExternos.JSONResponse;
                dynamic jobject      = JValue.Parse(jsonResponse);
                //jsonRespone["Status"]
                if (jobject.Status == true)
                {
                    Database context = new Database();
                    Pedidos  pedidos = context.Pedidos.Where(x => x.CodigoBarra == codeBar).FirstOrDefault();
                    pedidos.Estado = Constants.Pedidos.ID_CANCELADO;

                    pedidos.EstadoFecha = DateTime.Now;
                    pedidos.EstadoPor   = idUsuario;

                    pedidos.FechaCancelacion = DateTime.Now;
                    pedidos.CanceladoPor     = idUsuario;
                    context.SaveChanges();

                    return(new GenericResponse <bool>()
                    {
                        Code = 200, Result = true
                    });
                }
                else
                {
                    return(new GenericResponse <bool>()
                    {
                        Code = 500, Error = "No se puede cancelar el pedido"
                    });
                }
            }
            catch (Exception ex)
            {
                var message      = ex.Message;
                var messageInner = ex.InnerException != null ? ex.InnerException.Message : "";

                Database db2 = new Database();
                db2.Log.Add(new Log()
                {
                    Fecha = DateTime.Now, Ubicacion = Constants.LOG_UBICACION_REPORTES, Mensaje = message, Detalle = messageInner
                });

                db2.SaveChanges();

                return(new GenericResponse <bool>()
                {
                    Code = 500, Error = ex.Message
                });
            }
        }