Пример #1
0
        // POST api/<controller>
        public object Post(string data, string token)
        {
            string payload     = "";
            string newToken    = "";
            bool   tokenValido = ManageTokens.Instance.ValidateToken(token, out payload, out newToken);

            if (tokenValido)
            {
                JavaScriptSerializer serializer    = new JavaScriptSerializer();
                ItemCodeJson         DatosItemCode = serializer.Deserialize <ItemCodeJson>(data);
                Sam3_Usuario         usuario       = serializer.Deserialize <Sam3_Usuario>(payload);
                return(ItemCodeBd.Instance.GuardarItemCodePopUp(DatosItemCode, usuario));
            }
            else
            {
                TransactionalInformation result = new TransactionalInformation();
                result.ReturnMessage.Add(payload);
                result.ReturnCode     = 401;
                result.ReturnStatus   = false;
                result.IsAuthenicated = false;
                return(result);
            }
        }
Пример #2
0
        /// <summary>
        /// Obtener el detalle de un item code steelgo
        /// </summary>
        /// <param name="itemCodeSteelgoID">item code steelgo seleccionado</param>
        /// <param name="usuario">usuario actual</param>
        /// <returns>objeto con la informacion del item code steelgo</returns>
        public object ObtenerDetalleRelacionitemCodeSteelgo(string ItemCode, string diam1, string diam2, int mm, Sam3_Usuario usuario, int proyectoID)
        {
            try
            {
                using (SamContext ctx = new SamContext())
                {
                    Sam3_ItemCode item      = ctx.Sam3_ItemCode.Where(x => x.Codigo == ItemCode && x.Activo && x.ProyectoID == proyectoID).FirstOrDefault();
                    decimal       diametro1 = diam1 != "" ? Convert.ToDecimal(diam1) : 0;
                    decimal       diametro2 = diam2 != "" ? Convert.ToDecimal(diam2) : 0;

                    int diametro1IID = (from d in ctx.Sam3_Diametro
                                        where d.Activo && d.Valor == diametro1
                                        select d.DiametroID).AsParallel().SingleOrDefault();

                    int diametro2ID = (from d in ctx.Sam3_Diametro
                                       where d.Activo && d.Valor == diametro2
                                       select d.DiametroID).AsParallel().SingleOrDefault();

                    ItemCodeJson detalle = new ItemCodeJson();

                    detalle = (from r in ctx.Sam3_ItemCode
                               join rid in ctx.Sam3_Rel_ItemCode_Diametro on r.ItemCodeID equals rid.ItemCodeID
                               join riit in ctx.Sam3_Rel_ItemCode_ItemCodeSteelgo on rid.Rel_ItemCode_Diametro_ID equals riit.Rel_ItemCode_Diametro_ID
                               join rids in ctx.Sam3_Rel_ItemCodeSteelgo_Diametro on riit.Rel_ItemCodeSteelgo_Diametro_ID equals rids.Rel_ItemCodeSteelgo_Diametro_ID
                               join ics in ctx.Sam3_ItemCodeSteelgo on rids.ItemCodeSteelgoID equals ics.ItemCodeSteelgoID
                               join d1 in ctx.Sam3_Diametro on rid.Diametro1ID equals d1.DiametroID
                               join d2 in ctx.Sam3_Diametro on rid.Diametro2ID equals d2.DiametroID
                               where r.Activo && riit.Activo && ics.Activo && rid.Activo && d1.Activo && d2.Activo &&
                               r.ItemCodeID == item.ItemCodeID && d1.DiametroID == diametro1IID && d2.DiametroID == diametro2ID
                               select new ItemCodeJson
                    {
                        ItemCodeID = rid.Rel_ItemCode_Diametro_ID,
                        ItemCode = r.Codigo,
                        //ColadaNombre = (from c in ctx.Sam3_Colada where c.ColadaID == r.ColadaID && c.Activo select c.NumeroColada).FirstOrDefault(),
                        Cantidad = r.Cantidad,
                        MM = mm,
                        Descripcion = r.DescripcionEspanol,
                        Diametro1 = d1.Valor,
                        Diametro2 = d2.Valor,
                        FamiliaAcero = (from f in ctx.Sam3_FamiliaAcero where f.FamiliaAceroID == ics.FamiliaAceroID && f.Activo select f.Nombre).FirstOrDefault(),
                        ItemCodeSteelgoID = rids.Rel_ItemCodeSteelgo_Diametro_ID.ToString(),
                        ItemCodeSteelgo = ics.Codigo,
                        TipoAcero = (from rics in ctx.Sam3_Rel_ItemCode_ItemCodeSteelgo
                                     join rdis in ctx.Sam3_Rel_ItemCodeSteelgo_Diametro on rics.Rel_ItemCodeSteelgo_Diametro_ID equals rids.Rel_ItemCodeSteelgo_Diametro_ID
                                     join itcs in ctx.Sam3_ItemCodeSteelgo on rdis.ItemCodeSteelgoID equals ics.ItemCodeSteelgoID
                                     join fa in ctx.Sam3_FamiliaAcero on itcs.FamiliaAceroID equals fa.FamiliaAceroID
                                     join fm in ctx.Sam3_FamiliaMaterial on fa.FamiliaMaterialID equals fm.FamiliaMaterialID
                                     where rics.Activo && itcs.Activo &&
                                     rics.Rel_ItemCode_ItemCodeSteelgo == riit.Rel_ItemCode_ItemCodeSteelgo
                                     select fm.Nombre).FirstOrDefault(),
                        //ColadaID = r.ColadaID
                        ItemCodeOrigenID = r.ItemCodeID,
                        TipoPackingList = r.TipoMaterialID,
                        TextoTipoPackingList = (from tm in ctx.Sam3_TipoMaterial
                                                where tm.TipoMaterialID == r.TipoMaterialID
                                                select tm.Nombre).FirstOrDefault()
                    }).AsParallel().SingleOrDefault();

                    if (detalle != null)
                    {
                        string diametro = (from ricsd in ctx.Sam3_Rel_ItemCodeSteelgo_Diametro
                                           join ics in ctx.Sam3_ItemCodeSteelgo on ricsd.ItemCodeSteelgoID equals ics.ItemCodeSteelgoID
                                           join cat in ctx.Sam3_CatalogoCedulas on ics.CedulaID equals cat.CatalogoCedulasID
                                           join d in ctx.Sam3_Diametro on cat.DiametroID equals d.DiametroID
                                           where ricsd.Rel_ItemCodeSteelgo_Diametro_ID.ToString() == detalle.ItemCodeSteelgoID &&
                                           ricsd.Activo && ics.Activo && cat.Activo && d.Activo
                                           select d.Valor.ToString()).AsParallel().SingleOrDefault();

                        string cedulaA = (from ricsd in ctx.Sam3_Rel_ItemCodeSteelgo_Diametro
                                          join ics in ctx.Sam3_ItemCodeSteelgo on ricsd.ItemCodeSteelgoID equals ics.ItemCodeSteelgoID
                                          join cat in ctx.Sam3_CatalogoCedulas on ics.CedulaID equals cat.CatalogoCedulasID
                                          join ced in ctx.Sam3_Cedula on cat.CedulaA equals ced.CedulaID
                                          where ricsd.Rel_ItemCodeSteelgo_Diametro_ID.ToString() == detalle.ItemCodeSteelgoID &&
                                          ricsd.Activo && ics.Activo && cat.Activo && ced.Activo
                                          select ced.Codigo).AsParallel().SingleOrDefault();

                        string cedulaB = (from ricsd in ctx.Sam3_Rel_ItemCodeSteelgo_Diametro
                                          join ics in ctx.Sam3_ItemCodeSteelgo on ricsd.ItemCodeSteelgoID equals ics.ItemCodeSteelgoID
                                          join cat in ctx.Sam3_CatalogoCedulas on ics.CedulaID equals cat.CatalogoCedulasID
                                          join ced in ctx.Sam3_Cedula on cat.CedulaB equals ced.CedulaID
                                          where ricsd.Rel_ItemCodeSteelgo_Diametro_ID.ToString() == detalle.ItemCodeSteelgoID &&
                                          ricsd.Activo && ics.Activo && cat.Activo && ced.Activo
                                          select ced.Codigo).AsParallel().SingleOrDefault();

                        string cedulaC = (from ricsd in ctx.Sam3_Rel_ItemCodeSteelgo_Diametro
                                          join ics in ctx.Sam3_ItemCodeSteelgo on ricsd.ItemCodeSteelgoID equals ics.ItemCodeSteelgoID
                                          join cat in ctx.Sam3_CatalogoCedulas on ics.CedulaID equals cat.CatalogoCedulasID
                                          join ced in ctx.Sam3_Cedula on cat.CedulaC equals ced.CedulaID
                                          where ricsd.Rel_ItemCodeSteelgo_Diametro_ID.ToString() == detalle.ItemCodeSteelgoID &&
                                          ricsd.Activo && ics.Activo && cat.Activo && ced.Activo
                                          select ced.Codigo).AsParallel().SingleOrDefault();

                        detalle.Cedula = diametro + " - " + cedulaA + " - " + cedulaB + " - " + cedulaC;

                        return(detalle);
                    }
                    else
                    {
                        detalle = (from r in ctx.Sam3_ItemCode
                                   join rid in ctx.Sam3_Rel_ItemCode_Diametro on r.ItemCodeID equals rid.ItemCodeID
                                   join d1 in ctx.Sam3_Diametro on rid.Diametro1ID equals d1.DiametroID
                                   join d2 in ctx.Sam3_Diametro on rid.Diametro2ID equals d2.DiametroID
                                   where r.Activo && rid.Activo &&
                                   r.ItemCodeID == item.ItemCodeID &&
                                   d1.DiametroID == diametro1IID &&
                                   d2.DiametroID == diametro2ID
                                   select new ItemCodeJson
                        {
                            ItemCodeID = rid.Rel_ItemCode_Diametro_ID,
                            ItemCode = r.Codigo + "(" + d1.Valor + ", " + d2.Valor + ")",
                            Diametro1 = d1.Valor,
                            Diametro2 = d2.Valor,
                            //ColadaNombre = (from c in ctx.Sam3_Colada where c.ColadaID == r.ColadaID && c.Activo select c.NumeroColada).FirstOrDefault(),
                            Cantidad = r.Cantidad,
                            MM = mm,
                            Descripcion = r.DescripcionEspanol,
                            ItemCodeOrigenID = r.ItemCodeID,
                            TipoPackingList = r.TipoMaterialID,
                            TextoTipoPackingList = (from tm in ctx.Sam3_TipoMaterial
                                                    where tm.TipoMaterialID == r.TipoMaterialID
                                                    select tm.Nombre).FirstOrDefault()
                        }).AsParallel().SingleOrDefault();
                        return(detalle);
                    }
                }
            }
            catch (Exception ex)
            {
                //-----------------Agregar mensaje al Log -----------------------------------------------
                LoggerBd.Instance.EscribirLog(ex);
                //-----------------Agregar mensaje al Log -----------------------------------------------
                TransactionalInformation result = new TransactionalInformation();
                result.ReturnMessage.Add(ex.Message);
                result.ReturnCode     = 500;
                result.ReturnStatus   = false;
                result.IsAuthenicated = true;

                return(result);
            }
        }