Example #1
0
        public async Task <IActionResult> Create([Bind("Name,Description,Notes,StoreID")] Ingredient ingredient)
        {
            try
            {
                if (ingredient.Name != null && !String.IsNullOrEmpty(ingredient.Name))
                {
                    ingredient.Guid      = Guid.NewGuid();
                    ingredient.CreatedAt = DateTime.UtcNow;

                    _db.Add(ingredient);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator. " + e);
            }

            IngredientsData data = new IngredientsData()
            {
                Ingredient = ingredient,
                Stores     = _db.Stores.ToList()
            };

            return(View(data));
        }
Example #2
0
        public IActionResult Create()
        {
            IngredientsData data = new IngredientsData()
            {
                Stores = _db.Stores.ToList()
            };

            return(View(data));
        }
        public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.Ingredients.Any())
            {
                return;
            }

            var ingredients = IngredientsData.GetIngredients();
            await dbContext.Ingredients.AddRangeAsync(ingredients);
        }
Example #4
0
    public static void SaveIngredients(Blackhole blackhole)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        //string path = Application.persistentDataPath + "/ingredients.bla";
        string     path   = "ingredients.bla";
        FileStream stream = new FileStream(path, FileMode.Create);

        IngredientsData data = new IngredientsData(blackhole);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Example #5
0
        public IActionResult Detail(long id)
        {
            Ingredient ingredient = _db.Ingredients.First(x => x.ID == id);

            IngredientsData data = new IngredientsData()
            {
                Ingredient = ingredient,
                Stores     = _db.Stores.ToList()
            };

            return(View("Detail", data));
        }
Example #6
0
    public static IngredientsData LoadIngredients()
    {
        //string path = Application.persistentDataPath + "/ingredients.bla";
        string path = "ingredients.bla";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);

            IngredientsData data = formatter.Deserialize(stream) as IngredientsData;
            stream.Close();

            return(data);
        }
        else
        {
            //Debug.LogError("Save file not found in " + path);
            return(null);
        }
    }
        public List <IngredientDBModel> GetAllIngredients()
        {
            IngredientsData data = new IngredientsData();

            return(data.GetAllIngredients());
        }
Example #8
0
        public async Task <ActionResult <IEnumerable <String> > > GetUserAllergyData(String userId, [FromBody] IngredientsData ingredientsData)
        {
            var allergyData = allergySpotterService.getAllergicIngredients(userId, ingredientsData.ingredients);

            if (allergyData == null)
            {
                return(NotFound());
            }

            return(Ok(allergyData));
        }