Пример #1
0
        /// <inheritdoc />
        public async Task CreateAsync(FoodCreate food)
        {
            var entity = _mapper.Map <Food>(food);
            await _repo.CreateAsync(entity);

            await _repo.SaveAsync();
        }
Пример #2
0
        // 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));
        }
Пример #3
0
        public IHttpActionResult Post(FoodCreate food)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateFoodService();

            if (!service.CreateFood(food))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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));
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        public async Task <IActionResult> Create([FromBody] FoodCreate food)
        {
            await _foodService.CreateAsync(food);

            return(new NoContentResult());
        }