コード例 #1
0
 public ActionResult Create(MealCategoryViewModel mealCategoryViewModel)
 {
     try
     {
         _categoryController.PostCategory(mealCategoryViewModel);
         return View("Index");
     }
     catch
     {
         return View();
     }
 }
コード例 #2
0
        public HttpResponseMessage PostCategory(MealCategoryViewModel mealCategoryViewModel)
        {
            var category = _repositoryManager.Create(Mapper.Map<MealCategoryViewModel, MealCategory>(mealCategoryViewModel), mealCategoryViewModel.Name);
            if (ModelState.IsValid)
            {
                _repository.Add(category);

                var response = Request.CreateResponse(HttpStatusCode.Created, category);
                response.Headers.Location = new Uri(Url.Link("~/api/category/", new { id = category.Id }));
                return response;
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }