public void UpdateIngredient(WhatYouGotLibrary.Models.Ingredient ingredient)
        {
            Entities.Ingredient currentIngredient = _context.Ingredient.Find(ingredient.Id);
            Entities.Ingredient newIngredient     = Mapper.Map(ingredient);

            _context.Entry(currentIngredient).CurrentValues.SetValues(newIngredient);
        }
        public IActionResult Create(IngredientViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.SchoolUuid == null && AuthContextService.CurrentUser.SchoolGuid == null)
            {
                response.SetFailed("请登录学校账号");
                return(Ok(response));
            }
            using (_dbContext)
            {
                if (model.SchoolUuid != null)
                {
                    var query = _dbContext.Ingredient.FirstOrDefault(x => x.IsDelete != 1 && x.SchoolUuid == model.SchoolUuid && x.FoodName == model.FoodName);
                    if (query != null)
                    {
                        response.SetFailed("该食材已存在");
                        return(Ok(response));
                    }
                }
                else
                {
                    var query = _dbContext.Ingredient.FirstOrDefault(x => x.IsDelete != 1 && x.SchoolUuid == AuthContextService.CurrentUser.SchoolGuid && x.FoodName == model.FoodName);
                    if (query != null)
                    {
                        response.SetFailed("该食材已存在");
                        return(Ok(response));
                    }
                }
                var Ingredient = new Entities.Ingredient()
                {
                    IngredientUuid = Guid.NewGuid(),
                    FoodName       = model.FoodName,
                    TypeUuid       = model.TypeUuid,
                    HeatEnergy     = model.HeatEnergy,
                    Protein        = model.Protein,
                    Fat            = model.Fat,
                    Saccharides    = model.Saccharides,
                    Va             = model.Va,
                    AddTime        = model.AddTime,
                    AddPeople      = model.AddPeople,
                    IsDelete       = 0,
                    Accessory      = model.Accessory,
                    SchoolUuid     = model.SchoolUuid != null ? model.SchoolUuid : AuthContextService.CurrentUser.SchoolGuid,
                };
                _dbContext.Ingredient.Add(Ingredient);
                var num = _dbContext.SaveChanges();
                if (num > 0)
                {
                    response.SetSuccess("添加成功");
                }
                else
                {
                    response.SetFailed("添加失败");
                }

                return(Ok(response));
            }
        }
示例#3
0
 public static void Insert(Entities.Ingredient entity, ContextType contextType = ContextType.Default)
 {
     using (var context = ContextSwitcher.CreateContext(contextType))
     {
         context.Ingredients.Add(entity);
         context.SaveChanges();
     }
 }
        /// <summary>
        /// Method to convert a ingredient to an entity class so it can be added to the database
        /// </summary>
        /// <param name="ingredient">The ingredient to be converted</param>
        /// <returns>An instance of the ingredient entity</returns>
        private Entities.Ingredient CreateIngredientEntity(IngredientDTO ingredient)
        {
            var ingredientEntity = new Entities.Ingredient
            {
                Name = ingredient.Name
            };

            return(ingredientEntity);
        }
示例#5
0
 public static Ingredient ConvertToDTO(this Entities.Ingredient ingredient)
 {
     return(new Ingredient
     {
         ID = ingredient.ID,
         Weight = ingredient.Weight,
         TypeID = ingredient.IngredientType.ID,
         Type = ingredient.IngredientType.Name
     });
 }
示例#6
0
        // Storage to domain

        public static Result <Ingredient> ToIngredientDomain(this Entities.Ingredient dbIngredient)
        {
            Result <IngredientNameValue>     ingredientNameOrError     = IngredientNameValue.Create(dbIngredient.Name);
            Result <IngredientQuantityValue> ingredientQuantityOrError = IngredientQuantityValue.Create(dbIngredient.Quantity);

            Result okOrError = Result.FirstFailureOrOk(ingredientNameOrError, ingredientQuantityOrError);

            if (okOrError.IsFailure)
            {
                return(Result.FromError <Ingredient>(okOrError));
            }

            return(Ingredient.Create(dbIngredient.Id,
                                     dbIngredient.CreatedOn,
                                     dbIngredient.DeletedOn,
                                     ingredientNameOrError.Value,
                                     ingredientQuantityOrError.Value,
                                     dbIngredient.PizzaFk));
        }
