Ejemplo n.º 1
0
        public ActionResult Update(Hobby hobby)
        {
            ApiResult <Hobby> apiResult;

            if (ModelState.IsValid)
            {
                if (hobby.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        _hobbyRepository.Update(hobby);
                        _unitOfWork.Commit();
                        return(hobby);
                    }, "Hobby updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        _hobbyRepository.Create(hobby);
                        _unitOfWork.Commit();
                        return(hobby);
                    }, "Hobby created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <Hobby>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
 public void Create(Hobby entity)
 {
     _repository.Create(entity.ToGlobal());
 }
Ejemplo n.º 3
0
 public IActionResult Create([FromBody] Hobby entity)
 {
     _repository.Create(entity);
     return(Ok());
 }