コード例 #1
0
        public async Task <IActionResult> Edit(EditAreaViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var area = await areaApi.GetAreaById(model.Id);

                    if (area == null)
                    {
                        return(NotFound());
                    }

                    area.Name = model.Name;
                    await areaApi.UpdateArea(area);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.Error = "Failed to Edit a Area";
                    return(View(model));
                }
            }
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Edit([FromRoute] int id = 0)
        {
            if (id == 0)
            {
                return(BadRequest("Id is null!"));
            }
            var area = await areaApi.GetAreaById(id);

            if (area == null)
            {
                return(NotFound());
            }

            EditAreaViewModel editAreaViewModel = new EditAreaViewModel()
            {
                Name = area.Name,
            };

            return(View(editAreaViewModel));
        }