Exemplo n.º 1
0
        // GET: Boxers/Create
        public ActionResult Create()
        {
            BoxersDetailsViewModel model = new BoxersDetailsViewModel();

            ViewBag.Title = "Create";

            return View(model);
        }
Exemplo n.º 2
0
        // GET: Boxers/Edit/5
        public ActionResult Edit(int id)
        {
            var boxer = webClient.ExecuteGet<BoxerDto>(new Models.ApiRequest() { EndPoint = string.Format("boxers/{0}", id) });

            BoxersDetailsViewModel model = new BoxersDetailsViewModel();

            model.Name = boxer.Name;

            ViewBag.Title = "Edit";

            return View("Create", model);
        }
Exemplo n.º 3
0
        public ActionResult Create(BoxersDetailsViewModel model)
        {
            try
            {
                object existingTest = webClient.ExecutePost<object>(new Models.ApiRequest()
                {
                    EndPoint = string.Format("boxers"),
                    Request = new BoxerDto()
                    {
                        Name = model.Name
                    }
                });

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 4
0
        public ActionResult Edit(int id, BoxersDetailsViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        var response = webClient.ExecutePut<object>(new Models.ApiRequest()
                        {
                            EndPoint = string.Format("boxers/{0}", model.Id),
                            Request = new BoxerDto()
                            {
                                Name = model.Name
                            }
                        });

                        return RedirectToAction("Index");
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("generalError", e.Message);

                        return View(model);
                    }
                }

                return View(model);
            }
            catch
            {
                return View(model);
            }
        }