public PartialViewResult RemoveCustomCapacity(int capacityId) { var dbContext = new ApplicationDbContext(); var user = dbContext.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); var statistics = dbContext.StatisticsDbModels.FirstOrDefault(s => s.User.Id == user.Id); var searchModel = new JobSerachModel(); var dbEntity = dbContext.CustomPlaneCapacity.FirstOrDefault(x => x.User.Id == user.Id && x.Id == capacityId); if (dbEntity != null) { dbContext.CustomPlaneCapacity.Remove(dbEntity); statistics.CustomPlaneCapacity = null; searchModel.CustomPlaneCapacity = null; dbContext.SaveChanges(); } searchModel.CustomPlaneCapacityList = dbContext.CustomPlaneCapacity .Where(x => x.User.Id == user.Id).Select(c => new SelectListItem { Text = c.CustomNameCapacity, Value = c.Id.ToString(), }).ToList(); return(PartialView("CapacityListView", searchModel)); }
public ActionResult Index(JobSerachModel modelParam) { Session.Add("JobSerachModel", modelParam); var userStatistics = GetWebUserStatistics(); if (Request.Cookies[PassengersWeightCookie] != null && Request.Cookies[PassengersWeightCookie].Value != null) { long weight = Convert.ToInt32(Request.Cookies[PassengersWeightCookie].Value); TempData[PassengersWeightCookie] = GetWeight(Request, weight, userStatistics); } else { TempData[PassengersWeightCookie] = GetWeight(Request, PaxWeight, userStatistics); } TempData["PassengersWeightUnit"] = GetWeightUnit(Request); if (modelParam != null) { IList <JobListModel> jobs = new List <JobListModel>(); jobs = GenerateBoardJobs(modelParam, userStatistics); Session.Add("JobSearchResult", jobs); return(PartialView("Result", jobs.OrderBy(x => x.Dist).ToPagedList(1, 100))); } else { return(View("Index")); } }
public JsonResult Confirm(List <JobDbModel> jobList) { var dbContext = new ApplicationDbContext(); bool isPounds = GetWeightUnit(Request) == DataConversion.UnitPounds; // Check GUEST var user = dbContext.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); if (user != null && user.Email == AccountController.GuestEmail) { return(Json("Guest can't save!!!", JsonRequestBehavior.AllowGet));; } if (jobList != null) { if (Request.Cookies[PassengersWeightCookie] != null && Request.Cookies[PassengersWeightCookie].Value != null) { PaxWeight = int.Parse(Request.Cookies[PassengersWeightCookie].Value); } foreach (var selJob in jobList) { selJob.User = user; selJob.StartTime = DateTime.Now; selJob.EndTime = DateTime.Now; selJob.ChallengeExpirationDate = DateTime.Now.AddDays(-1); selJob.PaxWeight = PaxWeight; if (isPounds) { selJob.Cargo = DataConversion.ConvertPoundsToKilograms(selJob.Cargo); } if (Session["JobSerachModel"] != null) { JobSerachModel searchModel = (JobSerachModel)Session["JobSerachModel"]; if (!string.IsNullOrEmpty(searchModel.Alternative) && searchModel.Alternative.Length == 4) { selJob.AlternativeICAO = searchModel.Alternative.ToUpper(); } } dbContext.JobDbModels.Add(selJob); } dbContext.SaveChanges(); } return(Json("Saved", JsonRequestBehavior.AllowGet));; }
public ActionResult Update(int pax, int cargo, int paxWeight, string departure, string arrival, string type) { Response.Cache.SetCacheability(HttpCacheability.NoCache); long totalPayment = 0; long distance = 0; var weightUnit = GetWeightUnit(Request); var jobSerachModel = new JobSerachModel() { Departure = departure, Arrival = arrival, AviationType = "AirTransport", PassengerWeight = paxWeight, WeightUnit = weightUnit, UseCustomPlaneCapacity = true, CustomPlaneCapacity = new CustomPlaneCapacityDbModel() { CustomPassengerCapacity = pax, CustomCargoCapacityWeight = cargo }, }; var userStatistics = GetWebUserStatistics(); var jobs = GenerateBoardJobs(jobSerachModel, userStatistics); if (jobs.Count == 0) { return(null); } foreach (var j in jobs) { distance = j.Dist; totalPayment += j.Pay; } totalPayment = Convert.ToInt64(totalPayment * CHALLENGE_GAIN); var model = GetChallengerView(pax, cargo, paxWeight, departure, arrival, type, totalPayment, distance, weightUnit); if (model == null) { return(PartialView("BriefingView", new ChallengeViewModel())); } Session.Add(CHALLENGE_SESSION_MODEL, model); return(PartialView("BriefingView", model)); }
public PartialViewResult AddCustonCapacity(int passengers, int cargo, string name) { var dbContext = new ApplicationDbContext(); var user = dbContext.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); var statistics = dbContext.StatisticsDbModels.FirstOrDefault(s => s.User.Id == user.Id); var searchModel = new JobSerachModel(); if (!string.IsNullOrEmpty(name) && cargo > 0 && passengers > 0 && statistics != null) { var dbEntity = dbContext.CustomPlaneCapacity.FirstOrDefault(x => x.User.Id == user.Id && x.CustomNameCapacity == name); if (dbEntity == null) { var customCapacity = new CustomPlaneCapacityDbModel() { CustomCargoCapacityWeight = cargo, CustomPassengerCapacity = passengers, CustomNameCapacity = name.Trim(), User = user }; dbContext.CustomPlaneCapacity.Add(customCapacity); statistics.CustomPlaneCapacity = customCapacity; searchModel.CustomPlaneCapacity = customCapacity; } else { dbEntity.CustomCargoCapacityWeight = cargo; dbEntity.CustomPassengerCapacity = passengers; statistics.CustomPlaneCapacity = dbEntity; searchModel.CustomPlaneCapacity = dbEntity; } dbContext.SaveChanges(); } searchModel.CustomPlaneCapacityList = dbContext.CustomPlaneCapacity .Where(x => x.User.Id == user.Id).Select(c => new SelectListItem { Text = c.CustomNameCapacity, Value = c.Id.ToString(), }).ToList(); return(PartialView("CapacityListView", searchModel)); }
// GET: SearchJobs public ActionResult Index() { var dbContext = new ApplicationDbContext(); var user = dbContext.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); var statistics = dbContext.StatisticsDbModels.FirstOrDefault(s => s.User.Id == user.Id); var model = new JobSerachModel() { MaxRange = 450, MinRange = 10, WeightUnit = GetWeightUnit(Request) }; Session.Remove("JobSearchResult"); if (Session["JobSerachModel"] != null) { model = (JobSerachModel)Session["JobSerachModel"]; model.WeightUnit = GetWeightUnit(Request); } if (statistics != null) { if (statistics.CustomPlaneCapacity != null) { statistics.CustomPlaneCapacity.ImagePath = GetCustomCapacityPath(statistics.CustomPlaneCapacity.CustomNameCapacity); } model.UseCustomPlaneCapacity = statistics.UseCustomPlaneCapacity; model.CustomPlaneCapacity = statistics.CustomPlaneCapacity; model.CustomPlaneCapacityList = dbContext.CustomPlaneCapacity.Where(x => x.User.Id == user.Id).Select(c => new SelectListItem { Text = c.CustomNameCapacity, Value = c.Id.ToString(), }).ToList(); } return(View(model)); }
internal IList <JobListModel> GenerateBoardJobs(JobSerachModel model, StatisticsDbModel statistics) { IList <JobListModel> listBoardJobs = new List <JobListModel>(); try { var weightUnit = GetWeightUnit(Request); var dep = AirportDatabaseFile.FindAirportInfo(model.Departure); var arrival = AirportDatabaseFile.FindAirportInfo(model.Arrival); var depCoord = new GeoCoordinate(dep.Latitude, dep.Longitude); var randomPob = new Random(); var randomCargo = new Random(); int id = 0; bool validGaProfit = false; var arrCoord = new GeoCoordinate(arrival.Latitude, arrival.Longitude); var distMeters = depCoord.GetDistanceTo(arrCoord); var distMiles = (int)DataConversion.ConvertMetersToMiles(distMeters); // if (distMiles >= model.MinRange && distMiles <= model.MaxRange && arrival.ICAO.ToUpper() != dep.ICAO.ToUpper() && // arrival.ICAO.ToUpper() == model.Arrival.ToUpper()) if (arrival.ICAO.ToUpper() != dep.ICAO.ToUpper() && arrival.ICAO.ToUpper() == model.Arrival.ToUpper()) { var customCapacity = model.CustomPlaneCapacity; if (GetWeightUnit(Request) == DataConversion.UnitPounds) { customCapacity.CustomCargoCapacityWeight = DataConversion.ConvertPoundsToKilograms(customCapacity.CustomCargoCapacityWeight); } int index = randomPob.Next(14, 25); if (model.AviationType == "GeneralAviation" && model.UseCustomPlaneCapacity) { validGaProfit = customCapacity.CustomCargoCapacityWeight < 3000 && customCapacity.CustomPassengerCapacity < 30; } long gePobCount = 0, auxCargoCount = 0; for (int i = 0; i < index; i++) { long pob = 0; long cargo = 0; long profit = 0; bool isFisrtClass = Convert.ToBoolean(randomPob.Next(2)); var flightType = model.AviationType.Trim(); int alternateCargo = randomPob.Next(2); bool isCargo = alternateCargo == 0 || flightType == "Cargo"; if (isCargo) { int minCargo = 5; int maxCargo = 160; if (flightType == "AirTransport") { minCargo = 100; maxCargo = 3000; } ; if (flightType == "Cargo") { minCargo = 80; maxCargo = 3500; } if (flightType == "HeavyAirTransport") { minCargo = 800; maxCargo = 6000; } if (model.UseCustomPlaneCapacity) { var cargoCapacity = customCapacity.CustomCargoCapacityWeight; if (cargoCapacity < minCargo) { cargoCapacity = minCargo + 1; } cargo = randomCargo.Next(minCargo, cargoCapacity); if (auxCargoCount + cargo > cargoCapacity) { cargo = cargoCapacity - auxCargoCount; if (cargo == 0) { continue; } auxCargoCount = cargoCapacity; } else { auxCargoCount += cargo; } } else { cargo = randomCargo.Next(minCargo, maxCargo); } if (flightType == "GeneralAviation") { if (validGaProfit) { profit = Convert.ToInt32(taxCargoGE * distMiles * cargo); profit += (140 / customCapacity.CustomCargoCapacityWeight); } else { profit = Convert.ToInt32(taxCargo * distMiles * cargo); } } else if (flightType == "AirTransport") { profit = Convert.ToInt32(taxCargo * distMiles * cargo); } else if (flightType == "Cargo") { profit = Convert.ToInt32((taxCargo + 0.0005) * distMiles * cargo); } else // HeavyAirTransport { profit = Convert.ToInt32(taxCargo * distMiles * cargo); } } else { int minPob = 1; int maxPob = 12; if (flightType == "AirTransport") { minPob = 10; maxPob = 80; } ; if (flightType == "HeavyAirTransport") { minPob = 50; maxPob = 140; } if (model.UseCustomPlaneCapacity) { if (customCapacity.CustomPassengerCapacity < minPob) { customCapacity.CustomPassengerCapacity = minPob + 1; } pob = randomPob.Next(minPob, customCapacity.CustomPassengerCapacity); if (gePobCount + pob > customCapacity.CustomPassengerCapacity) { pob = customCapacity.CustomPassengerCapacity - gePobCount; if (pob == 0) { continue; } gePobCount = customCapacity.CustomPassengerCapacity; } else { gePobCount += pob; } } else { pob = randomPob.Next(minPob, maxPob); } if (flightType == "GeneralAviation") { isFisrtClass = true; /// Always premium for GA if (validGaProfit) { profit = Convert.ToInt32(taxFirstGE * distMiles * pob); profit += ((distMiles * 2) / customCapacity.CustomPassengerCapacity); } else { profit = Convert.ToInt32(taxFirstC * distMiles * pob); } } else if (flightType == "AirTransport") { profit = isFisrtClass ? Convert.ToInt32(taxFirstC * distMiles * pob) : Convert.ToInt32(taxEcon * distMiles * pob); } else // HeavyAirTransport { profit = isFisrtClass ? Convert.ToInt32(taxFirstC * distMiles * pob) : Convert.ToInt32(taxEcon * distMiles * pob); } } cargo = GetWeight(Request, cargo, statistics); listBoardJobs.Add(new JobListModel() { Id = id++, Departure = dep, Arrival = arrival, Dist = distMiles, Pax = pob, Cargo = cargo, PayloadLabel = (isCargo) ? "[Cargo] " : (isFisrtClass) ? "[Full price] " : "[Promo] ", PayloadView = (isCargo) ? cargo + weightUnit : (isFisrtClass) ? pob + " Pax" : pob + " Pax", Pay = profit, FirstClass = isFisrtClass, AviationType = model.AviationType, IsCargo = isCargo }); } } } catch (Exception ex) { ModelState.AddModelError("error", ex.Message); } return(listBoardJobs.OrderBy(j => j.Arrival).ThenBy(x => x.PayloadLabel).ToList()); }