Beispiel #1
0
 //не заработал. оставлю для алгоритма экстренной смены статуса места при забронированном состоянии
 public void Edit(reservation formedres, Int32 id_loc_place)
 {
     formedres.id_location_place = id_loc_place;
     formedres.id_alternative_location_place = id_loc_place;
     mp.Entry(formedres).State = EntityState.Modified;
     mp.SaveChanges();
 }
Beispiel #2
0
 public bool CreateReservation(string Describe, string Log, reservation_tariff tar)
 {
     bool Result = false;
     try
     {
         reservation r = new reservation();
         r.id_Reservation_Tariff = tar.id_Reservation_Tariff;
         r.Login = Log;
         r.Status = "Formed";
         r.Description = Describe;
         mp.reservation.Add(r);
         mp.SaveChanges();
         Result = true;
     }
     catch
     {
         Result = false;
     }
     return Result;
 }
Beispiel #3
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 #4
0
        public ActionResult Start_work(Int32 id_location_level, Int32 id_loc_pl, FormCollection form)
        {
            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
            reservation expired = new reservation();
            expired.FindOnExpired("");
            place not_working_place = mp.place.Where(x => x.id_location_place == id_loc_pl).FirstOrDefault();

            if (not_working_place.Status == "Not working")
            {
                place change = new place();

                reservation res = mp.reservation.Where(x => x.Status == "Active" & (x.id_location_place == id_loc_pl)).FirstOrDefault();
                if (res != null)
                {
                    if (res.id_alternative_location_place != null)
                    {
                        change.FreePlace((long)res.id_alternative_location_place);
                    }
                    res.id_alternative_location_place = id_loc_pl;
                    mp.Entry(res).State = EntityState.Modified;
                    mp.SaveChanges();
                    change.ChangeStatus("In waiting visit", id_loc_pl, 0);
                }
                else
                {
                    change.FreePlace((long)id_loc_pl);
                }
            }
            ViewData["Reservation"] = "";
            ViewData["Zone-Level"] = "Зона №" + Convert.ToString(not_working_place.levelzone.Parking_zone) + " ; Уровень:" + Convert.ToString(not_working_place.levelzone.Level) + " ; Тип уровня: " + not_working_place.levelzone.TypeLevel;           
            ViewData["ReservationPlace"] = "Место №" + not_working_place.NumberPlace + " было успешно переведено в активное состояние.";
            return View(mp.place.Where(x => x.id_location_level == id_location_level & (x.Status == "Free" || x.Status == "Not working" || x.Status == "In waiting visit")).OrderBy(x => x.NumberPlace).ToList());
        }
Beispiel #5
0
        public ActionResult Stop_work(Int32 id_location_level, Int32 id_loc_pl, FormCollection form)
        {
            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");

            reservation expired = new reservation();
            expired.FindOnExpired("");

            place not_working_place = mp.place.Where(x => x.id_location_place == id_loc_pl).FirstOrDefault();



                place change = new place();

                if (not_working_place.Status != "In waiting visit")
                {
                    change.ChangeStatus("Not working", id_loc_pl, 0);
                    reservation res = mp.reservation.Where(x => x.Status == "Active" & (x.id_location_place == id_loc_pl || x.id_alternative_location_place == id_loc_pl)).FirstOrDefault();
                    if (res != null)
                    {
                        place findmax = mp.place.Where(x => (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 = mp.place.Where(x => (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("Not working", id_loc_pl, 0); }
            
            //& (x.Status == "Free" || x.Status == "Not working" || x.Status == "In waiting visit")
            ViewData["Reservation"] = "";
            ViewData["Zone-Level"] = "Зона №" + Convert.ToString(not_working_place.levelzone.Parking_zone) + " ; Уровень:" + Convert.ToString(not_working_place.levelzone.Level) + " ; Тип уровня: " + not_working_place.levelzone.TypeLevel;
            ViewData["ReservationPlace"] = "Место №" + not_working_place.NumberPlace + " было успешно переведено в неактивное состояние.";
            return View(mp.place.Where(x => x.id_location_level == id_location_level & (x.Status == "Free" || x.Status == "Not working" || x.Status == "In waiting visit")).OrderBy(x => x.NumberPlace).ToList());
            
        }
Beispiel #6
0
        public ActionResult ConnectReservation(Int32? tariff, Int32 ChoosePlace, Int32 id_location_level, FormCollection form)
        {
            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
            reservation find = new reservation();
            find.FindOnExpired("");
            levelzone levz = mp.levelzone.Where(x => x.id_location_level == id_location_level).FirstOrDefault();
            Int32 zone = levz.Parking_zone;
            Int32 level = levz.Level;
            string type_level = levz.TypeLevel;
            ViewData["Zone-Level"] = "Зона №" + Convert.ToString(zone) + " ; Уровень:" + Convert.ToString(level) + " ; Тип уровня: " + type_level;
            ViewData["Reservation"] = "RESERVATION";

            if (User.Identity.IsAuthenticated)
            {
                string Log = User.Identity.Name.ToString();
                string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");

                reservation activeres = mp.reservation.Where(x => x.Login == Log & x.Status == "Active").FirstOrDefault();
                if (activeres == null)
                {

                    reservation formedres = mp.reservation.Where(x => x.Login == Log & x.Status == "Formed").FirstOrDefault();
                    if (formedres != null)
                    {
                                ts exist = mp.ts.Where(x => x.Login == Log & x.Status == "True").FirstOrDefault();
                                if (exist != null)
                                {

                                    visit vis = mp.visit.Where(x => x.id_ts == exist.id_ts & x.DateOut == "dateout").FirstOrDefault();
                                    if (vis == null)
                                    {
                        usr us = mp.usr.Where(x => x.Login == Log).FirstOrDefault();
                        place free = mp.place.Where(x => x.id_location_place == ChoosePlace).FirstOrDefault();
                        if (us != null & free.Status == "Free")
                        {
                            if (us.Now_Balance >= 0)
                            {


                                    reservation_tariff tar = mp.reservation_tariff.Where(x => x.Status == "available" & x.id_Reservation_Tariff == formedres.id_Reservation_Tariff).FirstOrDefault();
                                    if (tar != null)
                                    {
                                        //Ниже допустимый коментируемый код
                                        tariffonplace p = mp.tariffonplace.Where(x => x.id_tariff_on_place == tariff & x.Status == "Active").FirstOrDefault();
                                        if (p != null) //до сюда
                                        {
                                            formedres.id_location_place = ChoosePlace;
                                            formedres.id_alternative_location_place = ChoosePlace;
                                            formedres.Status = "Active";
                                            formedres.Description = "Reservation connect";
                                            formedres.DateConnection = Date;
                                            DateTime mydate = Convert.ToDateTime(Date).AddHours(tar.ValidityPeriodFromTheTimeOfActivationInHour);//Согласно активному тарифу
                                            formedres.ApproximatelyDateOutFromActivity = Convert.ToString(mydate);
                                            mp.Entry(formedres).State = EntityState.Modified;
                                            mp.SaveChanges();
                                            place newplace = new place();
                                            newplace.ChangeStatus("In waiting visit", (long)formedres.id_location_place, 0);
                                        }
                                       // и соответственно противное условие тожн комментируемое
                                        else if (p==null) {
                                            formedres.id_location_place = ChoosePlace;
                                            formedres.id_alternative_location_place = ChoosePlace;
                                            mp.Entry(formedres).State = EntityState.Modified;
                                            mp.SaveChanges();

                                            ViewData["ReservationPlace"] = "Внимание, тариф для места изменился!";
                                            return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x => x.NumberPlace).ToList());
    
                                        }//Комментировать можно чтобы уменьшить время общения с автомобилистом, но и проинформировать по сути тоже надо
                                                //Подумать стоит ли делать это(комментированный примерный код) в ResController при подключении брони
                                    }
                                    else
                                    {
                                        //У формируемой брони изменился тариф.
                                        formedres.id_location_place = ChoosePlace;
                                        formedres.id_alternative_location_place = ChoosePlace;
                                        mp.Entry(formedres).State = EntityState.Modified;
                                        mp.SaveChanges();
                                        return RedirectToAction("Agreement", new { Controller = "Res" });
                                    }



                            }
                            else if (us.Now_Balance < 0)
                            {
                                ViewData["ReservationPlace"] = "Активирование брони с отрицательным балансом запрещено. Формируемая вами бронь сохранена, вы сможете подключить ее после пополнения баланса!";
                                formedres.id_location_place = ChoosePlace;
                                formedres.id_alternative_location_place = ChoosePlace;
                                mp.Entry(formedres).State = EntityState.Modified;
                                mp.SaveChanges();

                                return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x => x.NumberPlace).ToList());
                            }

                        }
                        else if (free.Status != "Free")
                        {
                            formedres.id_location_place = ChoosePlace;
                            formedres.id_alternative_location_place = ChoosePlace;
                            mp.Entry(formedres).State = EntityState.Modified;
                            mp.SaveChanges();
                            if (free.Status == "Occupied" || free.Status == "In waiting visit")
                            {
                                ViewData["ReservationPlace"] = "Место №" + free.NumberPlace + " занято!";
                            }
                            else
                            {
                                ViewData["ReservationPlace"] = "Место недоступно!";
                            }
                            return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x=>x.NumberPlace).ToList());
                        }
            }
                else
                {
                    ViewData["ReservationPlace"] = "Формиремая бронь сохранена, но Вы не можете активировать бронирование, пока одно из ваших ТС находится у нас на парковке!";
                                        formedres.id_location_place = ChoosePlace;
                        formedres.id_alternative_location_place = ChoosePlace;
                        mp.Entry(formedres).State = EntityState.Modified;
                        mp.SaveChanges();
                        return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x => x.NumberPlace).ToList());
                   
                                }
                    }
                    else
                    {
                        ViewData["ReservationPlace"] = "Активирование брони без наличия ТС запрещено. Формируемая вами бронь сохранена, вы сможете подключить ее после добавления вашего ТС!";
                        formedres.id_location_place = ChoosePlace;
                        formedres.id_alternative_location_place = ChoosePlace;
                        mp.Entry(formedres).State = EntityState.Modified;
                        mp.SaveChanges();
                        return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x => x.NumberPlace).ToList());
                    }
                    }
                    else
                    {
                        //МОЖНО СДЕЛАТЬ ПЕРЕНАПРАВЛЕНИЕ СРАЗУ НА Reservation в ResController с этим же самым сообщением. Или на принятие соглашения.
                        ViewData["ReservationPlace"] = "Система не нашла формирующейся заявки! Возможно, она была удалена вами.";
                        return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x => x.NumberPlace).ToList());
                    }





                }

                else if (activeres != null)
                {
                    ViewData["ReservationPlace"] = "Вы уже имеете активное забронированное месторасположение!";
                    return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").ToList());
                }
                return RedirectToAction("Reservation", new { Controller = "Res" });
                //  return View(mp.place.Where(x => x.id_location_level == id_location_level).ToList());
            }
            else
            {
                return RedirectToAction("LogOn", new { Controller = "Account" });
            }
        }
