Exemplo n.º 1
0
        public IHttpActionResult Post([FromBody] Home home)
        {
            try
            {
                if (home == null)
                {
                    return(BadRequest("Home cannot be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var homeRepository = new Models.HomeRepository();
                var newHome        = homeRepository.Save(home);
                if (newHome == null)
                {
                    return(Conflict());
                }
                return(Created <Home>(Request.RequestUri + newHome.HomeId.ToString(),
                                      newHome));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 2
0
        // PUT: api/homes/5
        public IHttpActionResult Put(int id, [FromBody] Home home)
        {
            try
            {
                if (home == null)
                {
                    return(BadRequest("Home cannot be null"));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var homeRepository = new Models.HomeRepository();
                var updatedHome    = homeRepository.Save(id, home);
                if (updatedHome == null)
                {
                    return(NotFound());
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }