Example #1
0
        public static DishTag MapToDishTag(this SqliteDataReader reader)
        {
            var dishTag = new DishTag();

            dishTag.DishId = reader.GetInt32(0);
            dishTag.TagId  = reader.GetInt32(1);
            return(dishTag);
        }
Example #2
0
        /// <summary>
        /// 打印标签
        /// </summary>
        /// <param name="act"></param>
        /// <param name="id"></param>
        /// <param name="aId"></param>
        /// <param name="storeId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortData"></param>
        /// <param name="fid"></param>
        /// <returns></returns>
        public ActionResult Label(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20, string sortData = "", int fid = 0)
        {
            //显示
            if (string.IsNullOrEmpty(act))
            {
                string filterSql       = $"type=1 and state=1 and aid={aId} and storeid={storeId}";
                ViewModel <DishTag> vm = new ViewModel <DishTag>();
                vm.DataList   = DishTagBLL.SingleModel.GetList(filterSql, pageSize, pageIndex, "*", "sort desc");
                vm.TotalCount = DishTagBLL.SingleModel.GetCount(filterSql);
                vm.PageIndex  = pageIndex;
                vm.PageSize   = pageSize;
                vm.aId        = aId;
                vm.storeId    = storeId;
                //类型ID
                ViewBag.fid = fid;
                return(View(vm));
            }
            else
            {
                //删除
                if (act == "del")
                {
                    if (id <= 0)
                    {
                        _result.msg = "参数错误";
                    }
                    else
                    {
                        DishTag updateModel = DishTagBLL.SingleModel.GetModel(id);
                        if (updateModel != null)
                        {
                            updateModel.state = -1;
                            bool updateResult = DishTagBLL.SingleModel.Update(updateModel);
                            if (updateResult)
                            {
                                //同步设定了该标签的数据
                                DishGoodBLL.SingleModel.SyncGoodByPrintTag(updateModel.id);
                                DishPrintBLL.SingleModel.SyncPrintByPrintTag(updateModel.aId, updateModel.storeId, updateModel.id);

                                _result.code = 1;
                                _result.msg  = "删除成功";
                            }
                            else
                            {
                                _result.msg = "删除失败";
                            }
                        }
                        else
                        {
                            _result.msg = "删除失败,标签不存在或已删除";
                        }
                    }
                }
            }
            return(Json(_result));
        }
Example #3
0
 /// <summary>
 /// 编辑标签
 /// </summary>
 /// <returns></returns>
 public ActionResult LabelEdit(string act = "", int id = 0, int aId = 0, int storeId = 0, DishTag model = null, int fid = 0)
 {
     //参数验证
     if (id < 0 || aId <= 0 || storeId <= 0)
     {
         _result.msg = "参数错误";
         return(Json(_result));
     }
     //显示
     if (string.IsNullOrEmpty(act))
     {
         if (id == 0)
         {
             model = new DishTag();
         }
         else
         {
             model = DishTagBLL.SingleModel.GetModel(id);
             if (model == null)
             {
                 return(Content("分类不存在"));
             }
         }
         EditModel <DishTag> em = new EditModel <DishTag>();
         em.DataModel             = model;
         em.aId                   = aId;
         em.storeId               = storeId;
         ViewBag.dishAttrTypeList = DishTagBLL.SingleModel.GetList($"state=1 and aid={aId} and storeId={storeId}");
         ViewBag.fid              = fid;
         return(View(em));
     }
     else
     {
         if (act == "edit")
         {
             if (id == 0)
             {
                 model.type = 1;
                 int newid = Convert.ToInt32(DishTagBLL.SingleModel.Add(model));
                 _result.msg  = newid > 0 ? "添加成功" : "添加失败";
                 _result.code = newid > 0 ? 1 : 0;
             }
             else
             {
                 bool updateResult = DishTagBLL.SingleModel.Update(model, "name,sort");
                 _result.msg  = updateResult ? "修改成功" : "修改失败";
                 _result.code = updateResult ? 1 : 0;
             }
         }
     }
     return(Json(_result));
 }
