public async Task <IActionResult> Edit(int id, [Bind("GarbageServiceId,ServiceTypeId,HostMemberId,DistrictId,Address,StartTime,EndTime,IsActive,Latitude,Longitude,CanGo,GoRangeId,L3maxCount,L5maxCount,L14maxCount,L25maxCount,L33maxCount,L75maxCount,L120maxCount")] GarbageServiceOffer garbageServiceOffer) { if (id != garbageServiceOffer.GarbageServiceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(garbageServiceOffer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GarbageServiceOfferExists(garbageServiceOffer.GarbageServiceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DistrictId"] = new SelectList(_context.DistrictRefs, "DistrictId", "DistrictName", garbageServiceOffer.DistrictId); ViewData["GoRangeId"] = new SelectList(_context.RangeRefs, "RangeId", "RangeId", garbageServiceOffer.GoRangeId); ViewData["CityId"] = new SelectList(_context.CityRefs, "CityId", "CityName", garbageServiceOffer.District); ViewData["ServiceTypeId"] = new SelectList(_context.ServiceTypeRefs, "ServiceTypeId", "ServiceName", garbageServiceOffer.ServiceTypeId); GarbageServiceOffersViewModel gsovm = new GarbageServiceOffersViewModel(garbageServiceOffer); return(View(gsovm)); }
// GET: GarbageServiceOffers/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var garbageServiceOffer = await _context.GarbageServiceOffers.FindAsync(id); if (garbageServiceOffer == null) { return(NotFound()); } ViewData["DistrictId"] = new SelectList(_context.DistrictRefs, "DistrictId", "DistrictName", garbageServiceOffer.DistrictId); ViewData["GoRangeId"] = new SelectList(_context.RangeRefs, "RangeId", "RangeInMeters", garbageServiceOffer.GoRangeId); ViewData["CityId"] = new SelectList(_context.CityRefs, "CityId", "CityName", garbageServiceOffer.District); ViewData["ServiceTypeId"] = new SelectList(_context.ServiceTypeRefs, "ServiceTypeId", "ServiceName", garbageServiceOffer.ServiceTypeId); GarbageServiceOffersViewModel gsovm = new GarbageServiceOffersViewModel(garbageServiceOffer); return(View(gsovm)); }
public async Task <IActionResult> Index(GarbageServiceOffersViewModel g) { if (HttpContext.Session.GetInt32(cUtility.Current_User_Id) == null) { return(RedirectToAction("Login", "Member")); } g.HostMemberId = HttpContext.Session.GetInt32(cUtility.Current_User_Id).Value; if (g.Address != null) { g.StartTime = DateTime.Now; g.ServiceTypeId = 1; //get latlong from address DistrictRef dist = _context.DistrictRefs.Where(d => d.DistrictId == g.DistrictId) .Include(d => d.City).First(); string address = dist.City.CityName + dist.DistrictName + g.Address; var latlong = cUtility.addressToLatlong(address); g.Latitude = latlong[0]; g.Longitude = latlong[1]; g.IsActive = true; g.gso.L3available = g.L3maxCount; g.gso.L5available = g.L5maxCount; g.gso.L14available = g.L14maxCount; g.gso.L25available = g.L25maxCount; g.gso.L33available = g.L33maxCount; g.gso.L75available = g.L75maxCount; g.gso.L120available = g.L120maxCount; _context.Add(g.gso); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "ChatMessageRecords", new { grouptype = 2, groupid = g.gso.GarbageServiceId })); } ViewData["DistrictId"] = new SelectList(_context.DistrictRefs, "DistrictId", "DistrictName", g.DistrictId); ViewData["GoRangeId"] = new SelectList(_context.RangeRefs, "RangeId", "RangeInMeaters", g.GoRangeId); ViewData["CityId"] = new SelectList(_context.CityRefs, "CityId", "CityName", g.District); ViewData["ServiceTypeId"] = new SelectList(_context.ServiceTypeRefs, "ServiceTypeId", "ServiceName", g.ServiceTypeId); return(View(g)); }