public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { RouteStop newroute = routeStop; //************************************************************IMPORTANT************************************************************* //************************************************************IMPORTANT************************************************************* //************************************************************IMPORTANT************************************************************* //You have to control the route number and and stop number in the database to ensure you select specific one for that typical route //************************************************************IMPORTANT************************************************************* //************************************************************IMPORTANT************************************************************* //************************************************************IMPORTANT************************************************************* if (_context.RouteStop.Where(r => r.BusRouteCode == newroute.BusRouteCode).Any(r => r.BusStopNumber == newroute.BusStopNumber) || (_context.RouteStop.Where(r => r.BusStopNumber == newroute.BusStopNumber).Any(r => r.OffsetMinutes == newroute.OffsetMinutes))) { if (_context.RouteStop.Where(r => r.BusRouteCode == newroute.BusRouteCode).Any(r => r.BusStopNumber == newroute.BusStopNumber)) { TempData["Routemessage"] = "This route already exists, please select new one "; } if (_context.RouteStop.Where(r => r.BusStopNumber == newroute.BusStopNumber && r.BusRouteCode == newroute.BusRouteCode).Any(r => r.OffsetMinutes == newroute.OffsetMinutes)) { if (newroute.OffsetMinutes == 0) { TempData["Stopmessage"] = "there is already a Zero offset"; } else { TempData["Stopmessage"] = "This offset already exists, please select new one"; } } return(RedirectToAction("Create", "RouteStop")); } //This allows user to specify the offsetminutes for the typical busstopnumber //if(_context.RouteStop.Where(r=>r.BusStopNumber==newroute.BusStopNumber).Any(r => r.OffsetMinutes==newroute.OffsetMinutes)) //{ // TempData["message"] = "This offset already exists, please select new one"; // return RedirectToAction("Create", "RouteStop"); //} if (ModelState.IsValid) { _context.Add(routeStop); TempData["message"] = "Stop sucessfully created"; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //**********************************************Special Atention****************************************************************** //****************if you want the record to be insert into correct bus route, you need to speciify the code you have selected***** //******************************************************************************************************************************** ViewData["BusRouteCode"] = new SelectList(_context.BusRoute.Where(r => r.BusRouteCode == HttpContext.Session.GetString("busRouteCode")), "BusRouteCode", "BusRouteCode", routeStop.BusRouteCode); //ViewData["BusStopNumber"] = new SelectList(_context.BusStop, "BusStopNumber", "BusStopNumber", routeStop.BusStopNumber); ViewData["BusStopNumber"] = new SelectList(_context.BusStop.OrderBy(b => b.Location), "BusStopNumber", "Location", routeStop.BusStopNumber); ViewData["OffsetMinutes"] = new SelectList(_context.RouteStop, "OffsetMinutes", "OffsetMinutes", routeStop.OffsetMinutes); return(View(routeStop)); }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { if (routeStop.OffsetMinutes < 0) { ModelState.AddModelError("", "OffsetMinutes must be 0 or greater than 0"); } string busRCode = String.Empty; if (Request.Cookies["BusRouteCode"] != null) { busRCode = Request.Cookies["BusRouteCode"]; } else if (HttpContext.Session.GetString("BusRouteCode") != null) { } var busRoute = _context.BusRoute.Where(a => a.BusRouteCode == busRCode).FirstOrDefault(); ViewData["BusRCode"] = busRoute.BusRouteCode; ViewData["BusRName"] = busRoute.RouteName; routeStop.BusRouteCode = busRCode; //Check for offset 0 if (routeStop.OffsetMinutes == 0) { var isZeroExists = _context.RouteStop.Where(a => a.OffsetMinutes == 0 && a.BusRouteCode == routeStop.BusRouteCode); if (isZeroExists.Any()) { ModelState.AddModelError("", "There is already record for offset minute 0"); } } var isDuplicate = _context.RouteStop.Where(a => a.BusRouteCode == routeStop.BusRouteCode && a.BusStopNumber == routeStop.BusStopNumber); if (isDuplicate.Any()) { ModelState.AddModelError("", "Duplicate Record"); } if (ModelState.IsValid) { try { _context.Add(routeStop); await _context.SaveChangesAsync(); TempData["message"] = "New Route Stop Added"; return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError("", ex.GetBaseException().Message); } } ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "BusRouteCode", routeStop.BusRouteCode); ViewData["BusStopNumber"] = new SelectList(_context.BusStop.OrderBy(a => a.Location), "BusStopNumber", "Location", routeStop.BusStopNumber); return(View(routeStop)); }
public async Task <IActionResult> Create([Bind("BusRouteCode,RouteName")] BusRoute busRoute) { if (ModelState.IsValid) { _context.Add(busRoute); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(busRoute)); }
public async Task <IActionResult> Create([Bind("BusStopNumber,GoingDowntown,Location,LocationHash")] BusStop busStop) { if (ModelState.IsValid) { _context.Add(busStop); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(busStop)); }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { if (ModelState.IsValid) { _context.Add(routeStop); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(await Create(Request.Cookies[cookieBusRouteCode])); }
public async Task <IActionResult> Create([Bind("CountryCode,Name,PhonePattern,PostalPattern")] Country country) { if (ModelState.IsValid) { _context.Add(country); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(country)); }
public async Task <IActionResult> Create([Bind("RouteScheduleId,BusRouteCode,Comments,IsWeekDay,StartTime")] RouteSchedule routeSchedule) { if (ModelState.IsValid) { _context.Add(routeSchedule); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "BusRouteCode", routeSchedule.BusRouteCode); return(View(routeSchedule)); }
public async Task <IActionResult> Create([Bind("ProvinceCode,Capital,CountryCode,Name,TaxCode,TaxRate")] Province province) { if (ModelState.IsValid) { _context.Add(province); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["CountryCode"] = new SelectList(_context.Country, "CountryCode", "CountryCode", province.CountryCode); return(View(province)); }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { if (ModelState.IsValid) { _context.Add(routeStop); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "BusRouteCode", routeStop.BusRouteCode); ViewData["BusStopNumber"] = new SelectList(_context.BusStop, "BusStopNumber", "BusStopNumber", routeStop.BusStopNumber); return(View(routeStop)); }
public async Task <IActionResult> Create([Bind("DriverId,City,DateHired,FirstName,FullName,HomePhone,LastName,PostalCode,ProvinceCode,Street,WorkPhone")] Driver driver) { if (ModelState.IsValid) { _context.Add(driver); await _context.SaveChangesAsync(); ViewData["message"] = "Successfully made driver"; return(RedirectToAction("Index")); } ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", driver.ProvinceCode); return(View(driver)); }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { if (ModelState.IsValid) { _context.Add(routeStop); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "RouteName", routeStop.BusRouteCode); var BusStopNumber = _context.BusStop.OrderBy(a => a.Location).Select(x => new { Text = x.Location + " " + x.GoingDowntown, Value = x.BusStopNumber }).ToList(); ViewBag.BusStopNumber = new SelectList(BusStopNumber, "Value", "Text"); return(View(routeStop)); }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { if (routeStop.OffsetMinutes < 0) { ModelState.AddModelError("", "Offset min can not under 0"); } else if (routeStop.OffsetMinutes == 0) { var isZero = _context.RouteStop.Where(a => a.OffsetMinutes == 0); if (isZero.Any()) { ModelState.AddModelError("", "offset 0min is already exist"); } } var isDouble = _context.RouteStop.Where(a => a.OffsetMinutes == routeStop.OffsetMinutes && a.BusRouteCode == routeStop.BusRouteCode); if (isDouble.Any()) { ModelState.AddModelError("", "is doubled"); } int count = _context.RouteStop.Where(a => a.OffsetMinutes == routeStop.OffsetMinutes).Count(); if (count > 3) { ModelState.AddModelError("", "cant over 3 times"); } //string BusRCode = string.Empty; //if (Request.Cookies["BusRouteCode"] != null) //{ // BusRCode = Request.Cookies["BusRouteCode"].ToString(); //} if (ModelState.IsValid) { _context.Add(routeStop); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "BusRouteCode", routeStop.BusRouteCode); ViewData["BusStopNumber"] = new SelectList(_context.BusStop, "BusStopNumber", "Location", routeStop.BusStopNumber); return(View(routeStop)); }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop, string name, string code) { if (routeStop.OffsetMinutes < 0) { ModelState.AddModelError("OffsetMinutes", "Can't be less than 0"); } if (routeStop.OffsetMinutes == 0 && _context.RouteStop.Any(x => x.OffsetMinutes == 0)) { ModelState.AddModelError("OffsetMinutes", "Can't be another than 0"); } if (routeStop.OffsetMinutes > 0) { if (!_context.RouteStop.Any(x => x.OffsetMinutes == 0)) { ModelState.AddModelError("OffsetMinutes", "First add a 0 route"); } } if (_context.RouteStop.Any(x => x.BusRouteCode == routeStop.BusRouteCode) && _context.RouteStop.Any(x => x.BusStopNumber == routeStop.BusStopNumber)) { ModelState.AddModelError("BusStopNumber", "same combination can't exist"); } if (ModelState.IsValid) { _context.Add(routeStop); await _context.SaveChangesAsync(); TempData["SuccessBusRoute"] = "Route Stop Created Succesfully!"; return(RedirectToAction("Index", "BusRoutes")); } ViewData["BusCode"] = code; ViewData["RouteName"] = name; ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "BusRouteCode", routeStop.BusRouteCode); ViewData["BusStopNumber"] = new SelectList(_context.BusStop.OrderBy(x => x.Location), "BusStopNumber", "Location"); return(View(routeStop)); }
public async Task <IActionResult> Create([Bind("DriverId,City,DateHired,FirstName,FullName,HomePhone,LastName,PostalCode,ProvinceCode,Street,WorkPhone")] Driver driver) { if (ModelState.IsValid) { try { _context.Add(driver); await _context.SaveChangesAsync(); TempData["message"] = "Driver successfully added"; return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", $"Error adding a new driver: {ex.GetBaseException().Message}"); } } ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", driver.ProvinceCode); return(View(driver)); }
public async Task <IActionResult> Create([Bind("DriverId,City,DateHired,FirstName,FullName,HomePhone,LastName,PostalCode,ProvinceCode,Street,WorkPhone")] Driver driver) { try { if (ModelState.IsValid) { _context.Add(driver); await _context.SaveChangesAsync(); TempData["message"] = $"Driver " + driver.LastName + " created"; return(RedirectToAction("Index")); } ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", driver.ProvinceCode); return(View(driver)); } catch (Exception ex) { ModelState.AddModelError("", "Cannot create a new driver" + ex.GetBaseException().Message); return(RedirectToAction(actionName: "Create", controllerName: "MKDriver")); } }
public async Task <IActionResult> Create([Bind("RouteStopId,BusRouteCode,BusStopNumber,OffsetMinutes")] RouteStop routeStop) { routeStop.BusRouteCode = HttpContext.Session.GetString("__busRouteCode");//get from session //condition ii var condition2 = _context.RouteStop .Where(x => x.BusRouteCode == routeStop.BusRouteCode) .Where(x => x.OffsetMinutes == 0) .Count(); //condition i if (routeStop.OffsetMinutes < 0 || routeStop.OffsetMinutes == null) { TempData["message"] = "Condition 1 dint pass"; ModelState.AddModelError("OffsetMinutes", "OffsetMinutes has to be >0 "); } else { TempData["message"] = "Condition 1 passed"; } //condition ii if (condition2 < 1) //shld return true for route 100 { //Has no start in db if (routeStop.OffsetMinutes != 0) //Has no start in input { TempData["message"] = "Please enter a start position"; ModelState.AddModelError("OffsetMinutes", "There must be a 0 OffsetMinutes"); } } else if (condition2 == 1) { //Has one start already in db if (routeStop.OffsetMinutes == 0) { ModelState.AddModelError("OffsetMinutes", "There is a 0 OffsetMinutes already"); } } { TempData["message"] = "Condition 2 passed"; } //condition iii var condition3 = (_context.RouteStop .Where(x => x.BusStopNumber == routeStop.BusStopNumber) .Where(x => x.BusRouteCode == routeStop.BusRouteCode) .Count()); if (condition3 >= 1) { TempData["message"] = "The bus stop for this route already exists"; ModelState.AddModelError("OffsetMinutes", "BusStopNumber for this route already exists"); } else { TempData["message"] = "Condition 3 passed"; } //Step iv if (ModelState.IsValid) { _context.Add(routeStop); await _context.SaveChangesAsync(); TempData["message"] = "Added to list"; return(RedirectToAction(nameof(Index))); } ViewData["BusRouteCode"] = new SelectList(_context.BusRoute, "BusRouteCode", "BusRouteCode", routeStop.BusRouteCode); ViewData["BusStopNumber"] = new SelectList(_context.BusStop.OrderBy(x => x.Location), "BusStopNumber", "Location", routeStop.BusStopNumber); ViewBag.Route = _context.BusRoute .Where(x => x.BusRouteCode == routeStop.BusRouteCode) .FirstOrDefault() .BusRouteCode; ViewBag.RouteName = _context.BusRoute .Where(x => x.BusRouteCode == routeStop.BusRouteCode) .FirstOrDefault() .RouteName; return(View(routeStop));//Step5 }