示例#1
0
        public IHttpActionResult Postactivos(activos activos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (activos.fecha_baja > activos.fecha_compra)
            {
                return(BadRequest("La Fecha de Baja no puede ser mayor a la Fecha de Compra"));
            }

            db.activos.Add(activos);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                if (activosExists(activos.id_activo))
                {
                    return(InternalServerError(ex.GetBaseException()));
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Registro Insertado Correctamente"));
        }
示例#2
0
        public void Insertar(int id, string nombre, string descripcion, string color,
                             double valor, string serial, string tipo, string inventario, string peso,
                             string ancho, string alto, string largo, string estado, DateTime compra, DateTime baja)
        {
            activos a = new activos();

            a.id_activo      = id;
            a.nombre         = nombre;
            a.descripcion    = descripcion;
            a.color          = color;
            a.valor_compra   = valor;
            a.serial         = serial;
            a.tipo           = tipo;
            a.num_inventario = inventario;
            a.peso           = peso;
            a.ancho          = ancho;
            a.alto           = alto;
            a.largo          = largo;
            a.estado         = estado;
            a.fecha_compra   = compra;
            a.fecha_baja     = baja;

            activosController ac = new activosController();

            ac.Postactivos(a);
        }
示例#3
0
        public IHttpActionResult Getactivo(int id)
        {
            activos activos = db.activos.Find(id);

            if (activos == null)
            {
                return(NotFound());
            }

            return(Ok(activos));
        }
示例#4
0
        public IHttpActionResult Putactivos(int id, activos activos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (activos.serial.Equals(""))
            {
                return(BadRequest("El serial es obligatorio"));
            }

            if (id != activos.id_activo)
            {
                return(BadRequest("El ID no es el mismo"));
            }
            if (activos.fecha_baja > activos.fecha_compra)
            {
                return(BadRequest("La Fecha de Baja no puede ser mayor a la Fecha de Compra"));
            }

            db.Entry(activos).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!activosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw ex.GetBaseException();
                }
            }

            return(Ok("Registro Actualizado Correctamente"));
        }