示例#1
0
        public async Task SetIsApprovedRecipe(int id)
        {
            ApprovalRecipe approvalRecipe = this.approvalRecipesRepository.All()
                                            .Where(ar => ar.Id == id)
                                            .FirstOrDefault();

            approvalRecipe.IsApproved = true;
            await this.approvalRecipesRepository.SaveChangesAsync();
        }
示例#2
0
        public async Task <int> AddApprovalRecipeAsync(string name, string description, int timeToPrepare, IFormFile image, string neededProducts, int subcategoryId, string userId)
        {
            string[] splittedProducts = neededProducts
                                        .Split(new[] { NewLine }, StringSplitOptions.None)
                                        .Where(sp => sp != string.Empty)
                                        .Select(sp => sp.TrimEnd(' ', ',', '.', '-', '_', '!', '?'))
                                        .Distinct()
                                        .ToArray();

            // Cloudinary upload image
            ImageUploadResult uploadResult = null;

            if (image != null)
            {
                byte[] destinationImage;

                using var memoryStream = new MemoryStream();
                await image.CopyToAsync(memoryStream);

                destinationImage = memoryStream.ToArray();

                using var destinationStream = new MemoryStream(destinationImage);

                var uploadParams = new ImageUploadParams
                {
                    File = new FileDescription(image.FileName, destinationStream),
                };

                uploadResult = await this.cloudinary.UploadAsync(uploadParams);
            }

            StringBuilder sb = new StringBuilder();

            foreach (var pr in splittedProducts)
            {
                sb.AppendLine(pr);
            }

            ApprovalRecipe approvalRecipe = new ApprovalRecipe
            {
                Name           = char.ToUpper(name[0]) + name.Substring(1).ToLower().TrimEnd(' ', ',', '.', '-', '_', '!', '?'),
                Description    = description,
                TimeToPrepare  = timeToPrepare,
                RecipeProducts = sb.ToString(),
                ImageUrl       = uploadResult != null ? uploadResult.Uri.AbsoluteUri : null,
                SubcategoryId  = subcategoryId,
                UserId         = userId,
            };

            await this.approvalRecipesRepository.AddAsync(approvalRecipe);

            await this.approvalRecipesRepository.SaveChangesAsync();

            return(approvalRecipe.Id);
        }
示例#3
0
        public async Task <bool> SetIsDeletedApprovalRecipe(int id)
        {
            ApprovalRecipe approvalRecipe = this.approvalRecipesRepository.All()
                                            .Where(ar => ar.Id == id).FirstOrDefault();

            approvalRecipe.IsDeleted = true;

            await this.approvalRecipesRepository.SaveChangesAsync();

            return(true);
        }