예제 #1
0
        private int LackSelfControlIntensity(CompoundDish dish)
        {
            var loggedUser = _httpContextAccessor.CurrentUser();

            var item = dish.LackSelfControlDishes.FirstOrDefault(fd => fd.UserId == loggedUser);

            return(item != null ? item.Intensity : 0);
        }
        private async Task AuxUpdateCompountDishAsync(CompoundDish compoundDish, UpdateCompoundDishRequest dish)
        {
            compoundDish.Name       = dish.Name;
            compoundDish.ModifiedAt = DateTime.UtcNow;
            if (dish.Image != null)
            {
                if (!string.IsNullOrEmpty(compoundDish.Image))
                {
                    await _fileService.DeleteFileAsync(compoundDish.Image);
                }

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

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

            // delete previous dishes
            foreach (var item in compoundDish.DishCompoundDishes)
            {
                _uow.DishCompoundDishRepository.Delete(item);
            }

            if (dish.Dishes != null)
            {
                foreach (var item in dish.Dishes)
                {
                    var dComDish = new DishCompoundDish
                    {
                        CompoundDishId = compoundDish.Id,
                        DishId         = item.DishId,
                        DishQty        = item.Qty
                    };
                    await _uow.DishCompoundDishRepository.AddAsync(dComDish);
                }
            }

            _uow.CompoundDishRepository.Update(compoundDish);
        }
        private async Task <CompoundDish> AuxCreateCompoundDishAsync(int ownerId, CreateCompoundDishRequest dish, CompoundDish existingDish = null)
        {
            var cDish = new CompoundDish();

            if (existingDish != null)
            {
                cDish.Name             = existingDish.Name;
                cDish.UserId           = existingDish.UserId;
                cDish.CreatedBy        = existingDish.CreatedBy;
                cDish.IsAdminConverted = false;
                cDish.IsAdminReviewed  = false;

                cDish.IsDeleted  = false;
                cDish.ModifiedAt = DateTime.UtcNow;
                cDish.CreatedAt  = DateTime.UtcNow;

                foreach (var item in existingDish.DishCompoundDishes)
                {
                    cDish.DishCompoundDishes.Add(new DishCompoundDish
                    {
                        DishId  = item.DishId,
                        DishQty = item.DishQty
                    });
                }

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

                    cDish.Image         = guid;
                    cDish.ImageMimeType = existingDish.ImageMimeType;
                }
            }
            else
            {
                cDish.Name       = dish.Name;
                cDish.UserId     = ownerId;
                cDish.ModifiedAt = DateTime.UtcNow;
                cDish.CreatedAt  = DateTime.UtcNow;

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

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

                if (dish.Dishes != null)
                {
                    foreach (var item in dish.Dishes)
                    {
                        var dComDish = new DishCompoundDish
                        {
                            CompoundDish = cDish,
                            DishId       = item.DishId,
                            DishQty      = item.Qty
                        };
                        await _uow.DishCompoundDishRepository.AddAsync(dComDish);
                    }
                }
            }

            await _uow.CompoundDishRepository.AddAsync(cDish);

            return(cDish);
        }
예제 #4
0
        private bool IsLackSelfControl(CompoundDish dish)
        {
            var loggedUser = _httpContextAccessor.CurrentUser();

            return(dish.LackSelfControlDishes.Any(fd => fd.UserId == loggedUser));
        }
예제 #5
0
        private bool IsFavorite(CompoundDish dish)
        {
            var loggedUser = _httpContextAccessor.CurrentUser();

            return(dish.FavoriteDishes.Any(fd => fd.UserId == loggedUser));
        }