public ActionResult Create(StoreLocator storeLocator) { if (ModelState.IsValid) { try { var state = db.States.Find(int.Parse(storeLocator.State)); var city = db.Cities.Find(int.Parse(storeLocator.City)); storeLocator.State = state.StateName; storeLocator.City = city.CityName; } catch { storeLocator.State = ""; storeLocator.City = ""; } storeLocator.DateAdded = DateTime.Now; storeLocator.Ipaddress = GetIpaddress(); db.StoreLocators.Add(storeLocator); db.SaveChanges(); ModelState.Clear(); ViewBag.StateList1 = db.States.ToList(); ViewBag.Message = "Store Locator has been added uccessfully."; return(View(new StoreLocator())); } return(View(storeLocator)); }
// POST: StoreLocators/Delete/5 //[HttpPost, ActionName("Delete")] //[ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { StoreLocator storeLocator = db.StoreLocators.Find(id); db.StoreLocators.Remove(storeLocator); db.SaveChanges(); return(RedirectToAction("ViewStoreLocator")); }
public ActionResult Edit(StoreLocator storeLocator) { if (ModelState.IsValid) { db.Entry(storeLocator).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewStoreLocator")); } return(View(storeLocator)); }
// GET: StoreLocators/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StoreLocator storeLocator = db.StoreLocators.Find(id); if (storeLocator == null) { return(HttpNotFound()); } return(View(storeLocator)); }
public static void Initialize(TestContext context) { var config = new TestConfig { ResetHttpContext = true }; var stores = new BaseIntegrationTest <StoreLocator, StoreLocatorResponse>(config); var storesRequest = RequestBuilder.GetStoresRequestWithLatLong(); _result = (Response <StoreLocatorResponse>)stores.TestObject.Execute(storesRequest); _testObject = stores.TestObject; }
public static void Initialize(TestContext context) { var config = new TestConfig { ResetHttpContext = true }; var stores = new BaseIntegrationTest <StoreLocator, StoreLocatorResponse>(config); var storesRequest = RequestBuilder.GetStoresRequestWithZip(); _result = (Response <StoreLocatorResponse>)stores.TestObject.Execute(storesRequest); var test = _result.resultset.Locations.Find(x => x.Hours.Count != 7); _testObject = stores.TestObject; }
public ActionResult Edit(StoreModel model) { var store = _storeRepository.GetById(model.Id); if (ModelState.IsValid) { store = model.ToEntity(store); //add a default store locator when add new if (store.IsNew == true) { var storeLocator = new StoreLocator { Name = "DEF", StoreId = model.Id, IsDefault = true }; _storeLocatorRepository.Insert(storeLocator); } //always set IsNew to false when saving store.IsNew = false; //update attributes _storeRepository.Update(store); //commit all changes this._dbContext.SaveChanges(); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(new NullJsonResult()); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }
public NorthwindAdapter() { StoreLocator = new StoreLocator(); RequestPerformerLocator = new RequestPerformerLocator(); }
public NorthwindAdapter() { StoreLocator = new StoreLocator(); RequestPerformerLocator = new RequestPerformerLocator(); }
public ActionResult Index(StoreLocator sl) { //if (ModelState.IsValid) //{ try { string State = ""; string City = ""; if (sl.Pin == null && sl.State == "Select State") { BindStateFromSL(); // TempData["StateError"] = "Please Select State"; ViewBag.StateError = "Please Select State"; // working // ModelState.AddModelError(string.Empty, "Please Select State"); this is also working return(View("Index", sl)); } if (sl.State != "Select State") { var state = db.States.Find(int.Parse(sl.State)); State = state.StateName; } if (sl.City != "Select City") { var city = db.Cities.Find(int.Parse(sl.City)); City = city.CityName; } if (sl.Pin == null && sl.City == null) { BindStateFromSL(); ViewBag.CityError = "Please Select City"; return(View("Index", sl)); } if (sl.Pin != null) { // Location(sl.Pin); var result = db.StoreLocators.Where(x => x.Pin == sl.Pin).ToList(); //if (result.Count == 0) //{ // ViewBag.NotFoundMsg = "No Address Found!"; //} ViewBag.AddressDetails = result; ModelState.Clear(); } else if (sl.State != null && sl.City != null) { // Location(State, City); var result = db.StoreLocators.Where(x => x.State == State && x.City == City).ToList(); //if(result.Count==0) //{ // ViewBag.NotFoundMsg = "No Address Found!"; //} ViewBag.AddressDetails = result; ModelState.Clear(); BindStateFromSL(); return(View("Index", result)); } } catch { return(RedirectToAction("Index")); } //} BindStateFromSL(); //ModelState.Clear(); return(View("Index", sl)); }
public ActionResult SaveChanges([Bind(Prefix = "updated")] List <StoreLocatorModel> updatedItems, [Bind(Prefix = "created")] List <StoreLocatorModel> createdItems, [Bind(Prefix = "deleted")] List <StoreLocatorModel> deletedItems) { if (ModelState.IsValid) { try { //Create StoreLocators if (createdItems != null) { foreach (var model in createdItems) { var storeLocator = _storeLocatorRepository.GetAll().Where(c => c.Id == model.Id).FirstOrDefault(); if (storeLocator == null) { storeLocator = new StoreLocator { Name = model.Name, StoreId = model.StoreId }; _storeLocatorRepository.Insert(storeLocator); } } } //Update StoreLocators if (updatedItems != null) { foreach (var model in updatedItems) { var storeLocator = _storeLocatorRepository.GetById(model.Id); storeLocator.Name = model.Name; _storeLocatorRepository.Update(storeLocator); } } //Delete StoreLocators if (deletedItems != null) { foreach (var model in deletedItems) { var storeLocator = _storeLocatorRepository.GetById(model.Id); if (storeLocator != null) { _storeLocatorRepository.Deactivate(storeLocator); } } } _dbContext.SaveChanges(); SuccessNotification(_localizationService.GetResource("Record.Saved")); return(new NullJsonResult()); } catch (Exception e) { return(Json(new { Errors = e.Message })); } } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }