예제 #1
0
        public async Task <int> ImportAsync(ImportRecipe model, IValidator <ImportRecipe> validator)
        {
            var ingredientReplacements = model.IngredientReplacements
                                         .Select(x => (x.Id, x.ReplacementId, x.TransferNutritionData, x.TransferPriceData));

            return(await _recipesRepository.ImportAsync(model.Id, ingredientReplacements, model.ImageUri, model.UserId));
        }
        public async Task <IActionResult> TryImport([FromBody] ImportRecipeDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            var importModel = new ImportRecipe();

            try
            {
                importModel.UserId = IdentityHelper.GetUserId(User);
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }

            if (dto.CheckIfReviewRequired && _recipeService.IngredientsReviewIsRequired(dto.Id, importModel.UserId))
            {
                return(Ok(0));
            }

            importModel.Id = dto.Id;
            importModel.IngredientReplacements = dto.IngredientReplacements;

            // Copy recipe image if not default
            RecipeToNotify recipe = await _recipeService.GetAsync(importModel.Id);

            string tempImagePath = Path.Combine(_webHostEnvironment.ContentRootPath, "storage", "temp", Guid.NewGuid().ToString());

            importModel.ImageUri = await _cdnService.CopyAndUploadAsync(
                tempImagePath : tempImagePath,
                imageUriToCopy : recipe.ImageUri,
                uploadPath : $"users/{importModel.UserId}/recipes",
                template : "recipe"
                );

            int id = await _recipeService.ImportAsync(importModel, _importRecipeValidator);

            // Notify
            User currentUser = await _userService.GetAsync(importModel.UserId);

            User recipeUser = await _userService.GetAsync(recipe.UserId);

            CultureInfo.CurrentCulture = new CultureInfo(recipeUser.Language, false);
            var message = _localizer["AcceptedSendRequestNotification", IdentityHelper.GetUserName(User), recipe.Name];

            var pushNotification = new PushNotification
            {
                SenderImageUri = currentUser.ImageUri,
                UserId         = recipeUser.Id,
                Application    = "Cooking Assistant",
                Message        = message
            };

            _senderService.Enqueue(pushNotification);

            return(StatusCode(201, id));
        }
예제 #3
0
        private void buttonItem15_Click(object sender, EventArgs e)
        {
            ImportRecipe ir = new ImportRecipe();

            ir.ShowDialog();
        }