Пример #1
0
        public eAlmacenamiento Guardar(DSDataContext dcOri)
        {
            try
            {
                DSDataContext   dc   = dcOri;
                eAlmacenamiento fila = new eAlmacenamiento();
                fila.modelo = this.modelo;

                if (this.id == 0)
                {
                    dc.eAlmacenamientos.InsertOnSubmit(fila);
                }
                else
                {
                    var res = from x in dc.eAlmacenamientos where x.id == this.id select x;
                    if (res.Count() > 0)
                    {
                        fila        = res.First();
                        fila.modelo = this.modelo;
                    }
                    else
                    {
                        throw new Exception("Id no encontrado en Almacenamiento");
                    }
                }
                return(fila);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public void Guardar()
        {
            DSDataContext   dc   = new DSDataContext(Conexion.DarStrConexion());
            eAlmacenamiento fila = new eAlmacenamiento();

            if (this.id != 0) //detectamos que es uno nuevo
            {
                var res = from x in dc.eAlmacenamientos where x.id == this.id select x;
                if (res.Count() > 0)
                {
                    fila = res.First();
                }
                else //no lo encontramos.. mostramos error
                {
                    throw new Exception("Id no encontrado en Almacenamiento");
                }
            }


            fila.modelo    = modelo;
            fila.capacidad = capacidad;
            fila.velocidad = velocidad;
            fila.tipo      = tipo;
            fkMarca        = Marca.Id;

            if (this.Marca.Id == 0)
            {
                fila.eMarca = this.Marca.Guardar(dc);
            }
            else
            {
                fila.idMarca = fkMarca;
            }

            if (this.id == 0)
            {
                dc.eAlmacenamientos.InsertOnSubmit(fila);
            }

            dc.SubmitChanges();
            this.id = fila.id;
        }