/// <inheritdoc /> public async Task CreateAsync(FoodCreate food) { var entity = _mapper.Map <Food>(food); await _repo.CreateAsync(entity); await _repo.SaveAsync(); }
// GET: Food public ActionResult Create() { var viewModel = new FoodCreate(); var themes = _nightInnDb.Themes.Select(theme => new { ThemeId = theme.ThemeId, ThemeName = theme.ThemeName.ToString() }).ToList(); viewModel.ThemeList = new MultiSelectList(themes, "ThemeId", "ThemeName"); return(View(viewModel)); }
public IHttpActionResult Post(FoodCreate food) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateFoodService(); if (!service.CreateFood(food)) { return(InternalServerError()); } return(Ok()); }
public bool CreateFood(FoodCreate model) { var entity = new Food() { OwnerId = _userId, Name = model.Name, Amount = model.Amount, Calories = model.Calories }; using (var ctx = new ApplicationDbContext()) { ctx.Foods.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateFood(FoodCreate model) { var entity = new Food() { OwnerId = _userId, FoodName = model.FoodName, Ingredients = model.Ingredients, Instructions = model.Instructions, FoodServingSize = model.FoodServingSize, }; using (var ctx = new ApplicationDbContext()) { ctx.Foods.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateFood(FoodCreate model) { var entity = new Food() { OwnerId = _userId, Name = model.Name, //Species = model.Species, //ServingSize = model.ServingSize, PurchaseLink = model.PurchaseLink }; using (var ctx = new ApplicationDbContext()) { Food food = ctx.Foods.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(FoodCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateFoodService(); if (service.CreateFood(model)) { TempData["SaveResult"] = "Your Food was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Food could not be created."); return(View(model)); }
public bool CreateFood(FoodCreate model) { var entity = new Food() { OwnerId = _userId, Name = model.Name, Description = model.Description, Ingrediants = model.Ingredients, Cost = model.Cost, Allergens = model.Allergens, Servings = model.Servings, }; using (var ctx = new ApplicationDbContext()) { ctx.Foods.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task <IActionResult> Create([FromBody] FoodCreate food) { await _foodService.CreateAsync(food); return(new NoContentResult()); }