コード例 #1
0
ファイル: DeviceController.cs プロジェクト: gorova2006/Smart
        public ActionResult Edit(int id, string TypeDev, string Com)
        {
            dc = new DevicesContext();
            if (typeof(Heating).ToString() == TypeDev)
            {
                Heating h = dc.heatings.Find(id);
                if (Com == "+")
                    h.Temperature += 1;
                else if (Com == "-")
                    h.Temperature -= 1;
                else if (Com == "Вкл/Выкл")
                    h.OnOff();
                dc.Entry(h).State = EntityState.Modified;
                dc.SaveChanges();
                return View(h);
            }
            else if (typeof(TV).ToString() == TypeDev)
            {
                TV tv = dc.tvsets.Find(id);
                tv.tvsettings.tv = tv;
                if (Com == "Вкл/Выкл")
                    tv.OnOff();
                else if (tv.Status)
                {
                    if (Com == "Громкость+")
                        tv.tvsettings.AddVolume();

                    else if (Com == "Громкость-")
                        tv.tvsettings.SubVolume();

                    else if (Com == "Резкость+")
                        tv.tvsettings.AddAbruptness();

                    else if (Com == "Резкость-")
                        tv.tvsettings.SubAbruptness();

                    else if (Com == "Контраст+")
                        tv.tvsettings.AddContrast();

                    else if (Com == "Контраст-")
                        tv.tvsettings.SubContrast();

                    else if (Com == "<-")
                        tv.PreviousChannel();

                    else if (Com == "->")
                        tv.NextChannel();
                }
                else ViewBag.Error = "Телевизор не включен";
                dc.Entry(tv).State = EntityState.Modified;
                dc.SaveChanges();
                return View(tv);
            }
            else if (typeof(Boiler).ToString() == TypeDev)
            {
                Boiler b = dc.boilers.Find(id);
                if (Com == "Вкл/Выкл")
                    b.OnOff();
                else if (b.Status)
                {
                    if (Com == "Наполнить")
                    {
                        b.MakeFull();
                    }

                    else if (Com == "Закипетить")
                    {
                        b.MakeBoils();
                    }
                    else if (Com == "Слить Воду")
                    {
                        b.MakeEmpty();
                    }
                }
                else ViewBag.Error = "Бойлер не включен";
                dc.Entry(b).State = EntityState.Modified;
                dc.SaveChanges();
                return View(b);
            }
            else
            {
                Louvers l = dc.louvers.Find(id);
                if (Com == "Вкл/Выкл")
                    l.OnOff();
                else if (l.Status)
                {
                    if (Com == "Угол+")
                    {
                        l.AngelUp();
                    }

                    else if (Com == "Угол-")
                    {
                        l.AngelDown();
                    }
                    else if (Com == "Поднять/Опустить")
                    {
                        l.LowerUp();
                    }
                }
                else ViewBag.Error = "Жалюзи не включены";
                dc.Entry(l).State = EntityState.Modified;
                dc.SaveChanges();
                return View(l);
            }
        }