Ejemplo n.º 1
0
        public IHttpActionResult PutTv(int id, Tv tv)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tv.Id)
            {
                return(BadRequest());
            }
            db.Entry(tv).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
 public void Edit(ElectrDevice device)
 {
     dbDevices.Entry(device).State = EntityState.Modified;
     dbDevices.SaveChanges();
 }
Ejemplo n.º 3
0
        public ActionResult TurnOffOn(int?parametr, string id)
        {
            if (parametr == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ElectrDevice device = null;

            switch (id)
            {
            case "Illuminator":
                device = db.Illuminators.Find(parametr);
                if (device == null)
                {
                    return(HttpNotFound());
                }
                if (device.OnOff)
                {
                    device.TurnOff();
                    ((Illuminator)device).Img = "/Content/Images/off-lamp.png";
                }
                else
                {
                    device.TurnOn();
                    ((Illuminator)device).Img = "/Content/Images/low.png";
                }
                db.Entry((Illuminator)device).State = EntityState.Modified;
                break;

            case "Alarm":
                device = db.Alarms.Find(parametr);
                if (device == null)
                {
                    return(HttpNotFound());
                }
                if (device.OnOff)
                {
                    device.TurnOff();
                    ((Alarm)device).Img = "/Content/Images/alarm-off.png";
                }
                else
                {
                    device.TurnOn();
                    ((Alarm)device).Img = "/Content/Images/alarm-no.png";
                }
                db.Entry((Alarm)device).State = EntityState.Modified;
                break;

            case "Fridge":
                device = db.Fridges.Find(parametr);
                if (device == null)
                {
                    return(HttpNotFound());
                }
                if (device.OnOff)
                {
                    device.TurnOff();
                }
                else
                {
                    device.TurnOn();
                }
                db.Entry((Fridge)device).State = EntityState.Modified;
                break;

            case "Microwave":
                device = db.Microwaves.Find(parametr);
                if (device == null)
                {
                    return(HttpNotFound());
                }
                if (device.OnOff)
                {
                    device.TurnOff();
                    if (((Microwave)device).OpenClose)
                    {
                        ((Microwave)device).Img = "/Content/Images/icon/microwaveoffop.png";
                    }
                    else
                    {
                        ((Microwave)device).Img = "/Content/Images/icon/micrrocloseoff.png";
                    }
                }
                else
                {
                    device.TurnOn();
                    if (((Microwave)device).OpenClose)
                    {
                        ((Microwave)device).Img = "/Content/Images/microwave-open.png";
                    }
                    else
                    {
                        ((Microwave)device).Img = "/Content/Images/microwave-close.png";
                    }
                }
                db.Entry((Microwave)device).State = EntityState.Modified;
                break;
            }

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }