コード例 #1
0
        public override Result <Book> Insert(Book entity)
        {
            entity.UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name);

            var result = Validate(entity);

            if (result.Success)
            {
                var slug = _repository.Get()
                           .Where(x => x.Title.ToUpperInvariant().Equals(entity.Title.ToUpperInvariant()))
                           .OrderByDescending(x => x.CreationDate)?.FirstOrDefault()?.Slug;

                entity.Slug = slug == null?entity.Title.GenerateSlug() : slug.AddIncremental();

                entity.ImageSlug = ImageHelper.FormatImageName(entity.ImageName, entity.Slug);

                result.Value = _repository.Insert(entity);

                result.Value.ImageUrl = _uploadService.UploadImage(entity.ImageBytes, entity.ImageSlug, "Books");

                result.Value.ImageBytes = null;

                _booksEmailService.SendEmailNewBookInserted(entity);
            }
            return(result);
        }
コード例 #2
0
        public override Result <Book> Insert(Book entity)
        {
            entity.UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name);

            EBookValidate(entity);

            var result = Validate(entity);

            if (result.Success)
            {
                entity.Slug = SetSlugByTitleOrIncremental(entity);

                entity.ImageSlug = ImageHelper.FormatImageName(entity.ImageName, entity.Slug);

                if (entity.IsEbookPdfValid())
                {
                    entity.EBookPdfFile = _uploadService.UploadPdf(entity.EBookPdfBytes, entity.EBookPdfFile, "EBooks");
                }

                result.Value = _repository.Insert(entity);

                result.Value.ImageUrl = _uploadService.UploadImage(entity.ImageBytes, entity.ImageSlug, "Books");

                result.Value.ImageBytes = null;

                _booksEmailService.SendEmailNewBookInserted(entity).Wait();
            }
            return(result);
        }
コード例 #3
0
ファイル: BookService.cs プロジェクト: fonsecapontes/backend
        public override Result <Book> Insert(Book entity)
        {
            entity.UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name);

            var result = Validate(entity);

            if (result.Success)
            {
                entity.Image = ImageHelper.FormatImageName(entity.Image, entity.Id.ToString());

                _uploadService.UploadImage(entity.ImageBytes, entity.Image);
                result.Value = _repository.Insert(entity);
                _booksEmailService.SendEmailNewBookInserted(entity).Wait();
            }
            return(result);
        }
コード例 #4
0
        public override Result <Book> Insert(Book entity)
        {
            entity.UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name);

            var result = Validate(entity);

            if (result.Success)
            {
                entity.ImageSlug = ImageHelper.FormatImageName(entity.ImageName, entity.Title);

                entity.Slug = entity.Title.GenerateSlug();

                result.Value = _repository.Insert(entity);

                result.Value.ImageUrl = _uploadService.UploadImage(entity.ImageBytes, entity.ImageSlug, "Books");

                result.Value.ImageBytes = null;

                _booksEmailService.SendEmailNewBookInserted(entity).Wait();
            }
            return(result);
        }