Example #4
0
        public void CreateDishTags(int[] tagIdList, int dishId)
        {
            var dish = dishRepository.Get(dishId);

            foreach (var tagId in tagIdList)
            {
                if (dish.DishTag.All(x => x.TagId != tagId))
                {
                    var dishTag = new DishTag
                    {
                        DishId          = dishId,
                        TagId           = tagId,
                        CreatedByUserId = UserHelper.GetCurrentUserId(),
                        CreatedDateTime = DateTime.Now
                    };

                    dishTagRepository.Insert(dishTag);
                }
            }
        }
        private static async Task ImportDishesAsync(IUnitOfWork _uow, IServiceProvider serviceProvider)
        {
            var fileService = serviceProvider.GetRequiredService <IAmazonS3Service>();

            var handsCodes = new Dictionary <int, string>();

            handsCodes.Add(0, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/0.png");
            handsCodes.Add(1, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/1.png");
            handsCodes.Add(2, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/2.png");
            handsCodes.Add(3, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/3.png");
            handsCodes.Add(4, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/4.png");
            handsCodes.Add(5, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/5.png");
            handsCodes.Add(6, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/6.png");
            handsCodes.Add(7, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/7.png");
            handsCodes.Add(8, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/8.png");
            handsCodes.Add(9, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/9.png");
            handsCodes.Add(10, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/10.png");
            handsCodes.Add(11, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/11.png");
            handsCodes.Add(12, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/12.png");
            handsCodes.Add(13, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/13.png");
            handsCodes.Add(14, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/14.jpg");
            handsCodes.Add(15, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/15.png");
            handsCodes.Add(16, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/16.png");
            handsCodes.Add(17, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/17.png");
            handsCodes.Add(18, "D:/Projects/Mismes/BD Alimentos Saira/Alimentos 100x100/18.jpg");

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            using (var package = new ExcelPackage(new FileInfo("D:/Projects/Mismes/BD Alimentos Saira/ENVIADA YOANDY 10042021.xlsx")))
            {
                var sheetCount = package.Workbook.Worksheets.Count;
                var firstSheet = package.Workbook.Worksheets["hoja1"];
                for (int i = 2; i <= 50; i++)
                {
                    var code      = firstSheet.Cells[i, 2].Text.Trim();
                    var dishName  = firstSheet.Cells[i, 3].Text.Trim();
                    var handsCode = int.Parse(firstSheet.Cells[i, 4].Text.Trim());

                    var netWeight   = double.Parse(firstSheet.Cells[i, 5].Text.Trim());
                    var volume      = double.Parse(firstSheet.Cells[i, 6].Text.Trim());
                    var dishClasifi = firstSheet.Cells[i, 7].Text.Trim();
                    var category    = firstSheet.Cells[i, 8].Text.Trim();
                    var calories    = double.Parse(firstSheet.Cells[i, 9].Text.Trim());

                    var carbohidrates = double.Parse(firstSheet.Cells[i, 10].Text.Trim());
                    var proteins      = double.Parse(firstSheet.Cells[i, 11].Text.Trim());

                    var fiber               = double.Parse(firstSheet.Cells[i, 12].Text.Trim());
                    var fat                 = double.Parse(firstSheet.Cells[i, 13].Text.Trim());
                    var staurated           = double.Parse(firstSheet.Cells[i, 14].Text.Trim());
                    var monoUnsaturated     = double.Parse(firstSheet.Cells[i, 15].Text.Trim());
                    var polyUnsaturated     = double.Parse(firstSheet.Cells[i, 16].Text.Trim());
                    var cholesterol         = double.Parse(firstSheet.Cells[i, 17].Text.Trim());
                    var vitaminA            = double.Parse(firstSheet.Cells[i, 18].Text.Trim());
                    var vitaminB1Thiamin    = double.Parse(firstSheet.Cells[i, 19].Text.Trim());
                    var vitaminB2Riboflavin = double.Parse(firstSheet.Cells[i, 20].Text.Trim());
                    var vitaminB3Niacin     = double.Parse(firstSheet.Cells[i, 21].Text.Trim());
                    var vitaminB6           = double.Parse(firstSheet.Cells[i, 22].Text.Trim());
                    var vitaminB9Folate     = double.Parse(firstSheet.Cells[i, 23].Text.Trim());
                    var vitaminB12          = double.Parse(firstSheet.Cells[i, 24].Text.Trim());
                    var vitaminC            = double.Parse(firstSheet.Cells[i, 25].Text.Trim());
                    var vitaminD            = double.Parse(firstSheet.Cells[i, 26].Text.Trim());
                    var vitaminE            = double.Parse(firstSheet.Cells[i, 27].Text.Trim());
                    var vitaminK            = double.Parse(firstSheet.Cells[i, 28].Text.Trim());
                    var calcium             = double.Parse(firstSheet.Cells[i, 29].Text.Trim());
                    var phosporus           = double.Parse(firstSheet.Cells[i, 30].Text.Trim());
                    var iron                = double.Parse(firstSheet.Cells[i, 31].Text.Trim());
                    var zinc                = double.Parse(firstSheet.Cells[i, 32].Text.Trim());
                    var potsassium          = double.Parse(firstSheet.Cells[i, 33].Text.Trim());
                    var sodium              = double.Parse(firstSheet.Cells[i, 34].Text.Trim());

                    var tagsDict = new Dictionary <string, int>();
                    tagsDict.Add("Bebidas", 12);
                    tagsDict.Add("Frutas", 13);
                    tagsDict.Add("Grasas/aderezos/salsas", 14);
                    tagsDict.Add("Lácteos y derivados", 15);
                    tagsDict.Add("Platos combinados", 16);
                    tagsDict.Add("Postre/dulces/complementos", 17);
                    tagsDict.Add("Proteína animal", 18);
                    tagsDict.Add("Proteína vegetal", 19);
                    tagsDict.Add("Sopas/cereales/tubérculos", 20);
                    tagsDict.Add("Vegetales y verduras", 21);

                    var tags    = new List <DishTag>();
                    var dishTag = new DishTag();
                    dishTag.TagId    = tagsDict[category];
                    dishTag.TaggedAt = DateTime.UtcNow; tags.Add(dishTag);

                    //upload images
                    string guid = Guid.NewGuid().ToString();

                    using (FileStream f = new FileStream(handsCodes[handsCode], FileMode.Open, FileAccess.Read))
                    {
                        MemoryStream ms = new MemoryStream();
                        f.CopyTo(ms);
                        await fileService.PutObjectAsync(guid, ms);
                    }
                    var dish = new Dish();
                    dish.Image    = guid;
                    dish.Code     = code;
                    dish.Name     = dishName;
                    dish.HandCode = handsCode;
                    if (netWeight >= 0)
                    {
                        dish.NetWeight = netWeight;
                    }
                    if (volume >= 0)
                    {
                        dish.Volume = volume;
                    }
                    if (calories >= 0)
                    {
                        dish.Calories = calories;
                    }
                    if (proteins >= 0)
                    {
                        dish.Proteins = proteins;
                    }
                    if (carbohidrates >= 0)
                    {
                        dish.Carbohydrates = carbohidrates;
                    }
                    if (fiber >= 0)
                    {
                        dish.Fiber = fiber;
                    }
                    if (fat >= 0)
                    {
                        dish.Fat = fat;
                    }
                    if (staurated >= 0)
                    {
                        dish.SaturatedFat = staurated;
                    }
                    if (monoUnsaturated >= 0)
                    {
                        dish.MonoUnsaturatedFat = monoUnsaturated;
                    }
                    if (polyUnsaturated >= 0)
                    {
                        dish.PolyUnsaturatedFat = polyUnsaturated;
                    }
                    if (cholesterol >= 0)
                    {
                        dish.Cholesterol = cholesterol;
                    }
                    if (vitaminA >= 0)
                    {
                        dish.VitaminA = vitaminA;
                    }
                    if (vitaminB1Thiamin >= 0)
                    {
                        dish.VitaminB1Thiamin = vitaminB1Thiamin;
                    }
                    if (vitaminB2Riboflavin >= 0)
                    {
                        dish.VitaminB2Riboflavin = vitaminB2Riboflavin;
                    }
                    if (vitaminB3Niacin >= 0)
                    {
                        dish.VitaminB3Niacin = vitaminB3Niacin;
                    }

                    if (vitaminB6 >= 0)
                    {
                        dish.VitaminB6 = vitaminB6;
                    }
                    if (vitaminB9Folate >= 0)
                    {
                        dish.VitaminB9Folate = vitaminB9Folate;
                    }
                    if (vitaminB12 >= 0)
                    {
                        dish.VitaminB12 = vitaminB12;
                    }
                    if (vitaminC >= 0)
                    {
                        dish.VitaminC = vitaminC;
                    }
                    if (vitaminD >= 0)
                    {
                        dish.VitaminD = vitaminD;
                    }
                    if (vitaminE >= 0)
                    {
                        dish.VitaminE = vitaminE;
                    }
                    if (vitaminK >= 0)
                    {
                        dish.VitaminK = vitaminK;
                    }

                    if (calcium >= 0)
                    {
                        dish.Calcium = calcium;
                    }
                    if (phosporus >= 0)
                    {
                        dish.Phosphorus = phosporus;
                    }
                    if (iron >= 0)
                    {
                        dish.Iron = iron;
                    }
                    if (zinc >= 0)
                    {
                        dish.Zinc = zinc;
                    }
                    if (potsassium >= 0)
                    {
                        dish.Potassium = potsassium;
                    }
                    if (sodium >= 0)
                    {
                        dish.Sodium = sodium;
                    }

                    switch (dishClasifi)
                    {
                    case "Calórico":
                        dish.IsCaloric = true;
                        break;

                    case "Protéico":
                        dish.IsProteic = true;
                        break;

                    default:
                        dish.IsFruitAndVegetables = true;
                        break;
                    }

                    dish.DishTags   = tags;
                    dish.CreatedAt  = DateTime.UtcNow;
                    dish.ModifiedAt = DateTime.UtcNow;
                    await _uow.DishRepository.AddAsync(dish);
                }

                await _uow.CommitAsync();
            }
        }
        public async Task ConvertUserDishAsync(int loggedUser, UpdateDishRequest dish)
        {
            // validate admin user
            var user = await _uow.UserRepository.FindByAsync(u => u.Id == loggedUser && u.Role == RoleEnum.ADMIN);

            if (user.Count == 0)
            {
                throw new NotAllowedException(ExceptionConstants.NOT_ALLOWED);
            }

            var d = await _uow.CompoundDishRepository.GetAsync(dish.Id);

            if (d == null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "Dish");
            }

            // validate dish name, this no requires pass the id becaus we are converting a user dish
            // on a general dish
            var existDishName = await _uow.DishRepository.FindByAsync(p => p.Name.ToLower() == dish.Name.ToLower());

            if (existDishName.Count > 0)
            {
                throw new InvalidDataException(ExceptionConstants.INVALID_DATA, "Dish name");
            }

            var dishh = new Dish();

            dishh.Calories      = dish.Calories;
            dishh.Carbohydrates = dish.Carbohydrates;
            dishh.Fat           = dish.Fat;
            dishh.Fiber         = dish.Fiber;
            dishh.Name          = dish.Name;
            dishh.Proteins      = dish.Proteins;

            dishh.Cholesterol = dish.Cholesterol;
            dishh.Calcium     = dish.Calcium;
            dishh.Phosphorus  = dish.Phosphorus;
            dishh.Iron        = dish.Iron;
            dishh.Potassium   = dish.Potassium;
            dishh.Sodium      = dish.Sodium;
            dishh.Zinc        = dish.Zinc;
            dishh.VitaminA    = dish.VitaminA;
            dishh.VitaminC    = dish.VitaminC;
            dishh.VitaminB6   = dish.VitaminB6;
            dishh.VitaminB12  = dish.VitaminB12;
            dishh.VitaminD    = dish.VitaminD;
            dishh.VitaminE    = dish.VitaminE;
            dishh.VitaminK    = dish.VitaminK;

            dishh.VitaminB1Thiamin    = dish.VitaminB1Thiamin;
            dishh.VitaminB2Riboflavin = dish.VitaminB2Riboflavin;
            dishh.VitaminB3Niacin     = dish.VitaminB3Niacin;
            dishh.VitaminB9Folate     = dish.VitaminB9Folate;
            dishh.NetWeight           = dish.NetWeight;
            dishh.Volume             = dish.Volume;
            dishh.SaturatedFat       = dish.SaturatedFat;
            dishh.PolyUnsaturatedFat = dish.PolyUnsaturatedFat;
            dishh.MonoUnsaturatedFat = dish.MonoUnsaturatedFat;
            dishh.Alcohol            = dish.Alcohol;

            if (dish.Classification == 0)
            {
                dishh.IsProteic = true;
            }
            else if (dish.Classification == 1)
            {
                dishh.IsCaloric = true;
            }
            else
            {
                dishh.IsFruitAndVegetables = true;
            }

            // avatar

            // take the same user image
            if (dish.RemovedImage == "null" && dish.Image == null)
            {
                if (!string.IsNullOrWhiteSpace(d.Image))
                {
                    string destinationKey = Guid.NewGuid().ToString();
                    string sourceKey      = d.Image;

                    await _fileService.CopyFileAsync(sourceKey, destinationKey);

                    dishh.Image         = destinationKey;
                    dishh.ImageMimeType = d.ImageMimeType;
                }
            }
            else if (dish.Image != null)
            {
                string guid = Guid.NewGuid().ToString();
                await _fileService.UploadFileAsync(dish.Image, guid);

                dishh.Image         = guid;
                dishh.ImageMimeType = dish.Image.ContentType;
            }

            //existing tags
            foreach (var id in dish.TagsIds)
            {
                var t = await _uow.TagRepository.GetAsync(id);

                if (t != null)
                {
                    var exist = await _uow.DishTagRepository.GetAll().Where(t => t.TagId == id && t.DishId == dish.Id).FirstOrDefaultAsync();

                    if (exist == null)
                    {
                        var dt = new DishTag
                        {
                            Dish     = dishh,
                            TagId    = t.Id,
                            TaggedAt = DateTime.UtcNow
                        };

                        await _uow.DishTagRepository.AddAsync(dt);
                    }
                }
            }
            //new tags
            foreach (var name in dish.NewTags)
            {
                var ta = new Tag
                {
                    Name = name
                };
                await _uow.TagRepository.AddAsync(ta);

                var dt = new DishTag
                {
                    Dish     = dishh,
                    Tag      = ta,
                    TaggedAt = DateTime.UtcNow
                };

                await _uow.DishTagRepository.AddAsync(dt);
            }

            d.IsAdminConverted = true;
            d.IsAdminReviewed  = true;
            _uow.CompoundDishRepository.Update(d);

            await _uow.DishRepository.AddAsync(dishh);

            await _uow.CommitAsync();
        }
Example #7
0
        public async Task <Dish> CreateDishAsync(int loggedUser, CreateDishRequest dish)
        {
            // validate admin user
            var user = await _uow.UserRepository.FindByAsync(u => u.Id == loggedUser && u.Role == RoleEnum.ADMIN);

            if (user.Count == 0)
            {
                throw new NotAllowedException(ExceptionConstants.NOT_ALLOWED);
            }
            // validate dish name
            var existDishName = await _uow.DishRepository.FindByAsync(p => p.Name.ToLower() == dish.Name.ToLower());

            if (existDishName.Count > 0)
            {
                throw new InvalidDataException(ExceptionConstants.INVALID_DATA, "Dish name");
            }

            var dbDish = new Dish();

            dbDish.Calories      = dish.Calories;
            dbDish.Carbohydrates = dish.Carbohydrates;
            dbDish.Fat           = dish.Fat;
            dbDish.Fiber         = dish.Fiber;
            dbDish.Name          = dish.Name;
            dbDish.Proteins      = dish.Proteins;

            dbDish.Cholesterol = dish.Cholesterol;
            dbDish.Calcium     = dish.Calcium;
            dbDish.Phosphorus  = dish.Phosphorus;
            dbDish.Iron        = dish.Iron;
            dbDish.Potassium   = dish.Potassium;
            dbDish.Sodium      = dish.Sodium;
            dbDish.Zinc        = dish.Zinc;
            dbDish.VitaminA    = dish.VitaminA;
            dbDish.VitaminC    = dish.VitaminC;
            dbDish.VitaminB6   = dish.VitaminB6;
            dbDish.VitaminB12  = dish.VitaminB12;
            dbDish.VitaminD    = dish.VitaminD;
            dbDish.VitaminE    = dish.VitaminE;
            dbDish.VitaminK    = dish.VitaminK;

            dbDish.VitaminB1Thiamin    = dish.VitaminB1Thiamin;
            dbDish.VitaminB2Riboflavin = dish.VitaminB2Riboflavin;
            dbDish.VitaminB3Niacin     = dish.VitaminB3Niacin;
            dbDish.VitaminB9Folate     = dish.VitaminB9Folate;
            dbDish.NetWeight           = dish.NetWeight;
            dbDish.Volume             = dish.Volume;
            dbDish.SaturatedFat       = dish.SaturatedFat;
            dbDish.PolyUnsaturatedFat = dish.PolyUnsaturatedFat;
            dbDish.MonoUnsaturatedFat = dish.MonoUnsaturatedFat;
            dbDish.Alcohol            = dish.Alcohol;

            if (dish.Classification == 0)
            {
                dbDish.IsProteic = true;
            }
            else if (dish.Classification == 1)
            {
                dbDish.IsCaloric = true;
            }
            else
            {
                dbDish.IsFruitAndVegetables = true;
            }

            // avatar

            if (dish.Image != null)
            {
                string guid = Guid.NewGuid().ToString();
                await _fileService.UploadFileAsync(dish.Image, guid);

                dbDish.Image         = guid;
                dbDish.ImageMimeType = dish.Image.ContentType;
            }

            //existing tags
            foreach (var id in dish.TagsIds)
            {
                var t = await _uow.TagRepository.GetAsync(id);

                if (t != null)
                {
                    var dt = new DishTag
                    {
                        Dish     = dbDish,
                        TagId    = t.Id,
                        TaggedAt = DateTime.UtcNow
                    };

                    await _uow.DishTagRepository.AddAsync(dt);
                }
            }
            //new tags
            foreach (var name in dish.NewTags)
            {
                var ta = new Tag
                {
                    Name = name
                };
                await _uow.TagRepository.AddAsync(ta);

                var dt = new DishTag
                {
                    Dish     = dbDish,
                    Tag      = ta,
                    TaggedAt = DateTime.UtcNow
                };

                await _uow.DishTagRepository.AddAsync(dt);
            }

            await _uow.DishRepository.AddAsync(dbDish);

            await _uow.CommitAsync();

            //expire cache
            QueryCacheManager.ExpireTag(_config.GetSection("AWS")["CachePrefix"] + CacheEntries.ALL_DISHES);

            return(dbDish);
        }
Example #8
0
        public async Task <Dish> UpdateDishAsync(int loggedUser, UpdateDishRequest dish)
        {
            // validate admin user
            var user = await _uow.UserRepository.FindByAsync(u => u.Id == loggedUser && u.Role == RoleEnum.ADMIN);

            if (user.Count == 0)
            {
                throw new NotAllowedException(ExceptionConstants.NOT_ALLOWED);
            }

            var dishh = await _uow.DishRepository.GetAll().Where(d => d.Id == dish.Id)
                        .Include(d => d.FavoriteDishes)
                        .Include(d => d.LackSelfControlDishes)
                        .Include(d => d.DishTags)
                        .ThenInclude(t => t.Tag)
                        .FirstOrDefaultAsync();

            if (dishh == null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "Dish");
            }

            // validate dish name
            var existDishName = await _uow.DishRepository.FindByAsync(p => p.Name.ToLower() == dish.Name.ToLower() && p.Id != dish.Id);

            if (existDishName.Count > 0)
            {
                throw new InvalidDataException(ExceptionConstants.INVALID_DATA, "Dish name");
            }

            dishh.Calories      = dish.Calories;
            dishh.Carbohydrates = dish.Carbohydrates;
            dishh.Fat           = dish.Fat;
            dishh.Fiber         = dish.Fiber;
            dishh.Name          = dish.Name;
            dishh.Proteins      = dish.Proteins;

            dishh.Cholesterol = dish.Cholesterol;
            dishh.Calcium     = dish.Calcium;
            dishh.Phosphorus  = dish.Phosphorus;
            dishh.Iron        = dish.Iron;
            dishh.Potassium   = dish.Potassium;
            dishh.Sodium      = dish.Sodium;
            dishh.Zinc        = dish.Zinc;
            dishh.VitaminA    = dish.VitaminA;
            dishh.VitaminC    = dish.VitaminC;
            dishh.VitaminB6   = dish.VitaminB6;
            dishh.VitaminB12  = dish.VitaminB12;
            dishh.VitaminD    = dish.VitaminD;
            dishh.VitaminE    = dish.VitaminE;
            dishh.VitaminK    = dish.VitaminK;

            dishh.VitaminB1Thiamin    = dish.VitaminB1Thiamin;
            dishh.VitaminB2Riboflavin = dish.VitaminB2Riboflavin;
            dishh.VitaminB3Niacin     = dish.VitaminB3Niacin;
            dishh.VitaminB9Folate     = dish.VitaminB9Folate;
            dishh.NetWeight           = dish.NetWeight;
            dishh.Volume             = dish.Volume;
            dishh.SaturatedFat       = dish.SaturatedFat;
            dishh.PolyUnsaturatedFat = dish.PolyUnsaturatedFat;
            dishh.MonoUnsaturatedFat = dish.MonoUnsaturatedFat;
            dishh.Alcohol            = dish.Alcohol;

            if (dish.Classification == 0)
            {
                dishh.IsProteic            = true;
                dishh.IsCaloric            = false;
                dishh.IsFruitAndVegetables = false;
            }
            else if (dish.Classification == 1)
            {
                dishh.IsCaloric            = true;
                dishh.IsProteic            = false;
                dishh.IsFruitAndVegetables = false;
            }
            else
            {
                dishh.IsFruitAndVegetables = true;
                dishh.IsProteic            = false;
                dishh.IsCaloric            = false;
            }

            // avatar

            if (!string.IsNullOrWhiteSpace(dish.RemovedImage) && dish.RemovedImage != "null")
            {
                await _fileService.DeleteFileAsync(dishh.Image);

                dishh.Image         = "";
                dishh.ImageMimeType = "";
            }
            if (dish.Image != null)
            {
                string guid = Guid.NewGuid().ToString();
                await _fileService.UploadFileAsync(dish.Image, guid);

                dishh.Image         = guid;
                dishh.ImageMimeType = dish.Image.ContentType;
            }

            //delete current and removed tags
            var results = _uow.DishTagRepository.GetAll().Where(dt => dish.Id == dt.DishId && !dish.TagsIds.Contains(dt.TagId));

            foreach (var dt in results)
            {
                _uow.DishTagRepository.Delete(dt);
            }

            //existing tags
            foreach (var id in dish.TagsIds)
            {
                var t = await _uow.TagRepository.GetAsync(id);

                if (t != null)
                {
                    var exist = await _uow.DishTagRepository.GetAll().Where(t => t.TagId == id && t.DishId == dish.Id).FirstOrDefaultAsync();

                    if (exist == null)
                    {
                        var dt = new DishTag
                        {
                            Dish     = dishh,
                            TagId    = t.Id,
                            TaggedAt = DateTime.UtcNow
                        };

                        await _uow.DishTagRepository.AddAsync(dt);
                    }
                }
            }
            //new tags
            foreach (var name in dish.NewTags)
            {
                var ta = new Tag
                {
                    Name = name
                };
                await _uow.TagRepository.AddAsync(ta);

                var dt = new DishTag
                {
                    Dish     = dishh,
                    Tag      = ta,
                    TaggedAt = DateTime.UtcNow
                };

                await _uow.DishTagRepository.AddAsync(dt);
            }

            await _uow.DishRepository.UpdateAsync(dishh, dishh.Id);

            await _uow.CommitAsync();

            //expire cache
            QueryCacheManager.ExpireTag(_config.GetSection("AWS")["CachePrefix"] + CacheEntries.ALL_DISHES);
            return(dishh);
        }