public ActionResult Create(MealCategoryViewModel mealCategoryViewModel) { try { _categoryController.PostCategory(mealCategoryViewModel); return View("Index"); } catch { return View(); } }
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); }