Exemplo n.º 1
0
        public HttpResponseMessage NewGroupCategory(HttpRequestMessage request)
        {
            GroupCategory          groupCategory = new GroupCategory();
            GroupCategoryViewModel model         = new GroupCategoryViewModel(groupCategory);

            return(request.CreateResponse <GroupCategoryViewModel>(HttpStatusCode.OK, model));
        }
Exemplo n.º 2
0
        public HttpResponseMessage GetGroupCategory(HttpRequestMessage request, int groupCategoryId)
        {
            GroupCategory groupCategory = _service.GetGroupCategory(groupCategoryId);

            if (groupCategory != null)
            {
                GroupCategoryViewModel model = new GroupCategoryViewModel(groupCategory);
                return(request.CreateResponse <GroupCategoryViewModel>(HttpStatusCode.OK, model));
            }

            return(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
Exemplo n.º 3
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.º 4
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));
        }