Beispiel #7
0
 public ActionResult Continue_place(Int32 id_location_level, string Value)
 {
     ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
     reservation find = new reservation();
     find.FindOnExpired("");
     levelzone levz = mp.levelzone.Where(x => x.id_location_level == id_location_level).FirstOrDefault();
     Int32 zone = levz.Parking_zone;
     Int32 level = levz.Level;
     string type_level = levz.TypeLevel;
     ViewData["Zone-Level"] = "Зона №" + Convert.ToString(zone) + " ; Уровень:" + Convert.ToString(level) + " ; Тип уровня: " + type_level;
     if (Value == "RESERVATION")
     {
         ViewData["Reservation"] = Value;
         return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status == "Free").OrderBy(x=>x.NumberPlace));
     }
     else
     {
         ViewData["Reservation"] = "";
         return View(mp.place.Where(x => x.id_location_level == id_location_level & x.Status != "Was replaced" & x.Status != "Disabled").OrderBy(x=>x.NumberPlace));
     }
 }
Beispiel #8
0
        public ActionResult Choose_tariff_on_place(Int32 not_working_place, Int32 choose_tariff_on_place, FormCollection form)
        {//Может вывести в качестве информации текущий тариф?? 
            reservation expired = new reservation();
            expired.FindOnExpired("");
            ViewData["Reservation"] = "";
            ViewData["ActiveTariffs"] = mp.tariffonplace.Where(x => x.Status == "Active");
            place not_working_plac = mp.place.Where(x => x.id_location_place == not_working_place & (x.Status=="Free" || x.Status=="Not working")).FirstOrDefault();
            if (not_working_plac != null)
            {
                tariffonplace choosetop = mp.tariffonplace.Where(x => x.id_tariff_on_place == choose_tariff_on_place & x.Status == "Active").FirstOrDefault();
                if (choosetop != null)
                {

                    reservation searchactiveres = mp.reservation.Where(x => x.id_location_place == not_working_place & x.Status == "Active").FirstOrDefault();
                    if (searchactiveres != null)
                    {
                        ViewData["ReservationPlace"] = "Вы не можете изменить тариф для этого места, пока в этом расположении нуждается один из участников системы";
                    }
                    else
                    {
                        place thplace = mp.place.Where(x => x.id_location_level == not_working_plac.id_location_level & x.NumberPlace == not_working_plac.NumberPlace & x.Status == "Was replaced" & x.id_tariff_on_place == choose_tariff_on_place).FirstOrDefault();
                        if (thplace == null)
                        {
                            if (not_working_plac.id_tariff_on_place != choose_tariff_on_place)
                            {
                                place place_new = new place();
                                place_new.id_location_level = not_working_plac.id_location_level;
                                place_new.id_tariff_on_place = choose_tariff_on_place;
                                place_new.Status = not_working_plac.Status;
                                place_new.NumberPlace = not_working_plac.NumberPlace;
                                place_new.id_alternative_tariff_on_place = choose_tariff_on_place;
                                mp.place.Add(place_new);
                                mp.SaveChanges();

                                not_working_plac.Status = "Was replaced";
                                mp.Entry(not_working_plac).State = EntityState.Modified;
                                mp.SaveChanges();
                                ViewData["ReservationPlace"] = "Тариф для места №" + not_working_plac.NumberPlace + " был успешно сменен.";
                            }
                            ViewData["ReservationPlace"] = "Тариф для места №" + not_working_plac.NumberPlace + " не отличался от предыдущего.";
                            //Перекинуть на представление редактирования в качестве кода сообщения выше будет txt=2, в том представлении оно определится
                        }
                        else
                        {
                            thplace.Status = not_working_plac.Status;
                            mp.Entry(thplace).State = EntityState.Modified;
                            mp.SaveChanges();

                            not_working_plac.Status = "Was replaced";
                            mp.Entry(not_working_plac).State = EntityState.Modified;
                            mp.SaveChanges();
                            ViewData["ReservationPlace"] = "Тариф для места №" + not_working_plac.NumberPlace + " был успешно сменен.";
                        }

                    }

                    //return View(mp.place.Where(x => x.id_location_level == not_working_plac.id_location_level & x.Status != "Was replaced").OrderBy(x=>x.NumberPlace).ToList());

                    ViewData["Zone-Level"] = "Зона №" + Convert.ToString(not_working_plac.levelzone.Parking_zone) + " ; Уровень:" + Convert.ToString(not_working_plac.levelzone.Level) + " ; Тип уровня: " + not_working_plac.levelzone.TypeLevel;
                    return View(mp.place.Where(x => x.id_location_level == not_working_plac.id_location_level & (x.Status == "Free" || x.Status == "Not working" || x.Status == "In waiting visit")).OrderBy(x => x.NumberPlace).ToList());
                }
                else
                {
                    return RedirectToAction("Place_tariff", new { objp = not_working_place, txt = 1 });
                }
            }
            else
            {
                ViewData["ReservationPlace"] = "Вы не можете изменить тариф для этого места, пока в этом расположении нуждается один из участников системы";
                ViewData["Zone-Level"] = "Зона №" + Convert.ToString(not_working_plac.levelzone.Parking_zone) + " ; Уровень:" + Convert.ToString(not_working_plac.levelzone.Level) + " ; Тип уровня: " + not_working_plac.levelzone.TypeLevel;
                return View(mp.place.Where(x => x.id_location_level == not_working_plac.id_location_level & (x.Status == "Free" || x.Status == "Not working" || x.Status == "In waiting visit")).OrderBy(x => x.NumberPlace).ToList());

            }
        }
