public static async Task SeedData(IBlogService blogService, ICategoryService categoryService, ICategoryBlogService categoryBlogService)
        {
            if ((await categoryService.GetAllAsync()).Count == 0)
            {
                await categoryService.AddAsync(new Category
                {
                    Name = "Lorem ipsum"
                });
            }

            if (await blogService.GetAllBlogCount() == 0)
            {
                await blogService.AddAsync(new Blog
                {
                    AppUserId        = 1,
                    Title            = "LOREM IPSUM NEDIR?",
                    Description      = "<h2 style=\"margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px; font-family: DauphinPlain; font-size: 24px; line-height: 24px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); --darkreader-inline-color:#e8e6e3; --darkreader-inline-bgcolor:#181a1b;\" data-darkreader-inline-color=\"\" data-darkreader-inline-bgcolor=\"\">Lorem Ipsum Nedir?</h2><p style=\"margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255); --darkreader-inline-color:#e8e6e3; --darkreader-inline-bgcolor:#181a1b;\" data-darkreader-inline-color=\"\" data-darkreader-inline-bgcolor=\"\"><strong style=\"margin: 0px; padding: 0px;\">Lorem Ipsum</strong>, dizgi ve baskı endüstrisinde kullanılan mıgır metinlerdir. Lorem Ipsum, adı bilinmeyen bir matbaacının bir hurufat numune kitabı oluşturmak üzere bir yazı galerisini alarak karıştırdığı 1500'lerden beri endüstri standardı sahte metinler olarak kullanılmıştır. Beşyüz yıl boyunca varlığını sürdürmekle kalmamış, aynı zamanda pek değişmeden elektronik dizgiye de sıçramıştır. 1960'larda Lorem Ipsum pasajları da içeren Letraset yapraklarının yayınlanması ile ve yakın zamanda Aldus PageMaker gibi Lorem Ipsum sürümleri içeren masaüstü yayıncılık yazılımları ile popüler olmuştur.</p>",
                    ShortDescription = "LOREM IPSUM, DIZGI VE BASKI ENDÜSTRISINDE KULLANILAN MIGIR METINLERDIR.",
                    ImagePath        = "blog-1.jpg",
                    PostedTime       = DateTime.Now
                });

                await blogService.AddAsync(new Blog
                {
                    AppUserId        = 1,
                    Title            = "LOREM IPSUM AÇIKLAMA",
                    Description      = "<p style=\"margin: 0px 14.3906px 0px 28.7969px; padding: 0px; width: 436.797px; float: left; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px;\"><h2 style=\"margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px; font-family: DauphinPlain; font-size: 24px; line-height: 24px;\">What is Lorem Ipsum?</h2><p style=\"margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; text-align: justify;\"><strong style=\"margin: 0px; padding: 0px;\">Lorem Ipsum</strong>&nbsp;is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Why do we use it?</p></p><p style=\"margin: 0px 28.7969px 0px 14.3906px; padding: 0px; width: 436.797px; float: right; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px;\"><h2 style=\"margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px; font-family: DauphinPlain; font-size: 24px; line-height: 24px;\">Why do we use it?<br></h2><p style=\"margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; text-align: justify;\">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p></p><p><br style=\"margin: 0px; padding: 0px; clear: both; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px; text-align: center;\"></p><p style=\"margin: 0px 14.3906px 0px 28.7969px; padding: 0px; width: 436.797px; float: left; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px;\"><h2 style=\"margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px; font-family: DauphinPlain; font-size: 24px; line-height: 24px;\">Where does it come from?</h2><p style=\"margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; text-align: justify;\">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.</p><p style=\"margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; text-align: justify;\">The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from \"de Finibus Bonorum et Malorum\" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p></p><p style=\"margin: 0px 28.7969px 0px 14.3906px; padding: 0px; width: 436.797px; float: right; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px;\"><h2 style=\"margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px; font-family: DauphinPlain; font-size: 24px; line-height: 24px;\">Where can I get some?</h2><p style=\"margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding: 0px; text-align: justify;\">There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p></p>",
                    ShortDescription = "WHAT IS LOREM IPSUM? WHY DO WE USE IT? WHERE DOES IT COME FROM? WHERE CAN I GET SOME?",
                    ImagePath        = "blog-2.jpg",
                    PostedTime       = DateTime.Now + TimeSpan.FromDays(1)
                });
            }

            if ((await categoryBlogService.GetAllAsync()).Count == 0)
            {
                await categoryBlogService.AddAsync(new CategoryBlog
                {
                    BlogId     = (await blogService.GetAllAsync())[0].Id,
                    CategoryId = (await categoryService.GetAllAsync())[0].Id
                });

                await categoryBlogService.AddAsync(new CategoryBlog
                {
                    BlogId     = (await blogService.GetAllAsync())[1].Id,
                    CategoryId = (await categoryService.GetAllAsync())[0].Id
                });
            }
        }
        public async Task <ActionResult> Create(BlogAddDto model, IFormFile photo)
        {
            if (ModelState.IsValid)
            {
                var allAdminUsers = _appUserService.GetAdminUsers();
                var arif          = allAdminUsers.FirstOrDefault(x => x.UserName == "*****@*****.**");

                if (arif != null)
                {
                    model.AppUserId = arif.Id;
                }

                if (photo != null)
                {
                    string extension = Path.GetExtension(photo.FileName);
                    string photoName = Guid.NewGuid() + extension;
                    string path      = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/" + photoName);
                    await using var stream = new FileStream(path, FileMode.Create);
                    await photo.CopyToAsync(stream);

                    model.ImagePath = photoName;
                }

                await _blogService.AddAsync(_mapper.Map <Blog>(model));

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Post([FromBody] BlogDTO blogDTO)
        {
            Blog blog = BlogMapper.mapSingleToBlog(blogDTO);
            await _blogService.AddAsync(blog);

            return(CreatedAtAction(nameof(Get), new { id = blog.Id }, blogDTO));
        }
        public async Task <ActionResult <Blog> > PostBlog([FromForm] BlogAddModel blogAddModel)
        {
            var uploadModel = await UploadImage(blogAddModel.Image, "image/jpeg");

            if (uploadModel.UploadState == UploadState.success)
            {
                blogAddModel.ImagePath = uploadModel.NewName;
                await _blogService.AddAsync(_mapper.Map <Blog>(blogAddModel));
            }
            else if (uploadModel.UploadState == UploadState.notExist)
            {
                await _blogService.AddAsync(_mapper.Map <Blog>(blogAddModel));
            }
            else
            {
                return(BadRequest("Resim kaydedilirken problem oluştu."));
            }

            return(Created("", blogAddModel));
        }
Beispiel #5
0
        public async Task <IActionResult> Create([FromForm] BlogAddModel blogAddModel)
        {
            var uploadModel = await UploadFileAsync(blogAddModel.Image, "image/jpeg");

            if (uploadModel.UploadState == UploadState.Success)
            {
                blogAddModel.ImagePath = uploadModel.NewName;
                await _blogService.AddAsync(_mapper.Map <Blog>(blogAddModel));

                return(Created("", blogAddModel));
            }
            else if (uploadModel.UploadState == UploadState.NotExist)
            {
                await _blogService.AddAsync(_mapper.Map <Blog>(blogAddModel));

                return(Created("", blogAddModel));
            }
            else
            {
                return(BadRequest(uploadModel.ErrorMessage));
            }
        }
        public async Task <IActionResult> Post([FromBody] NewBlogDTO resource)
        {
            var response = new SingleResponse <BlogDTO>();

            try
            {
                response.Data = await _service.AddAsync(resource);
            }
            catch (Exception ex)
            {
                response.Meta.Code         = -1;
                response.Meta.ErrorMessage = "Internal server error.";

                _logger.Error("There was an error on 'AddAsync' invocation.", ex);
            }

            return(response.ToHttpResponse());
        }
Beispiel #7
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                await _blogService.AddAsync(Blog, user);

                return(RedirectToPage("./Index"));
            }
            catch (ValidationException vex)
            {
                SetModelError(vex);
                return(Page());
            }
        }
Beispiel #8
0
 public async Task <BlogDTO> AddBlogAsync([FromBody] BlogDTO blog)
 {
     return(await service.AddAsync(blog));
 }
Beispiel #9
0
 public async Task <long> SaveBlog(BlogSave obj)
 {
     return(await _blogService.AddAsync(obj));
 }