// GET: Items/Edit/5 public IActionResult Edit(int id) { // we pass the current values into the Edit view // so that the input fields can be pre-populated instead of blank // (important for good UX) Domain.Model.Review review = RepoRev.GetReviewById(id); var viewModel = new ReviewViewModel { ReviewId = review.Id, UserName = RepoPers.GetPersonById(review.PersonId).Username, Password = RepoPers.GetPersonById(review.PersonId).Password, SellerName = RepoSell.GetSellerById(review.SellerId).Name, Score = review.Score, Comment = review.Comment }; List <string> mySellers = new List <string> (); foreach (var val in RepoSell.GetSellersByName().ToList()) { mySellers.Add(val.Name); } ViewData["SellerName"] = new SelectList(mySellers); List <string> myPeople = new List <string> (); foreach (var val in RepoPers.GetPeopleByName().ToList()) { myPeople.Add(val.Username); } ViewData["UserName"] = new SelectList(myPeople); return(View(viewModel)); }
public ActionResult Finalize() { try { double price = 0; List <Domain.Model.Item> orderItemsList = new List <Domain.Model.Item>(); foreach (var val in MyOrder.itemsInOrder) { orderItemsList.Add(RepoItem.GetItemById(val)); price = price + RepoItem.GetItemById(val).Price; } Domain.Model.Order myNewOrder = new Domain.Model.Order { UserId = RepoPers.GetPeopleByName(MyOrder.Username).First().Id, Date = DateTime.Now, Price = price, Items = orderItemsList }; RepoOrd.AddOrder(myNewOrder); RepoOrd.Save(); MyOrder.Username = ""; MyOrder.itemsInOrder = null; } catch { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public ActionResult ViewCart(int id = 0) { double price = 0; List <Domain.Model.Item> orderItemsList = new List <Domain.Model.Item>(); foreach (var val in MyOrder.itemsInOrder) { orderItemsList.Add(RepoItem.GetItemById(val)); price = price + RepoItem.GetItemById(val).Price; } if (id > 0) { MyOrder.itemsInOrder.Add(id); orderItemsList.Add(RepoItem.GetItemById(id)); price = price + RepoItem.GetItemById(id).Price; } var viewModel = new DetailedOrderViewModel { PersonName = MyOrder.Username, StoreName = RepoStore.GetStoreById(RepoPers.GetPeopleByName(MyOrder.Username).First(p => p.Username.ToLower() == MyOrder.Username.ToLower()).StoreId).Name, DateOfOrder = DateTime.Now, Price = price, ItemList = orderItemsList, SuggestedItem = GetSuggestedItem.Suggest(RepoItem, RepoStore, RepoOrd, RepoTopi, RepoSell, RepoPers, RepoRev, MyOrder) }; return(View(viewModel)); }
// GET: Items/Delete/5 public IActionResult Delete(int id) { Domain.Model.Review review = RepoRev.GetReviewById(id); var viewModel = new ReviewViewModel { ReviewId = review.Id, UserName = RepoPers.GetPersonById(review.PersonId).Username, Password = RepoPers.GetPersonById(review.PersonId).Password, SellerName = RepoSell.GetSellerById(review.SellerId).Name, Score = review.Score, Comment = review.Comment }; 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()); } }
// GET: Items/Create public IActionResult Create() { List <string> myPeople = new List <string> (); foreach (var val in RepoPers.GetPeopleByName().ToList()) { myPeople.Add(val.Username); } ViewData["UserName"] = new SelectList(myPeople); List <string> mySellers = new List <string> (); foreach (var val in RepoSell.GetSellersByName().ToList()) { mySellers.Add(val.Name); } ViewData["SellerName"] = new SelectList(mySellers); return(View()); }
public IActionResult Create([Bind("UserName,Password,SellerName,Score,Comment")] ReviewViewModel viewModel) { try { if (ModelState.IsValid) { if (viewModel.Password != RepoPers.GetPeopleByName(viewModel.UserName).First(p => p.Username.ToLower() == viewModel.UserName.ToLower()).Password) { return(View(viewModel)); } var review = new Domain.Model.Review { Id = viewModel.ReviewId, Comment = viewModel.Comment, Score = viewModel.Score, PersonId = RepoPers.GetPeopleByName(viewModel.UserName).First(p => p.Username.ToLower() == viewModel.UserName.ToLower()).Id, SellerId = RepoSell.GetSellersByName(viewModel.SellerName).First(p => p.Name.ToLower() == viewModel.SellerName.ToLower()).Id }; List <string> mySellers = new List <string> (); foreach (var val in RepoSell.GetSellersByName().ToList()) { mySellers.Add(val.Name); } ViewData["SellerName"] = new SelectList(mySellers); List <string> myPeople = new List <string> (); foreach (var val in RepoPers.GetPeopleByName().ToList()) { myPeople.Add(val.Username); } ViewData["UserName"] = new SelectList(myPeople); RepoRev.AddReview(review); RepoRev.Save(); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); } catch { return(View(viewModel)); } }
public ActionResult LogIn([Bind("Username,Password")] LogInViewModel viewModelLog) { try { if (ModelState.IsValid) { MyOrder.Username = viewModelLog.Username; var itemlogin = PopulateItemList.Populate(RepoItem, RepoStore, RepoOrd, RepoTopi, RepoSell, RepoPers, RepoRev, MyOrder); // new ItemAnLogInViewModel if (RepoPers.GetPeopleByName(viewModelLog.Username).First(p => p.Username == viewModelLog.Username).Password == viewModelLog.Password) { return(View("Order", itemlogin)); } } return(View(viewModelLog)); } catch { return(View(viewModelLog)); } }
// GET: Items public ActionResult Index([FromQuery] string search = "") { List <Domain.Model.Review> reviews = RepoRev.GetReviewByUserName(); List <ReviewViewModel> realReviews = new List <ReviewViewModel>(); foreach (var val in reviews) { realReviews.Add(new ReviewViewModel { ReviewId = val.Id, UserName = RepoPers.GetPersonById(val.PersonId).Username, Password = RepoPers.GetPersonById(val.PersonId).Password, SellerName = RepoSell.GetSellerById(val.SellerId).Name, Score = val.Score, Comment = val.Comment }); } if (search != null) { return(View(realReviews.FindAll(p => p.UserName.ToLower().Contains(search.ToLower()) || p.SellerName.ToLower().Contains(search.ToLower()) || RepoRev.GetReviewById(p.ReviewId).Comment.ToLower().Contains(search.ToLower())))); } return(View(realReviews)); }
public IActionResult Edit([FromRoute] int id, [Bind("UserName,SellerName,Score,Comment,Password")] ReviewViewModel viewModel) { try { if (ModelState.IsValid) { Domain.Model.Review review = RepoRev.GetReviewById(id); review.Comment = viewModel.Comment; review.Score = viewModel.Score; review.PersonId = RepoPers.GetPeopleByName(viewModel.UserName).First(p => p.Username.ToLower() == viewModel.UserName.ToLower()).Id; review.SellerId = RepoSell.GetSellersByName(viewModel.SellerName).First(p => p.Name.ToLower() == viewModel.SellerName.ToLower()).Id; RepoRev.UpdateReview(review); RepoRev.Save(); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); } catch (Exception) { return(View(viewModel)); } }