Beispiel #9
0
        public ActionResult Revoke(Int32 id_reservation_user)
        {
            if (User.Identity.IsAuthenticated)
            {
                string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");
                string Log = User.Identity.Name.ToString();
                try
                {
                    reservation n = mp.reservation.Where(x => x.id_reservation_user == id_reservation_user).FirstOrDefault();
                    if (n.Status != "Formed")
                    {
                        reservation findforlog = new reservation();
                        if (findforlog.FindOnExpired(Log) == false)
                        {

                            if (Convert.ToDateTime(n.ApproximatelyDateOutFromActivity) >= Convert.ToDateTime(Date))
                            {
                                n.DateOutFromActivity = Date;
                                n.Status = "Closed";
                                n.Description = "Reservation was revoke";
                                mp.Entry(n).State = EntityState.Modified;
                                mp.SaveChanges();
                                //При посещении или отказе (и если бронь не истекла) в кач-ве третьего параметра отправить текущее время,
                                //Здесь оа истекла и я отправляю предположительное, уже ранее рассчитанное при создании заявки брони.
                                reservation n1 = mp.reservation.Where(x => x.id_reservation_user == id_reservation_user).FirstOrDefault();
                                r.Revoke("Reservation was revoke", n1, Date);
                                //рассчитать средства и списать их со счета.
                            }
                        }
                    }
                    else if (n.Status == "Formed")
                    {
                        mp.reservation.Remove(n);
                        mp.SaveChanges();
                    }

                    ViewData["ReservationTariff"] = mp.reservation_tariff.Where(x => x.Status == "available").ToList();
                    return View(mp.reservation.Where(x => x.Login == Log & (x.Status == "Formed" || x.Status == "Active")).ToList());
                }
                catch
                {
                    ViewData["AnswerFromReservation"] = id_reservation_user;
                    ViewData["ReservationTariff"] = mp.reservation_tariff.Where(x => x.Status == "available").ToList();
                    return View(mp.reservation.Where(x => x.Login == Log & (x.Status == "Formed" || x.Status == "Active")).ToList());
                }
            }
            else
            {
                return RedirectToAction("LogOn", new { Controller = "Account" });
            }
            

        }
