Beispiel #1
0
        public ActionResult Change_visit_parameters(tariffonplace tp, Int32? id_tariff_on_place)
        {
            if (id_tariff_on_place != null)
            {
                if (ModelState.IsValid)
                {
                    tariffonplace oldforchange = mp.tariffonplace.Where(x => x.id_tariff_on_place == id_tariff_on_place).FirstOrDefault();
                    if (oldforchange != null)
                    {
                        tariffonplace old = mp.tariffonplace.Where(x => x.id_tariff_on_place == id_tariff_on_place & x.PriceForHourWithAbonement == tp.PriceForHourWithAbonement & x.PriceForHourWithoutAbonement == tp.PriceForHourWithoutAbonement).FirstOrDefault();
                        if (old != null)
                        {
                            ViewData["VisitParameters"] = "Изменений не произошло!";
                            return View(old);
                        }
                        else
                        {
                            if (oldforchange.Status != "Active")
                            {
                                ViewData["VisitParameters"] = "Этот тариф больше неактивен, применить к нему измененения невозможно!";
                                return View(old);
                            }
                            else
                            {
                                //произвожу изменение статуса тарифа на not active в oldforchange
                                tariffonplace old2 = mp.tariffonplace.Where(x => x.SupportClimateControl == oldforchange.SupportClimateControl & x.Type == oldforchange.Type & x.Status != "Active" & x.PriceForHourWithAbonement == tp.PriceForHourWithAbonement & x.PriceForHourWithoutAbonement == tp.PriceForHourWithoutAbonement).FirstOrDefault();

                                oldforchange.Status = "Not active";
                                mp.Entry(oldforchange).State = EntityState.Modified;
                                mp.SaveChanges();
                                if (old2 != null)
                                {
                                    old2.Status = "Active";
                                    mp.Entry(old2).State = EntityState.Modified;
                                    mp.SaveChanges();

                                }
                                else
                                {
                                    tariffonplace tpnew = new tariffonplace();
                                    tpnew.Status = "Active";
                                    tpnew.SupportClimateControl = oldforchange.SupportClimateControl;
                                    tpnew.Type = oldforchange.Type;
                                    tpnew.PriceForHourWithAbonement = tp.PriceForHourWithAbonement;
                                    tpnew.PriceForHourWithoutAbonement = tp.PriceForHourWithoutAbonement;
                                    mp.tariffonplace.Add(tpnew);
                                    mp.SaveChanges();
                                }
                            }
                        }
                    }
                }
                else return View();
            }
            return RedirectToAction("TariffsOnPlace");
        }
Beispiel #2
0
        public ActionResult Save_new_tariff_on_place(tariffonplace tp)
        {
            //ViewData["VisitParameters"] = "";
            //Наверное зедсь будет лучше если найдется запись с такими же параметрами в Not active, а создаваемые такие же будут Active,
            //Тогда перевести просто ту запись в Active.
            if (ModelState.IsValid)
            {
                tariffonplace old = mp.tariffonplace.Where(x => x.SupportClimateControl == tp.SupportClimateControl & x.Type == tp.Type & x.PriceForHourWithAbonement == tp.PriceForHourWithAbonement & x.PriceForHourWithoutAbonement == tp.PriceForHourWithoutAbonement).FirstOrDefault();
                if (old != null)
                {
                    if (old.Status == "Active")
                    {
                        ViewData["VisitParameters"] = "Такой тариф уже существует и он активен";
                        return View(tp);
                    }
                    else if (old.Status != "Active")
                    {

                        tariffonplace oldforchange = mp.tariffonplace.Where(x => x.SupportClimateControl == tp.SupportClimateControl & x.Type == x.Type & x.Status == "Active").FirstOrDefault();
                        if (tp.Status == "Active")
                        {
                            if (oldforchange != null)
                            {
                                oldforchange.Status = "Not active";
                                mp.Entry(oldforchange).State = EntityState.Modified;
                                mp.SaveChanges();
                            }
                        }

                        old.Status = tp.Status;
                        mp.Entry(old).State = EntityState.Modified;
                        mp.SaveChanges();
                    }
                }
                else
                {
                    tariffonplace oldforchange = mp.tariffonplace.Where(x => x.SupportClimateControl == tp.SupportClimateControl & x.Type == tp.Type & x.Status == "Active").FirstOrDefault();
                    if (tp.Status == "Active")
                    {
                        if (oldforchange != null)
                        {
                            oldforchange.Status = "Not active";
                            mp.Entry(oldforchange).State = EntityState.Modified;
                            mp.SaveChanges();
                        }
                    }

                    tariffonplace tpnew = new tariffonplace();
                    tpnew.Status = tp.Status;
                    tpnew.SupportClimateControl = oldforchange.SupportClimateControl;
                    tpnew.Type = oldforchange.Type;
                    tpnew.PriceForHourWithAbonement = tp.PriceForHourWithAbonement;
                    tpnew.PriceForHourWithoutAbonement = tp.PriceForHourWithoutAbonement;
                    mp.tariffonplace.Add(tpnew);
                    mp.SaveChanges();
                }
            }
            else return View();
            return RedirectToAction("TariffsOnPlace");
        }