示例#7
0
        public IActionResult ToSync()
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var schoollist = _dbContext.School.Where(x => x.IsDelete == 0).ToList();
                var schoolEnt  = schoollist.Find(x => x.SchoolName == "萧山三中");
                //var schoolEnt = schoollist.Find(x => x.SchoolName == "xxxx1");
                schoollist.Remove(schoolEnt);
                var ingredients = _dbContext.Ingredient.Where(x => x.SchoolUuid == schoolEnt.SchoolUuid && x.IsDelete == 0).ToList();
                for (int n = 0; n < schoollist.Count; n++)
                {
                    for (int i = 0; i < ingredients.Count; i++)
                    {
                        if (!_dbContext.Ingredient.Any(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && x.FoodName == ingredients[i].FoodName))
                        {
                            var ing = new Entities.Ingredient()
                            {
                                IngredientUuid = Guid.NewGuid(),
                                SchoolUuid     = schoollist[n].SchoolUuid,
                                AddTime        = DateTime.Now.ToString("yyyy-MM-dd"),
                                AddPeople      = "",
                                FoodName       = ingredients[i].FoodName,
                                TypeUuid       = ingredients[i].TypeUuid,
                                IsDelete       = 0,
                                HeatEnergy     = ingredients[i].HeatEnergy,
                                Protein        = ingredients[i].Protein,
                                Fat            = ingredients[i].Fat,
                                Va             = ingredients[i].Va,
                                Saccharides    = ingredients[i].Saccharides,
                                Accessory      = ingredients[i].Accessory,
                            };


                            _dbContext.Ingredient.Add(ing);
                        }
                    }
                    //_dbContext.Ingredient.AddRange(ingredients);
                    _dbContext.SaveChanges();
                }
                var cuisines = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoolEnt.SchoolUuid && x.IsDelete == 0).ToList();
                for (int n = 0; n < schoollist.Count; n++)
                {
                    for (int i = 0; i < cuisines.Count; i++)
                    {
                        if (!_dbContext.Cuisine.Any(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && x.CuisineName == cuisines[i].CuisineName))
                        {
                            var cui = new Entities.Cuisine()
                            {
                                CuisineUuid = Guid.NewGuid(),
                                SchoolUuid  = schoollist[n].SchoolUuid,
                                AddTime     = DateTime.Now.ToString("yyyy-MM-dd"),
                                AddPeople   = "",
                                LikeNum     = 0,
                                IsDelete    = 0,
                                CuisineName = cuisines[i].CuisineName,
                                Price       = cuisines[i].Price,
                                Burdening   = cuisines[i].Burdening,
                                Ingredient  = cuisines[i].Ingredient,
                                Abstract    = cuisines[i].Abstract,
                                CuisineType = cuisines[i].CuisineType,
                                Accessory   = cuisines[i].Accessory,
                            };



                            _dbContext.Cuisine.Add(cui);
                        }
                    }
                    //_dbContext.Cuisine.AddRange(cuisines);
                    _dbContext.SaveChanges();
                }
                var nweekmenus = _dbContext.NweekMenu.Where(x => x.SchoolUuid == schoolEnt.SchoolUuid && x.IsDelete == 0).OrderByDescending(x => x.Datetimes).Take(3).ToList();
                for (int n = 0; n < schoollist.Count; n++)
                {
                    for (int i = 0; i < nweekmenus.Count; i++)
                    {
                        if (!_dbContext.NweekMenu.Any(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.Datetimes == nweekmenus[0].Datetimes && x.IsDelete == 0))
                        {
                            var ids1     = nweekmenus[i].MonMon.ToLower().Split(',');
                            var names1   = _dbContext.Cuisine.Where(x => ids1.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var MonMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names1
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var MonMon = string.Join(",", MonMonLs);

                            var ids2      = nweekmenus[i].MonNoon.ToLower().Split(',');
                            var names2    = _dbContext.Cuisine.Where(x => ids2.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var MonNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names2
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var MonNoon = string.Join(",", MonNoonLs);

                            var ids3       = nweekmenus[i].MonNight.ToLower().Split(',');
                            var names3     = _dbContext.Cuisine.Where(x => ids3.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var MonNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names3
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var MonNight = string.Join(",", MonNightLs);

                            var ids4      = nweekmenus[i].TuesMon.ToLower().Split(',');
                            var names4    = _dbContext.Cuisine.Where(x => ids4.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var TuesMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names4
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var TuesMon = string.Join(",", TuesMonLs);

                            var ids5       = nweekmenus[i].TuesNoon.ToLower().Split(',');
                            var names5     = _dbContext.Cuisine.Where(x => ids5.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var TuesNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names5
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var TuesNoon = string.Join(",", TuesNoonLs);

                            var ids6        = nweekmenus[i].TuesNight.ToLower().Split(',');
                            var names6      = _dbContext.Cuisine.Where(x => ids6.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var TuesNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names6
                                                                       .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var TuesNight = string.Join(",", TuesNightLs);

                            var ids7     = nweekmenus[i].WedMon.ToLower().Split(',');
                            var names7   = _dbContext.Cuisine.Where(x => ids7.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var WedMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names7
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var WedMon = string.Join(",", WedMonLs);

                            var ids8      = nweekmenus[i].WedNoon.ToLower().Split(',');
                            var names8    = _dbContext.Cuisine.Where(x => ids8.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var WedNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names8
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var WedNoon = string.Join(",", WedNoonLs);

                            var ids9       = nweekmenus[i].WedNight.ToLower().Split(',');
                            var names9     = _dbContext.Cuisine.Where(x => ids9.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var WedNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names9
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var WedNight = string.Join(",", WedNightLs);

                            var ids10      = nweekmenus[i].ThursMon.ToLower().Split(',');
                            var names10    = _dbContext.Cuisine.Where(x => ids10.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var ThursMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names10
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var ThursMon = string.Join(",", ThursMonLs);

                            var ids11       = nweekmenus[i].ThursNoon.ToLower().Split(',');
                            var names11     = _dbContext.Cuisine.Where(x => ids11.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var ThursNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names11
                                                                       .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var ThursNoon = string.Join(",", ThursNoonLs);

                            var ids12        = nweekmenus[i].ThursNight.ToLower().Split(',');
                            var names12      = _dbContext.Cuisine.Where(x => ids12.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var ThursNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names12
                                                                        .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var ThursNight = string.Join(",", ThursNightLs);

                            var ids13    = nweekmenus[i].FriMon.ToLower().Split(',');
                            var names13  = _dbContext.Cuisine.Where(x => ids13.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var FriMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names13
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var FriMon = string.Join(",", FriMonLs);

                            var ids14     = nweekmenus[i].FriNoon.ToLower().Split(',');
                            var names14   = _dbContext.Cuisine.Where(x => ids14.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var FriNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names14
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var FriNoon = string.Join(",", FriNoonLs);

                            var ids15      = nweekmenus[i].FriNight.ToLower().Split(',');
                            var names15    = _dbContext.Cuisine.Where(x => ids15.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var FriNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names15
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var FriNight = string.Join(",", FriNightLs);

                            var ids16    = nweekmenus[i].SatMon.ToLower().Split(',');
                            var names16  = _dbContext.Cuisine.Where(x => ids16.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SatMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names16
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SatMon = string.Join(",", SatMonLs);

                            var ids17     = nweekmenus[i].SatNoon.ToLower().Split(',');
                            var names17   = _dbContext.Cuisine.Where(x => ids17.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SatNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names17
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SatNoon = string.Join(",", SatNoonLs);

                            var ids18      = nweekmenus[i].SatNight.ToLower().Split(',');
                            var names18    = _dbContext.Cuisine.Where(x => ids18.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SatNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names18
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SatNight = string.Join(",", SatNightLs);

                            var ids19    = nweekmenus[i].SunMon.ToLower().Split(',');
                            var names19  = _dbContext.Cuisine.Where(x => ids19.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SunMonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names19
                                                                    .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SunMon = string.Join(",", SunMonLs);

                            var ids20     = nweekmenus[i].SunNoon.ToLower().Split(',');
                            var names20   = _dbContext.Cuisine.Where(x => ids20.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SunNoonLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names20
                                                                     .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SunNoon = string.Join(",", SunNoonLs);

                            var ids21      = nweekmenus[i].SunNight.ToLower().Split(',');
                            var names21    = _dbContext.Cuisine.Where(x => ids21.Contains(x.CuisineUuid.ToString().ToLower())).Select(x => x.CuisineName).ToList();
                            var SunNightLs = _dbContext.Cuisine.Where(x => x.SchoolUuid == schoollist[n].SchoolUuid && x.IsDelete == 0 && names21
                                                                      .Contains(x.CuisineName)).Select(x => x.CuisineUuid).ToArray();
                            var SunNight = string.Join(",", SunNightLs);

                            var menu = new NweekMenu()
                            {
                                NweekMenuUuid = Guid.NewGuid(),
                                SchoolUuid    = schoollist[n].SchoolUuid,
                                MonMon        = MonMon,
                                MonNight      = MonNight,
                                MonNoon       = MonNoon,
                                TuesMon       = TuesMon,
                                TuesNight     = TuesNight,
                                TuesNoon      = TuesNoon,
                                WedMon        = WedMon,
                                WedNight      = WedNight,
                                WedNoon       = WedNoon,
                                ThursMon      = ThursMon,
                                ThursNight    = ThursNight,
                                ThursNoon     = ThursNoon,
                                FriMon        = FriMon,
                                FriNight      = FriNight,
                                FriNoon       = FriNoon,
                                SatMon        = SatMon,
                                SatNight      = SatNight,
                                SatNoon       = SatNoon,
                                SunMon        = SunMon,
                                SunNight      = SunNight,
                                SunNoon       = SunNoon,
                                AddTime       = DateTime.Now.ToString("yyyy-MM-dd"),
                                AddPeople     = "",
                                IsDelete      = 0,
                                Datetimes     = nweekmenus[0].Datetimes,
                            };

                            _dbContext.NweekMenu.Add(menu);
                        }
                    }
                    _dbContext.SaveChanges();
                }
            }
            return(Ok(response));
        }
        public WhatYouGotLibrary.Models.Ingredient GetIngredientById(int id)
        {
            Entities.Ingredient ingredient = _context.Ingredient.Find(id);

            return(Mapper.Map(ingredient));
        }
 public void DeleteIngredientById(int id)
 {
     Entities.Ingredient ingredient = _context.Ingredient.Find(id);
     _context.Remove(ingredient);
 }
 public void AddIngredient(WhatYouGotLibrary.Models.Ingredient ingredient)
 {
     Entities.Ingredient newIngredient = Mapper.Map(ingredient);
     _context.Add(newIngredient);
 }
示例#11
0
 /// <summary>
 /// Initializes this object using an Ingredient entity object
 /// </summary>
 public Ingredient(Entities.Ingredient ingredient)
 {
     this.Id = ingredient.Id;
 }