Beispiel #10
0
        public bool Revoke(string Describe, reservation obj, string Date)
        {
            bool result = false;
            try
            {
                //format my date have view:  string d = "21.11.14 20:00";

                decimal price = 0;
                usr ur = mp.usr.Where(x => x.Login == obj.Login).FirstOrDefault();
                balance bl = new balance();
                place p = new place();

                //Можно упростить задачу. Следующим коментируемым кодом
                /*  obj.id_alternative_location_place == obj.id_location_place
                 * то есть если место уже изменено на другое, то сделать автомобилисту бесплатную бронь(т.к. нарушена его потребность)
                 * соответственно проверка на то что лучше это место или хуже не понадобится вообще.
                 * 
                 * сейчас действует схема, что бронь бесплатна если новое выданное место хуже или его нет вообще. (риск он принимал в
                 * соглашении)
                */
                if (obj.id_alternative_location_place != null) {


                    if (Describe != "Reservation was used")
                    {
                        //освобождающее место либо достанется кому-то, либо переведтся в свободное состояние
                        p.FreePlace((long)obj.id_alternative_location_place);
                    }

                    //Эта проверка может непонадобится, если обдумать описанный комментарий выше.
                    if (p.bestornot((long)obj.id_location_place, (long)obj.id_alternative_location_place) == true ||
                        obj.id_alternative_location_place == obj.id_location_place)
                        {


                long span = 0;

                if (Describe == "Reservation was expired" | Describe == "Reservation was revoke")
                {
                    span = Convert.ToDateTime(Date).Ticks - Convert.ToDateTime(obj.DateConnection).Ticks;
                }
                else if (Describe == "Reservation was used")
                {



                    DateTime mydate = Convert.ToDateTime(obj.DateConnection).AddMinutes(obj.reservation_tariff.FirstFreeTimeInMinutes);
                    if (mydate <= Convert.ToDateTime(DateTime.Now.ToString("dd.MM.yy HH:mm")))
                    {
                        span = Convert.ToDateTime(Date).Ticks - mydate.Ticks;
                    }


                }





                    decimal priceinmin = (decimal)(obj.reservation_tariff.PriceInRubForHourHightFreeTime) / 60;

                            price = (decimal)TimeSpan.FromTicks(span).TotalMinutes * priceinmin;
                            ur.Now_Balance = ur.Now_Balance - price;
                            mp.Entry(ur).State = EntityState.Modified;
                            mp.SaveChanges();
                        }

                    
                    //Да и еще, расчеты делаются точно. Но не округлить ли баланс на выходе в лучшую сторону для автомобилиста, до копейки(сотых) хотя бы.
                }

                
                bl.Operation("Debit", price, (decimal)ur.Now_Balance, ur.Login, Describe, Date);
                
                result = true;
            }
            catch
            {
                result = false;
            }
            return result;
        }
Beispiel #11
0
        public bool FindOnExpired(string Log)
        {
            if (Log != "")
            {
                bool Result = false;
                foreach (reservation n in mp.reservation.Where(x => x.Login == Log & x.Status == "Active").ToList())
                {
                string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");
                    //Проверяю истекла ли дата брони
                    if (Convert.ToDateTime(n.ApproximatelyDateOutFromActivity) < Convert.ToDateTime(Date))
                    {
                        n.DateOutFromActivity = n.ApproximatelyDateOutFromActivity;
                        n.Status = "Closed";
                        n.Description = "Reservation was expired";
                        mp.Entry(n).State = EntityState.Modified;
                        mp.SaveChanges();
                        //При посещении или отказе (и если бронь не истекла) в кач-ве третьего параметра отправить текущее время,
                        //Здесь оа истекла и я отправляю предположительное, уже ранее рассчитанное при создании заявки брони.
                        reservation r = new reservation();
                        r.Revoke("Reservation was expired", n, n.ApproximatelyDateOutFromActivity);
                        //рассчитать средства и списать их со счета.
                        Result = true;
                        break;
                    }
                }
                return Result;
            }
            else
            {

                foreach (reservation n in mp.reservation.Where(x => x.Status == "Active").ToList())
                {
                    string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");
                    //Проверяю истекла ли дата брони
                    if (Convert.ToDateTime(n.ApproximatelyDateOutFromActivity) < Convert.ToDateTime(Date))
                    {
                        n.DateOutFromActivity = n.ApproximatelyDateOutFromActivity;
                        n.Status = "Closed";
                        n.Description = "Reservation was expired";
                        mp.Entry(n).State = EntityState.Modified;
                        mp.SaveChanges();
                        //При посещении или отказе (и если бронь не истекла) в кач-ве третьего параметра отправить текущее время,
                        //Здесь оа истекла и я отправляю предположительное, уже ранее рассчитанное при создании заявки брони.
                        reservation r = new reservation();
                        r.Revoke("Reservation was expired", n, n.ApproximatelyDateOutFromActivity);
                        //рассчитать средства и списать их со счета.
                        break;
                    }
                }
                return true;
            }


        }
