Beispiel #1
0
        public ActionResult Create(Area area)
        {
            if (ModelState.IsValid)
            {
                _areaRepository.Add(area);
                _areaRepository.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(area));
        }
Beispiel #2
0
        public IActionResult Create([FromBody] AreaViewModel area)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Area _newArea = new Area {
                Name = area.Name
            };

            _areaRepository.Add(_newArea);
            _areaRepository.Commit();

            area = Mapper.Map <Area, AreaViewModel>(_newArea);

            CreatedAtRouteResult result = CreatedAtRoute("GetArea", new { controller = "Areas", id = area.Id }, area);

            return(result);
        }