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; }
//Нужен для регистрации выезда, так же сойдет для отката(и истечения) брони: //Можно попробовать задействовать при включении места. Мое место включить и сразу все обновить, а альтернативное //уже не нужное отправить сюда public bool FreePlace(long free_id_loc_place) { bool res = true; place fp = mp.place.Where(x => x.id_location_place == free_id_loc_place).FirstOrDefault(); var obj = mp.reservation.Where(x => x.Status == "Active" & x.id_alternative_location_place == null).ToList(); int count = obj.Count(); place pl = new place(); if (count > 0) { long id_user_reserv = 0; int i = 0; foreach (var search in obj) { DateTime min = Convert.ToDateTime(search.DateConnection); foreach (var mindate in obj) { if (i < count) { if (min <= Convert.ToDateTime(mindate.DateConnection)) { min = Convert.ToDateTime(mindate.DateConnection); id_user_reserv = mindate.id_reservation_user; } i++; } else { break; } } break; } reservation myfind = mp.reservation.Where(x => x.id_reservation_user == id_user_reserv).FirstOrDefault(); myfind.id_alternative_location_place = (int)free_id_loc_place; mp.Entry(myfind).State = EntityState.Modified; mp.SaveChanges(); //Если освобождающееся место лучше или такое же if (pl.bestornot((long)myfind.id_location_place, free_id_loc_place) == true) { pl.ChangeStatus("In waiting visit", free_id_loc_place, (int)myfind.place.id_tariff_on_place); } //если нет else { pl.ChangeStatus("In waiting visit", free_id_loc_place, 0); } res = true; } else { int newfr = 0; var eq = mp.reservation.Where(x => x.Status == "Active" & x.id_alternative_location_place != x.id_location_place & x.id_alternative_location_place != free_id_loc_place).ToList(); int e = eq.Count(); //long id_u_r = 0; // int coun = 0; if (e > 0) { foreach (var s1 in eq) { place fineq = mp.place.Where(x => x.id_location_place == s1.id_alternative_location_place).FirstOrDefault(); if ((fp.tariffonplace.PriceForHourWithoutAbonement > fineq.tariffonplace.PriceForHourWithoutAbonement) & (fp.tariffonplace.PriceForHourWithoutAbonement <= s1.place.tariffonplace.PriceForHourWithoutAbonement)) //alt<new<=first { //Можно модернизировать путем определения ранней даты. Кто раньше забронировался, тому и получше достанется //присвоить и получить newfr = (int)s1.id_alternative_location_place; s1.id_alternative_location_place = (int)free_id_loc_place; mp.Entry(s1).State = EntityState.Modified; mp.SaveChanges(); pl.ChangeStatus("In waiting visit", free_id_loc_place, (int)fp.id_tariff_on_place); break; } }//Разъединил. Сначала те, кто могут подняться к лучшему, потом те, кто могут отпустить более лучшее место, потом //те, кто могут из худшего перейти в лучшее сразу. Может быть удалить первую часть, оставив только 3-ю вместо нее? if (newfr == 0)//последнее добавленное { foreach (var s1 in eq) { place fineq = mp.place.Where(x => x.id_location_place == s1.id_alternative_location_place).FirstOrDefault(); if ((fp.tariffonplace.PriceForHourWithoutAbonement >= s1.place.tariffonplace.PriceForHourWithoutAbonement) & (fp.tariffonplace.PriceForHourWithoutAbonement < fineq.tariffonplace.PriceForHourWithoutAbonement)) {//alt>new>=first newfr = (int)s1.id_alternative_location_place; s1.id_alternative_location_place = (int)free_id_loc_place; mp.Entry(s1).State = EntityState.Modified; mp.SaveChanges(); pl.ChangeStatus("In waiting visit", free_id_loc_place, (int)s1.place.id_tariff_on_place); break; } } } if (newfr == 0)//последнее добавленное { foreach (var s1 in eq) {// alt<first<=new place fineq = mp.place.Where(x => x.id_location_place == s1.id_alternative_location_place).FirstOrDefault(); if (((s1.place.tariffonplace.PriceForHourWithoutAbonement > fineq.tariffonplace.PriceForHourWithoutAbonement) & (fp.tariffonplace.PriceForHourWithoutAbonement >= s1.place.tariffonplace.PriceForHourWithoutAbonement))) { newfr = (int)s1.id_alternative_location_place; s1.id_alternative_location_place = (int)free_id_loc_place; mp.Entry(s1).State = EntityState.Modified; mp.SaveChanges(); pl.ChangeStatus("In waiting visit", free_id_loc_place, (int)fp.id_tariff_on_place); break; } } } } if (newfr != 0) { pl.FreePlace((long)newfr); } else { pl.ChangeStatus("Free", free_id_loc_place, 0); res = false ; } } return res; }
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; }
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; }
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()); }
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()); }
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" }); } }
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"); } }
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" }); } }