Beispiel #12
0
        public ActionResult Next_step_formed(Int32? id_Reservation_Tariff)
        {
            if (id_Reservation_Tariff != null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    //reservation_tariff check = mp.reservation_tariff.Where(x => x.Status == "available").FirstOrDefault();

                    string Log = User.Identity.Name.ToString();
                    reservation activeres = mp.reservation.Where(x => x.Login == Log & x.Status == "Active").FirstOrDefault();
                    if (activeres == null)
                    {
                        reservation_tariff check = mp.reservation_tariff.Where(x => x.id_Reservation_Tariff == id_Reservation_Tariff & x.Status == "available").FirstOrDefault();
                        if (check != null)
                        {
                            reservation formed = mp.reservation.Where(x => x.Login == Log & x.Status == "Formed").FirstOrDefault();
                            if (formed == null)
                            {
                                reservation r = new reservation();
                                r.CreateReservation("Reservation wait full formed", Log, check);
                            }
                            else if (formed != null)
                            {
                                formed.id_Reservation_Tariff = (long)id_Reservation_Tariff;
                                mp.Entry(formed).State = EntityState.Modified;
                                mp.SaveChanges();
                                return RedirectToAction("Reservation");
                            }
                        }
                        else if (check == null)
                        {
                            ViewData["NewTariff"] = "Ранее подтвержденный Вами на использование тариф закончил свое действие, пожалуйста, ознакомьтесь с условиями для нового тарифа";
                            return View(mp.reservation_tariff.Where(x => x.Status == "available").ToList());
                        }
                    }
                    else if (activeres != null)
                    {
                        ViewData["NewTariff"] = "Вы уже имеете активное забронированное месторасположение!";
                        return View(mp.reservation_tariff.Where(x => x.Status == "available").ToList());
                    }
                    //return RedirectToAction("ZonesLevelsPlaces", new { Controller = "Home", value = "RESERVATION" });

                    return RedirectToAction("ZonesLevelsPlaces", new { Controller = "Home", value = "RESERVATION" });
                }
                else
                {
                    return RedirectToAction("LogOn", new { Controller = "Account" });
                }
            }
            else
            {
                return RedirectToAction("Reservation");
            }
        }
Beispiel #13
0
        public ActionResult Reservation()
        {
            if (User.Identity.IsAuthenticated)
            {
                string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");
                string Log = User.Identity.Name.ToString();
                reservation findforlog = new reservation();
                findforlog.FindOnExpired(Log);
                ViewData["ReservationTariff"] = mp.reservation_tariff.Where(x => x.Status == "available").ToList();
                return View(mp.reservation.Where(x => x.Login == Log & (x.Status == "Formed" || x.Status == "Active")).ToList());
            }

            else
            {
                return RedirectToAction("LogOn", new { Controller = "Account" });
            }

        }
Beispiel #14
0
        public string Run_this_level(Int32 id_loc_level)
        {
            string Result = "";
            reservation expired = new reservation();
            expired.FindOnExpired("");
            int ap = mp.place.Count(x => x.id_location_level == id_loc_level & x.Status != "Was replaced" & x.Status != "Disabled");

            for (int i = 0; i <= ap; i++)
            {
                place not_working_place = mp.place.Where(x => x.id_location_level == id_loc_level & x.NumberPlace == i & x.Status == "Not working").FirstOrDefault();
                if (not_working_place != null)
                {
                    place change = new place();

                    reservation res = mp.reservation.Where(x => x.Status == "Active" & (x.id_location_place == not_working_place.id_location_place)).FirstOrDefault();
                    if (res != null)
                    {
                        if (res.id_alternative_location_place != null)
                        {
                            change.FreePlace((long)res.id_alternative_location_place);
                        }
                        res.id_alternative_location_place = (int)not_working_place.id_location_place;
                        mp.Entry(res).State = EntityState.Modified;
                        mp.SaveChanges();
                        change.ChangeStatus("In waiting visit", not_working_place.id_location_place, 0);
                    }
                    else
                    {
                        change.FreePlace((long)not_working_place.id_location_place);
                    }
                }
            }


            return Result;
        }
