public ActionResult Create(AirPort airPort) { bool flag = false; List <string> listId = new List <string>(); IEnumerable <AirPort> airPorts = _AirPortService.GetAll(); foreach (AirPort x in airPorts) { if (airPort.Id == x.Id) { flag = true; break; } } if (ModelState.IsValid) { if (flag == true) { ModelState.AddModelError("airportId", "ID is exist"); return(View(airPort)); } else { _AirPortService.Create(airPort); return(RedirectToAction("Index")); } } return(View(airPort)); }
public void SaveToDatabase(string row) { string id = (row.Split(',')[0]).Trim(); string subId = id.Substring(0, 2); switch (subId) { case "AP": _AirPortService.Create(new Model.AirPort { Id = id, Name = row.Split(',')[1], RunwaySize = int.Parse(row.Split(',')[2]), MaxFWParkingPlace = int.Parse(row.Split(',')[3]), MaxRWParkingPlace = int.Parse(row.Split(',')[5]) }); string[] listFWId = (row.Split(',')[4]).TrimEnd().Split(' '); foreach (string FWId in listFWId) { Model.AirPlane airplane = _AirPlaneService.GetById(FWId); airplane.AirPortId = id; _AirPlaneService.Update(airplane); } string[] listRWId = (row.Split(',')[6]).TrimEnd().Split(' '); foreach (string RWId in listRWId) { Model.Helicopter helicopter = _HelicopterService.GetById(RWId); helicopter.AirPortId = row.Split(',')[0]; _HelicopterService.Update(helicopter); } break; case "FW": _AirPlaneService.Create(new Model.AirPlane { Id = id, Model = row.Split(',')[1], AirPlaneType = row.Split(',')[2], CruiseSpeed = double.Parse(row.Split(',')[3]), EmptyWeight = double.Parse(row.Split(',')[4]), MaxTakeoffWeight = double.Parse(row.Split(',')[5]), MinNeededRunwaySize = double.Parse(row.Split(',')[6]) }); break; case "RW": _HelicopterService.Create(new Model.Helicopter { Id = id, Model = row.Split(',')[1], CruiseSpeed = double.Parse(row.Split(',')[2]), EmptyWeight = double.Parse(row.Split(',')[3]), MaxTakeoffWeight = double.Parse(row.Split(',')[4]), Range = double.Parse(row.Split(',')[5]) }); break; default: ViewBag.Message = "Load file false"; break; } }