Beispiel #1
0
        public string Disable(Int32 id_loc_level, Int32 Last_place, string Status)
        {
            string Result = "";

            reservation expired = new reservation();
            expired.FindOnExpired("");
            place last = mp.place.Where(x => x.id_location_level == id_loc_level & x.Status != "Was replaced").OrderByDescending(x => x.NumberPlace).FirstOrDefault();
           // bool conti = true;
           // Int32 Last_place_2 = Last_place+1;
            for (int i = Last_place + 1; i <= last.NumberPlace; i++)
            {
                place not_working_place = mp.place.Where(x => x.id_location_level == id_loc_level & x.NumberPlace == i & x.Status != "Was replaced").FirstOrDefault();
                if (not_working_place.Status == "Occupied" & Status != "Not working")
                {
                    Result = "В сокращаемом диапазоне были обнаружены занятые места, их отключение невозможно, поэтому сокращаемый диапазон частично перевелся в состояние 'not working'";
                    Status = "Not working";
                    place occ = mp.place.Where(x => x.Status == "Occupied").OrderByDescending(x => x.NumberPlace).FirstOrDefault();
                    place recurs = new place();
                    recurs.Disable(id_loc_level,occ.NumberPlace,"Disabled");
                    // occ.NumberPlace + 1;
                    break;
                }
                else if (not_working_place.Status == "Occupied" & Status == "Not working")
                {
                    Result = "В связи с тем, что одно или более транспортных мест на данный момент находится на этом уровне парковки, места были отключены не полностью...";
                    break;
                }
            }

            place last2 = mp.place.Where(x => x.id_location_level == id_loc_level & x.Status != "Was replaced").OrderByDescending(x => x.NumberPlace).FirstOrDefault();

            for (int i = Last_place + 1; i <= last2.NumberPlace; i++)
            {
                place not_working_place = mp.place.Where(x => x.id_location_level == id_loc_level & x.NumberPlace == i & x.Status != "Was replaced").FirstOrDefault();
                if (not_working_place.Status != "Occupied")
                {
                    place change = new place();
                    if (not_working_place.Status != "Disabled" & not_working_place.Status != Status)
                    {

                        if (not_working_place.Status == "In waiting visit")
                        {
                            change.ChangeStatus(Status, not_working_place.id_location_place, 0);
                            reservation res = mp.reservation.Where(x => x.Status == "Active" & (x.id_location_place == not_working_place.id_location_place || x.id_alternative_location_place == not_working_place.id_location_place)).FirstOrDefault();
                            if (res != null)
                            {
                                place findmax;
                                if (Last_place != 0)
                                {
                                    findmax = mp.place.Where(x => (x.tariffonplace.PriceForHourWithoutAbonement >= res.place.tariffonplace.PriceForHourWithoutAbonement) & x.Status == "Free").OrderBy(x => x.tariffonplace.PriceForHourWithAbonement).FirstOrDefault();
                                }
                                else
                                {
                                    findmax = mp.place.Where(x => x.id_location_level != id_loc_level & (x.tariffonplace.PriceForHourWithoutAbonement >= res.place.tariffonplace.PriceForHourWithoutAbonement) & x.Status == "Free").OrderBy(x => x.tariffonplace.PriceForHourWithAbonement).FirstOrDefault();
                                }

                                if (findmax != null)
                                {
                                    change.ChangeStatus("In waiting visit", (long)findmax.id_location_place, (int)res.place.id_tariff_on_place);
                                    res.id_alternative_location_place = (int)findmax.id_location_place;
                                    mp.Entry(res).State = EntityState.Modified;
                                    mp.SaveChanges();
                                }
                                else if (findmax == null)
                                {
                                    place findmin;
                                    if (Last_place != 0)
                                    {
                                        findmin = mp.place.Where(x => (x.tariffonplace.PriceForHourWithoutAbonement < res.place.tariffonplace.PriceForHourWithoutAbonement) & x.Status == "Free").OrderByDescending(x => x.tariffonplace.PriceForHourWithAbonement).FirstOrDefault();
                                    }
                                    else
                                    {
                                        findmin = mp.place.Where(x => x.id_location_level != id_loc_level & (x.tariffonplace.PriceForHourWithoutAbonement < res.place.tariffonplace.PriceForHourWithoutAbonement) & x.Status == "Free").OrderByDescending(x => x.tariffonplace.PriceForHourWithAbonement).FirstOrDefault();
                                    }

                                    if (findmin != null)
                                    {
                                        change.ChangeStatus("In waiting visit", (long)findmin.id_location_place, 0);
                                        res.id_alternative_location_place = (int)findmin.id_location_place;
                                        mp.Entry(res).State = EntityState.Modified;
                                        mp.SaveChanges();
                                    }
                                    else
                                    {
                                        res.id_alternative_location_place = null;
                                        mp.Entry(res).State = EntityState.Modified;
                                        mp.SaveChanges();
                                    }
                                }
                            }
                        }
                        else { change.ChangeStatus(Status, not_working_place.id_location_place, 0); }
                    }
                }
            }

            
            return Result;
        }
