Exemplo n.º 1
0
        [ValidateModel] //this will handle validation (and return with errors) before method is run
        public HttpResponseMessage InsertGroupCategory(HttpRequestMessage request, [FromBody] GroupCategoryViewModel groupCategory)
        {
            GroupCategory entity = groupCategory.ToEntity();

            //save it
            if (_service.InsertGroupCategory(entity))
            {
                GroupCategoryViewModel model = new GroupCategoryViewModel(entity);
                return(request.CreateResponse <GroupCategoryViewModel>(HttpStatusCode.OK, model));
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
Exemplo n.º 2
0
        [ValidateModel] //this will handle validation (and return with errors) before method is run
        public HttpResponseMessage UpdateGroupCategory(HttpRequestMessage request, int groupCategoryId, [FromBody] GroupCategoryViewModel groupCategory)
        {
            GroupCategory existing = _service.GetGroupCategory(groupCategoryId);

            if (existing != null)
            {
                //update entity model
                existing = groupCategory.ToEntity(existing);

                //save it
                if (_service.UpdateGroupCategory(existing))
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }