public IActionResult Create([Bind("LocationName")] StoreViewModel viewModel) { try { if (ModelState.IsValid) { var store = new Domain.Model.Store { Id = viewModel.StoreId, Name = viewModel.LocationName, Items = RepoItem.GetItemsByStoreName(viewModel.LocationName) .FindAll(p => p.StoreId == (RepoStore.GetStoresByName(viewModel.LocationName) .First(p => p.Name == viewModel.LocationName).Id)), }; RepoStore.AddStore(store); RepoStore.Save(); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); } catch { return(View(viewModel)); } }
public ActionResult Delete(int id, [BindNever] IFormCollection collection) { try { RepoPers.DeletePeopleByStoreId(id); RepoItem.DeleteItemByStoreId(id); RepoStore.DeleteStoreById(id); RepoStore.Save(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public IActionResult Edit([FromRoute] int id, [Bind("LocationName")] StoreViewModel viewModel) { try { if (ModelState.IsValid) { Domain.Model.Store store = RepoStore.GetStoreById(id); store.Name = viewModel.LocationName; store.Items = RepoItem.GetItemsByStoreName(viewModel.LocationName) .FindAll(p => p.StoreId == (RepoStore.GetStoresByName(viewModel.LocationName) .First(p => p.Name == viewModel.LocationName).Id)); RepoStore.UpdateStore(store); RepoStore.Save(); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); } catch (Exception) { return(View(viewModel)); } }