Beispiel #2
0
 public ActionResult Temporarily_not_working_zone(Int32 Parking_zone)
 {
     var levels = mp.levelzone.Where(x => x.Parking_zone == Parking_zone).ToList();
     string Mes = "";
     if (levels != null)
     {
         foreach (var lev in levels)
         {
             if (mp.place.Where(x => x.id_location_level == lev.id_location_level).FirstOrDefault() != null)
             {
                 place dis = new place();
                 if (Mes == "")
                 {
                     dis.Disable((Int32)lev.id_location_level, 0, "Not working");
                 }
                 else
                 {
                     dis.Disable((Int32)lev.id_location_level, 0, "Not working");
                 }
             }
         }
     }
     if (Mes != "")
     {
         ViewData["EditZone1"] = "В связи с тем, что одно или более транспортных мест на данный момент находится на этой зоне парковки, места в уровнях на которых находятся эти ТС были отключены не полностью соответственно...";
     }
     return View(mp.parkingzone.ToList());
 }
Beispiel #3
0
        public ActionResult Disabled_level(Int32 Parking_zone, Int32 id_location_level)
        {
            //Вернуть выборку по полученной зоне и значение ViewData
            ViewData["Reservation"] = "";
            ViewData["Zone"] = "Зона №" + Convert.ToString(Parking_zone);


            place dis = new place();
            ViewData["EditLevel"] = dis.Disable(id_location_level, 0,"Disabled");


            //Вернуть выборку по полученной зоне и значение ViewData
            //Из представления вынести подсчет сюда. и если роль админ то вернуть строку которая ниже. если нет, то с ограничениями
            //А именно те уровни, в которых кол-во мест не 0 по условию (!=disabled & !=Replaced)
            return View(mp.levelzone.Where(x => x.Parking_zone == Parking_zone));
        }
Beispiel #4
0
        public ActionResult Change_level(Int32 EditPlace, Int32? ChTariffForPlaces, Int32 id_location_level, Int32 Parking_zone, string NewAmountPlaces, string AddPlaces, string Status, string TariffForAllPlace, FormCollection form)
        {
            //В случае успеха вернуть
            // return RedirectToAction("Levels", new { Parking_zone = Parking_zone });
            levelzone edit_level = mp.levelzone.Where(x => x.id_location_level == id_location_level).FirstOrDefault();

            //  ViewData["EditLevel"] = "ChTariffForPlaces: " + ChTariffForPlaces + " " + AmPlace + " " + AdPlace + " " + type.TypeLevel + " " + type.id_location_level + " " + TariffForAllPlace + " Status:" + Status;

            if (EditPlace == 1)
            {
                Int32 AmountPlace = 0;
                Int32 AddPlace = 0;
                int ap = mp.place.Count(x => x.id_location_level == id_location_level & x.Status != "Was replaced" & x.Status != "Disabled");

                    if (ChTariffForPlaces != null & NewAmountPlaces == null & AddPlaces == null & TariffForAllPlace != "True")
                    {
                        ViewData["EditLevel"] = "Выбирая тариф необходимо выбрать как его применить, а именно, либо ко всем местам уровня (поставив соответсвующую галочку), либо задать новое или добавляемое количество мест. Причем, задавая новое количество мест меньше текущего количества, выбранный тариф проигнорируется соответственно.";
                        ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                        return View(edit_level);
                    }
                    else
                        if (ChTariffForPlaces == null & NewAmountPlaces == null & AddPlaces == null & TariffForAllPlace != "True")
                        {
                            ViewData["EditLevel"] = "Изменений не произошло.";
                            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                            return View(edit_level);
                        }

                    
                    if (NewAmountPlaces != null  & AddPlaces == null)
                    {
                        try
                        {
                            AmountPlace = Convert.ToInt32(NewAmountPlaces);
                            if (AmountPlace < 0) //|| AmountPlace == ap)
                            {
                                ViewData["EditLevel"] = "Неверный формат ввода. Значение должно быть положительным и целочисленным"; //+ отличаться от текущего количества мест в уровне.";
                                ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                return View(edit_level);
                            }
                        }
                        catch
                        {
                            ViewData["EditLevel"] = "Неверный формат ввода. Значение должно быть положительным и целочисленным"; //+ отличаться от текущего количества мест в уровне.";
                            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                            return View(edit_level);
                        }
                        if (AmountPlace <= ap)
                        {
                            //Если добавлять поле "Количество удаляемых мест из уровня, то в качестве параметра AmountPlace отсылать значение: ap-amount_delete_place
                            //таким образом я как бы вновь получу новое количество мест, а это значит, что и номер последнего места.
                            //ViewData["EditLevel"] = "Количество мест в уровне уменьшилось на " + Convert.ToString(ap-AmountPlace);
                            place dis = new place();
                            ViewData["EditLevel"] = dis.Disable(id_location_level, AmountPlace,"Disabled");




                        }
                        else if (AmountPlace > ap)
                        {
                            if (ChTariffForPlaces != null)
                            {
                                tariffonplace ac = mp.tariffonplace.Where(x => x.id_tariff_on_place == ChTariffForPlaces & x.Status == "Active").FirstOrDefault();
                                if (ac != null)
                                {

                                    place ad_pl = new place();
                                    string message = ad_pl.AddPlace(id_location_level, AmountPlace - ap, Status, (long)ChTariffForPlaces);
                                    if (message != "")
                                    {
                                        ViewData["EditLevel"] = message;
                                    }










                                }
                                else
                                {
                                    ViewData["EditLevel"] = "Выбранный тариф перестал быть активным";
                                    ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                    return View(edit_level);
                                }
                            }
                            else
                            {
                                ViewData["EditLevel"] = "Необходимо задать тариф.";
                                ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                return View(edit_level);
                            }
                        }


                    }
                    else if (NewAmountPlaces == null & AddPlaces != null )
                    {
                        try
                        {
                            AddPlace = Convert.ToInt32(AddPlaces);
                            if (AddPlace <= 0)
                            {
                                ViewData["EditLevel"] = "Неверный формат ввода. Значение должно быть больше нуля и целочисленным.";
                                ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                return View(edit_level);
                            }
                        }
                        catch
                        {
                            ViewData["EditLevel"] = "Неверный формат ввода. Значение должно быть больше нуля и целочисленным.";
                            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                            return View(edit_level);
                        }

                        if (ChTariffForPlaces != null)
                        {
                            tariffonplace ac = mp.tariffonplace.Where(x => x.id_tariff_on_place == ChTariffForPlaces & x.Status == "Active").FirstOrDefault();
                            if (ac != null)
                            {
                                



                                place ad_pl = new place();
                                string message = ad_pl.AddPlace(id_location_level, AddPlace, Status, (long)ChTariffForPlaces);
                                if (message != "")
                                {
                                    ViewData["EditLevel"] = message;
                                }



                            }
                            else
                            {
                                ViewData["EditLevel"] = "Выбранный тариф перестал быть активным";
                                ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                return View(edit_level);
                            }
                        }
                        else
                        {
                            ViewData["EditLevel"] = "Необходимо задать тариф.";
                            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                            return View(edit_level);
                        }

                    }



                
                if (TariffForAllPlace == "True")
                {
                    if (ChTariffForPlaces != null)
                    {
                        tariffonplace ac = mp.tariffonplace.Where(x => x.id_tariff_on_place == ChTariffForPlaces & x.Status == "Active").FirstOrDefault();
                        if (ac != null)
                        {
                            //int apo = mp.place.Count(x => x.id_location_level == id_location_level & x.Status != "Was replaced" & x.Status != "Disabled"); 
                            if (ap != 0)
                            {
                                //Тогда обновить тариф для всех мест в уровне, причем так же с учетом брони
                                var allplace = mp.place.Where(x => x.id_location_level == id_location_level & x.Status != "Was replaced" & x.Status != "Disabled").ToList();
                                if (allplace != null)
                                {
                                    string Mes = "";
                                    string Mes2 = "";
                                    foreach (var ch in allplace)
                                    {
                                        if (ch.Status != "Occupied")
                                        {
                                            reservation searchactiveres = mp.reservation.Where(x => x.id_location_place == ch.id_location_place & x.Status == "Active").FirstOrDefault();
                                            if (searchactiveres != null)
                                            {
                                                if (searchactiveres.place.id_tariff_on_place != ChTariffForPlaces)
                                                {
                                                   Mes = "Обновление тарифа для любого забронированного расположения запрещено даже если место временно не доступно.";
                                                }
                                            }
                                            else
                                            {
                                                place thplace = mp.place.Where(x => x.id_location_level == ch.id_location_level & x.NumberPlace == ch.NumberPlace & x.Status == "Was replaced" & x.id_tariff_on_place == ChTariffForPlaces).FirstOrDefault();
                                                if (thplace == null)
                                                {
                                                    if (ch.id_tariff_on_place != ChTariffForPlaces)
                                                    {
                                                        place place_new = new place();
                                                        place_new.id_location_level = ch.id_location_level;
                                                        place_new.id_tariff_on_place = (long)ChTariffForPlaces;
                                                        place_new.Status = ch.Status;
                                                        place_new.NumberPlace = ch.NumberPlace;
                                                        place_new.id_alternative_tariff_on_place = ChTariffForPlaces;
                                                        mp.place.Add(place_new);
                                                        mp.SaveChanges();

                                                        ch.Status = "Was replaced";
                                                        mp.Entry(ch).State = EntityState.Modified;
                                                        mp.SaveChanges();
                                                    }
                                                }
                                                else
                                                {
                                                    thplace.Status = ch.Status;
                                                    mp.Entry(thplace).State = EntityState.Modified;
                                                    mp.SaveChanges();

                                                    ch.Status = "Was replaced";
                                                    mp.Entry(ch).State = EntityState.Modified;
                                                    mp.SaveChanges();
                                                }

                                            }
                                        }
                                        else
                                        {
                                            Mes2 = "Обновление тарифа запрещено для расположений на которых простаивает транспортное средство.";
                                        }
                                    }
                                    if (Mes2 == "")
                                    {
                                        ViewData["EditLevel"] = Mes;
                                    }
                                    else if (Mes2 != "")
                                    {
                                        ViewData["EditLevel"] = Mes2;
                                    }
                                    if (Mes != "" & Mes2 != "")
                                    {
                                        ViewData["EditLevel"] = "Обновление выполнено частично, т.к. 1." + Mes + " 2." + Mes2;
                                    }
                                }
                                else
                                {
                                    ViewData["EditLevel"] = "Возможно, все места заняты и выполнить обновление тарифа невозможно. Рекомендуется выполнять обновление тарифа всех мест для временно недоступного уровня в целом";
                                    ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                    return View(edit_level);
                                }
                            }
                            else
                            {
                                ViewData["EditLevel"] = "Количество мест в этом уровне не превышает нуля. Обновление запрещено.";
                                ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                                return View(edit_level);
                            }
                        }
                        else
                        {
                            ViewData["EditLevel"] = "Выбранный тариф перестал быть активным";
                            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                            return View(edit_level);
                        }
                    }
                    else
                    {
                        ViewData["EditLevel"] = "Необходимо задать тариф.";
                        ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
                        return View(edit_level);
                    }

                }

            }
            else { ViewData["EditLevel"] = "Изменений не произошло."; }
            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
            return View(edit_level);
        }