// GET: Matches/Create public ActionResult Create() { MatchesDetailsViewModel model = new MatchesDetailsViewModel(); ViewBag.Title = "Create"; var boxers = webClient.ExecuteGet<IEnumerable<BoxerDto>>(new Models.ApiRequest() { EndPoint = "boxers" }) ?.Select(q => new BoxersListItem() { Id = q.Id, Name = q.Name })?.ToList(); if (boxers != null) { SelectList list = new SelectList(boxers, "Id", "Name", 1); ViewData["Boxers"] = list; } return View(model); }
// GET: Matches/Edit/5 public ActionResult Edit(int id) { var match = webClient.ExecuteGet<MatchDto>(new Models.ApiRequest() { EndPoint = string.Format("matches/{0}", id) }); MatchesDetailsViewModel model = new MatchesDetailsViewModel(); model.Boxer1Id = match.Boxer1Id; model.Boxer2Id = match.Boxer2Id; model.Address = match.Address; model.Time = match.Time; model.Description = match.Description; ViewBag.Title = "Edit"; var boxers = webClient.ExecuteGet<IEnumerable<BoxerDto>>(new Models.ApiRequest() { EndPoint = "boxers" }) ?.Select(q => new BoxersListItem() { Id = q.Id, Name = q.Name })?.ToList(); if (boxers != null) { SelectList list = new SelectList(boxers, "Id", "Name", model.Boxer1Id); ViewData["Boxers1"] = list; list = new SelectList(boxers, "Id", "Name", model.Boxer2Id); ViewData["Boxers2"] = list; } return View("Create", model); }
public ActionResult Edit(int id, MatchesDetailsViewModel model) { try { if (ModelState.IsValid) { try { var response = webClient.ExecutePut<object>(new Models.ApiRequest() { EndPoint = string.Format("matches/{0}", model.Id), Request = new MatchDto() { Boxer1Id = model.Boxer1Id, Boxer2Id = model.Boxer2Id, Address = model.Address, Time = model.Time, Description = model.Description } }); return RedirectToAction("Index"); } catch (Exception e) { ModelState.AddModelError("generalError", e.Message); return View(model); } } return View(model); } catch { return View(model); } }
public ActionResult Create(MatchesDetailsViewModel model) { try { object newMatch = webClient.ExecutePost<object>(new Models.ApiRequest() { EndPoint = string.Format("matches"), Request = new MatchDto() { Boxer1Id = model.Boxer1Id, Boxer2Id = model.Boxer2Id, Address = model.Address, Time = model.Time, Description = model.Description } }); return RedirectToAction("Index"); } catch { return View(); } }