Beispiel #15
0
        public ActionResult RegisterIn(ts numb)
        {
                if (ModelState.IsValidField("Number"))
                {
                    visitparameters vp = mp.visitparameters.Where(x => x.Status == "Active").FirstOrDefault();
                    if (vp != null)
                    {
                        reservation r = new reservation();
                        r.FindOnExpired("");
                        ts searchts = mp.ts.Where(x => x.Number == numb.Number & x.Status == "True").FirstOrDefault();
                        if (searchts != null)
                        {
                            visit nvis = new visit();
                                            visit vis = mp.visit.Where(x => x.id_ts == searchts.id_ts & x.DateOut == "dateout").FirstOrDefault();
                                            if (vis == null)
                                            {
                                                place p = new place();
                                                string Log = searchts.Login;
                                                string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");
                                                reservation res = mp.reservation.Where(x => x.Login == Log & x.Status == "Active").FirstOrDefault(); //Существует ли бронь
                                                if (res != null)
                                                {
                                                    if (res.id_alternative_location_place != null)
                                                    {

                                                        nvis.RegisterIn((long)res.id_alternative_location_place, searchts.id_ts, Date, vp.id_vis_param);
                                                        res.DateOutFromActivity = Date;
                                                        res.Status = "Closed";
                                                        res.Description = "Reservation was used";
                                                        mp.Entry(res).State = EntityState.Modified;
                                                        mp.SaveChanges();
                                                        r.Revoke("Reservation was used", res, Date);
                                                        p.ChangeStatus("Occupied", (long)res.id_alternative_location_place, (Int32)res.place.id_alternative_tariff_on_place);
                                                    }
                                                    else
                                                    {
                                                        ViewData["ExceptionRegisterIn"] = "Изначально выбранное место этим ТС было закрыто, других свободных мест на данный момент нет"; //, с броней ничего не делать. Будет ждать свободных, не дождется - умрет сама.
                                                        return View("RegisterIn");
                                                    }
                                                }
                                                else
                                                {
                                                    place autoplace = mp.place.Where(x => x.Status == "Free").OrderBy(x => x.tariffonplace.PriceForHourWithoutAbonement).FirstOrDefault();
                                                    if (autoplace != null)
                                                    {
                                                        nvis.RegisterIn((long)autoplace.id_location_place, searchts.id_ts, Date, vp.id_vis_param);
                                                        p.ChangeStatus("Occupied", (long)autoplace.id_location_place, 0);
                                                    }
                                                    else
                                                    {
                                                        ViewData["ExceptionRegisterIn"] = "Свободных мест нет!";
                                                        return View("RegisterIn");
                                                    }
                                                    //Автоматический расчет мест";
                                                }
                                            }
                                            else
                                            {
                                                ViewData["ExceptionRegisterIn"] = "Возможно, Вы ошиблись при вводе регистрационного номера, т.к. указанное вами ТС уже находится на парковке.";
                                                return View("RegisterIn");
                                            }
                        }
                        else
                        {
                            ViewData["ExceptionRegisterIn"] = "TC не найдено в бд";
                            return View("RegisterIn");
                        }

                    }
                    else
                    {
                        ViewData["ExceptionRegisterIn"] = "Осутствуют параметры въезда, активной записи не найдено";
                        return View("RegisterIn");
                    }







                    return RedirectToAction("Index", new { Controller = "Home"});
                }
                else
                {
                    return View("RegisterIn");
                }
            

        }
Beispiel #16
0
        public string AddPlace(Int32 id_loc_level, Int32 amount_added_place, string Status, long id_tariff_on_place)
        {
            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" & x.Status != "Disabled").OrderByDescending(x => x.NumberPlace).FirstOrDefault();
            Int32 last_place = 0;
            if (last != null)
            {
                last_place = last.NumberPlace+1;
            }
            else { last_place = 1; }

            for (int i = last_place; i < last_place + amount_added_place; i++)
            {
                place disabled = mp.place.Where(x => x.id_location_level == id_loc_level & x.Status == "Disabled" & x.NumberPlace == i).FirstOrDefault();
                place change = new place();
                if (disabled != null)
                {
                    reservation res = mp.reservation.Where(x => x.Status == "Active" & (x.id_location_place == disabled.id_location_place)).FirstOrDefault();
                    if (res != null)
                    {

                        if (Status == "Free" & disabled.id_tariff_on_place == id_tariff_on_place)
                        {
                            if (res.id_alternative_location_place != null)
                            {
                                change.FreePlace((long)res.id_alternative_location_place);
                            }
                            res.id_alternative_location_place = (int)disabled.id_location_place;
                            mp.Entry(res).State = EntityState.Modified;
                            mp.SaveChanges();
                            change.ChangeStatus("In waiting visit", disabled.id_location_place, 0);

                            //Т.е. админ должен потом решить включить ли то место с со СТАРЫМ тарифом или ждать пока бронь кончится,
                            //а потом как доступ к изменению тарифу будет открыт(как закончится бронь) он его изменит и включит.
                            //Совпадающий тариф учитывается
                        }
                        else if (Status == "Free" & disabled.id_tariff_on_place != id_tariff_on_place)
                        {
                            change.ChangeStatus("Not working", disabled.id_location_place, 0);
                            Result = "0";
                        }
                        if (Status != "Free" & disabled.id_tariff_on_place != id_tariff_on_place)
                        {
                            if (Result != "0")
                            {
                                Result = "1";
                            }
                            change.ChangeStatus("Not working", disabled.id_location_place, 0);
                        }
                        else if (Status != "Free" & disabled.id_tariff_on_place == id_tariff_on_place)
                        {
                            change.ChangeStatus("Not working", disabled.id_location_place, 0);
                        }
                    }
                    else
                    {

                        disabled.Status = Status;
                        disabled.id_tariff_on_place = id_tariff_on_place;
                        disabled.id_alternative_tariff_on_place = (int)id_tariff_on_place;
                        mp.Entry(disabled).State = EntityState.Modified;
                        mp.SaveChanges();
                        if (Status == "Free")
                        {
                            change.FreePlace((long)disabled.id_location_place);
                        }
                    }
                }
                else
                {
                    place di = mp.place.Where(x => x.id_location_level == id_loc_level & x.Status == "Occupied" & x.NumberPlace == i).FirstOrDefault();
                    if (di == null)
                    {
                        place new_place = new place();
                        new_place.NumberPlace = i;
                        new_place.Status = Status;
                        new_place.id_tariff_on_place = id_tariff_on_place;
                        new_place.id_alternative_tariff_on_place = (int)id_tariff_on_place;
                        new_place.id_location_level = id_loc_level;
                        mp.place.Add(new_place);
                        mp.SaveChanges();
                        if (Status == "Free")
                        {
                            place new_place_search = mp.place.Where(x => x.NumberPlace == i & x.Status == Status & x.id_tariff_on_place == id_tariff_on_place & x.id_location_level == id_loc_level & x.id_alternative_tariff_on_place == (int)id_tariff_on_place).FirstOrDefault();
                            change.FreePlace((long)new_place_search.id_location_place);
                        }
                    }
                }
            }
            if (Result == "0")
            {
                Result = "К некоторым местам смена тарифа будет доступна по истечении действия активных записей бронирований, которые прикреплены к этим местам. К местам, к которым не удалось произвести смену тарифа, был присвоен статус 'Not working', их можно так же включить не меняя тариф, перейдя в просмотр мест этого уровня.";
            }
            else if (Result == "1")
            {
                Result = "К некоторым местам не удалось произвести смену тарифа, поскольку их ожидают активные записи бронирования. Смена тарифа будет доступна по истечении действия активных записей бронирований.";
            }
            return Result;
        }
Beispiel #17
0
        public ActionResult Connect()
        {
            reservation find = new reservation();
            find.FindOnExpired("");
            if (User.Identity.IsAuthenticated)
            {
                string Log = User.Identity.Name.ToString();
                string Date = DateTime.Now.ToString("dd.MM.yy HH:mm");
                reservation formedres = mp.reservation.Where(x => x.Login == Log & x.Status == "Formed").FirstOrDefault();


                            ts exist = mp.ts.Where(x => x.Login == Log & x.Status == "True").FirstOrDefault();
                            if (exist != null)
                            {

                visit vis = mp.visit.Where(x => x.id_ts == exist.id_ts & x.DateOut == "dateout").FirstOrDefault();
                if (vis == null)
                {

                usr us = mp.usr.Where(x => x.Login == Log).FirstOrDefault();
                if (formedres.id_location_place != null)
                {
                    place free = mp.place.Where(x => x.id_location_place == formedres.id_location_place).FirstOrDefault();
                    if (us != null & free.Status == "Free")
                    {
                        if (us.Now_Balance >= 0)
                        {


                                reservation_tariff tar = mp.reservation_tariff.Where(x => x.Status == "available" & x.id_Reservation_Tariff == formedres.id_Reservation_Tariff).FirstOrDefault();
                                if (tar != null)
                                {
                                    formedres.Status = "Active";
                                    formedres.Description = "Reservation connect";
                                    formedres.DateConnection = Date;
                                    DateTime mydate = Convert.ToDateTime(Date).AddHours(tar.ValidityPeriodFromTheTimeOfActivationInHour);//Согласно активному тарифу
                                    formedres.ApproximatelyDateOutFromActivity = Convert.ToString(mydate);
                                    mp.Entry(formedres).State = EntityState.Modified;
                                    mp.SaveChanges();
                                    place newplace = new place();
                                    newplace.ChangeStatus("In waiting visit", (long)formedres.id_location_place,0);
                                }
                                else
                                {
                                    ViewData["AnswerFromReservation"] = "Данный тариф бронирования не активен. Пожалуйста, переформируйте заявку!";
                                }

                        }
                        else if (us.Now_Balance < 0)
                        {
                            ViewData["AnswerFromReservation"] = "У Вас отрицательный баланс, активирование бронирования запрещено!";
                        }
                    }

                    else if (free.Status != "Free")
                    {
                        if (free.Status == "Occupied" || free.Status == "In waiting visit")
                        {
                            ViewData["AnswerFromReservation"] = "Месторасположение занято!";
                        }
                        else
                        {
                            ViewData["AnswerFromReservation"] = "Место недоступно!";
                        }
                        
                    }
                }
                else if (formedres.id_location_place == null)
                {
                    ViewData["AnswerFromReservation"] = "Месторасположение не задано!";
                }
            }
                else
                {
                    ViewData["AnswerFromReservation"] = "Формиремая бронь сохранена, но Вы не можете активировать бронирование, пока хотя бы одно из ваших ТС находится у нас на парковке!";
                }
                            }
                            else
                            {
                                ViewData["AnswerFromReservation"] = "Активирование бронирования без наличия ТС запрещено!";
                            }

                ViewData["ReservationTariff"] = mp.reservation_tariff.Where(x => x.Status == "available").ToList();
                return View(mp.reservation.Where(x => x.Login == Log & (x.Status == "Formed" || x.Status == "Active")).ToList());
            }
            else
            {
                return RedirectToAction("LogOn", new { Controller = "Account" });
            }
        }