public IActionResult New(BlogDataModel blog, IFormFile formFile)
        {
            if (ModelState.IsValid)
            {
                if (formFile == null || formFile.Length <= 0)
                {
                    ModelState.AddModelError("", "Your Blog need a Cover!");
                    return(View(blog));
                }

                BlogDataModel newBlog = new BlogDataModel
                {
                    Name        = blog.Name,
                    Description = blog.Description,
                    Cover       = FileToByteArray(formFile),
                    Created     = DateTime.Now
                };

                this.applicationContext.Blogs.Add(newBlog);
                this.applicationContext.SaveChanges();

                return(RedirectToAction("View", "Blog", new { id = this.applicationContext.Blogs.FirstOrDefault(x => x.Name == newBlog.Name).BlogId }));
            }
            return(View(blog));
        }
        /// <summary>
        /// Blog view
        /// </summary>
        /// <returns></returns>
        public ActionResult Blog()
        {
            ViewBag.Message = "Blog";
            BlogService          svc      = new BlogService();
            List <BlogFileTbl>   fileTbl  = svc.ReadAllBlogFiles();
            List <BlogTbl>       blogTbl  = svc.ReadAllBlogItems();
            List <BlogDataModel> blogList = new List <BlogDataModel>();

            foreach (BlogTbl blogItem in blogTbl)
            {
                BlogDataModel model = new BlogDataModel();
                foreach (BlogFileTbl fileItem in fileTbl)
                {
                    if (fileItem.BlogId == blogItem.Id)
                    {
                        model.FileData = fileItem.FileData.ToArray();
                    }
                }
                //Assigning values to blog model
                model.BlogTitle   = blogItem.BlogTitle;
                model.BlogContent = blogItem.BlogContent;
                model.DateCreated = (DateTime)blogItem.DateCreated;
                blogList.Add(model);
            }
            return(View(blogList));
        }
Exemple #3
0
        public ActionResult EditBlogEntry(BlogDataModel model)
        {
            BlogService svc = new BlogService();

            svc.EditBlogRecord(model);
            return(Redirect("/Account/BlogTool?GUID=" + AdminToolsGUID));
        }
Exemple #4
0
        public void EditBlogRecord(BlogDataModel model)
        {
            dbContext = new RockstarDBModelDataContext();
            BlogTbl     oldBlogItem = dbContext.BlogTbls.Where(o => o.Id == model.Id).FirstOrDefault();
            BlogFileTbl oldBlogFile = dbContext.BlogFileTbls.Where(f => f.BlogId == model.Id).FirstOrDefault();
            DateTime    now         = DateTime.UtcNow;
            DateTime    localNow    = TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);

            oldBlogItem.BlogTitle   = model.BlogTitle;
            oldBlogItem.BlogContent = model.BlogContent;
            oldBlogItem.DateCreated = localNow;


            if (model.FileContent != null)
            {
                byte[] firstUploadFile = new byte[model.FileContent.InputStream.Length];
                model.FileContent.InputStream.Read(firstUploadFile, 0, firstUploadFile.Length);

                oldBlogFile.FileTitle = model.FileContent.FileName;
                oldBlogFile.FileData  = firstUploadFile;
                oldBlogFile.BlogId    = oldBlogItem.Id;
            }


            dbContext.SubmitChanges();
        }
Exemple #5
0
        public void CreateBlogEntry(BlogDataModel model)
        {
            dbContext = new RockstarDBModelDataContext();
            BlogTbl     blogTbl     = new BlogTbl();
            BlogFileTbl blogFileTbl = new BlogFileTbl();
            DateTime    now         = DateTime.UtcNow;
            DateTime    localNow    = TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);

            blogTbl.BlogTitle   = model.BlogTitle;
            blogTbl.BlogContent = model.BlogContent;
            blogTbl.DateCreated = localNow;

            dbContext.BlogTbls.InsertOnSubmit(blogTbl);
            dbContext.SubmitChanges();

            if (model.FileContent != null)
            {
                byte[] firstUploadFile = new byte[model.FileContent.InputStream.Length];
                model.FileContent.InputStream.Read(firstUploadFile, 0, firstUploadFile.Length);

                blogFileTbl.FileTitle = model.FileContent.FileName;
                blogFileTbl.FileData  = firstUploadFile;
                blogFileTbl.BlogId    = blogTbl.Id;
                dbContext.BlogFileTbls.InsertOnSubmit(blogFileTbl);
                dbContext.SubmitChanges();
            }
        }
Exemple #6
0
        public BlogDataModel GetBlogById(int Id)
        {
            BlogDataModel obj_CF = new BlogDataModel();
            List <KeyValuePair <string, string> > getByID_Parameters = new List <KeyValuePair <string, string> >();

            getByID_Parameters.Add(new KeyValuePair <string, string>("@Blog_Id", Convert.ToString(Id)));
            obj_CF = JsonConvert.DeserializeObject <BlogDataModel>(obj_Blog_DAL.GetBlogById(getByID_Parameters));
            return(obj_CF);
        }
        public IActionResult Delete(int id)
        {
            BlogDataModel blog = this.applicationContext.Blogs.Include(x => x.Posts).FirstOrDefault(x => x.BlogId == id);

            this.applicationContext.Posts.RemoveRange(blog.Posts);
            this.applicationContext.Blogs.Remove(blog);
            this.applicationContext.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Exemple #8
0
        public string Insert_Update_Blog(BlogDataModel Blog_Model)
        {
            string result = "";
            List <KeyValuePair <string, string> > insert_Parameters = new List <KeyValuePair <string, string> >();

            insert_Parameters.Add(new KeyValuePair <string, string>("@Blog_Id", Convert.ToString(Blog_Model.Blog_Id)));
            insert_Parameters.Add(new KeyValuePair <string, string>("@Blog_Name", Convert.ToString(Blog_Model.Blog_Name)));
            insert_Parameters.Add(new KeyValuePair <string, string>("@Blog_Discription", Convert.ToString(Blog_Model.Blog_Discription)));
            insert_Parameters.Add(new KeyValuePair <string, string>("@Product_Id", Convert.ToString(Blog_Model.Product_Id)));
            result = obj_Blog_DAL.Insert_Update_Blog(insert_Parameters);
            return(result);
        }
Exemple #9
0
        public BlogDataModel ReadBlogModelItemByID(int id)
        {
            dbContext = new RockstarDBModelDataContext();
            BlogDataModel model = (from b in dbContext.BlogTbls
                                   where b.Id == id
                                   select new BlogDataModel
            {
                BlogTitle = b.BlogTitle,
                BlogContent = b.BlogContent
            }).FirstOrDefault();

            return(model);
        }
Exemple #10
0
 /// <summary>
 /// Edit blog view
 /// </summary>
 /// <param name="GUID"></param>
 /// <param name="Id"></param>
 /// <returns></returns>
 public ActionResult EditBlogEntry(string GUID, int Id)
 {
     if (!(String.IsNullOrEmpty(GUID)) && GUID.Equals(AdminToolsGUID))
     {
         BlogService svc = new BlogService();
         if (Id == 0)
         {
             return(View());
         }
         else
         {
             BlogDataModel model = svc.ReadBlogModelItemByID(Id);
             return(View(model));
         }
     }
     else
     {
         return(Redirect("/Home/Index"));
     }
 }
        public IActionResult Edit(int id, BlogDataModel blog, IFormFile formFile)
        {
            BlogDataModel target = this.applicationContext.Blogs.FirstOrDefault(x => x.BlogId == id);

            if (ModelState.IsValid)
            {
                target.Name        = blog.Name;
                target.Description = blog.Description;
                if (!(formFile == null || formFile.Length <= 0))
                {
                    target.Cover = FileToByteArray(formFile);
                }

                this.applicationContext.Blogs.Update(target);
                this.applicationContext.SaveChanges();

                return(RedirectToAction("View", "Blog", new { id }));
            }

            blog.Cover = target.Cover;
            return(View(blog));
        }
        public async Task <IActionResult> Edit(Guid id, BlogDataModel blog, IFormFile formFile)
        {
            var targetBlog = await this.blogRepository.GetById(id);

            if (ModelState.IsValid)
            {
                targetBlog.Name        = blog.Name;
                targetBlog.Description = blog.Description;

                if (!(formFile == null || formFile.Length <= 0))
                {
                    targetBlog.Cover = formFile.ToByteArray();
                }

                await this.blogRepository.Update(targetBlog);

                return(RedirectToAction("View", "Blog", new { id }));
            }

            blog.Cover = targetBlog.Cover;

            return(View(blog));
        }
Exemple #13
0
        public static async Task MainAsync(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            try
            {
                using (var scope = host.Services.CreateScope())
                {
                    using (var applicationContext = scope.ServiceProvider.GetService <ApplicationDbContext>())
                    {
                        await applicationContext.Database.EnsureCreatedAsync();

                        BlogDataModel   blogDataModel   = null;
                        ApplicationUser applicationUser = null;

                        using (var roleManager = scope.ServiceProvider.GetService <RoleManager <IdentityRole> >())
                        {
                            if (!await roleManager.RoleExistsAsync("Administrator"))
                            {
                                await roleManager.CreateAsync(new IdentityRole("Administrator"));
                            }

                            if (!await roleManager.RoleExistsAsync("Writer"))
                            {
                                await roleManager.CreateAsync(new IdentityRole("Writer"));
                            }
                        }

                        using (var userManager = scope.ServiceProvider.GetService <UserManager <ApplicationUser> >())
                        {
                            if (!applicationContext.Users.Any())
                            {
                                applicationUser          = new ApplicationUser();
                                applicationUser.UserName = "******";
                                applicationUser.Email    = "*****@*****.**";
                                applicationUser.Image    = System.IO.File.ReadAllBytes(".//wwwroot//images//ProfilPicture.png");

                                await userManager.CreateAsync(applicationUser, "adminPassword");

                                await userManager.AddToRoleAsync(applicationUser, "Administrator");
                            }
                        }

                        if (!applicationContext.Blogs.Any())
                        {
                            blogDataModel = new BlogDataModel
                            {
                                Cover       = System.IO.File.ReadAllBytes(".//wwwroot//images//Logo.png"),
                                Created     = DateTime.Now,
                                Description = "Welcome to Reddnet a Asp.Net Core mini Reddit",
                                Name        = "Welcome"
                            };

                            applicationContext.Blogs.Add(blogDataModel);
                        }

                        if (!applicationContext.Posts.Any())
                        {
                            PostDataModel postDataModel = new PostDataModel
                            {
                                Pinned    = true,
                                Archieved = true,
                                Blog      = blogDataModel,
                                Author    = applicationUser,
                                Title     = "Welcome to r/Welcome and Reddnet a Asp.Net Core mini Reddit",
                                Preview   = "Hello visitor this is not an serious Project that goes online",
                                Content   = "Hello visitor this is not an serious Project that goes online! <br> i only want to make an mini Reddit Clone to learn Asp.Net Core <br> And i wan´t to share it with your all!",
                                Link      = "https://github.com/cetoxx/Reddnet",
                                Cover     = System.IO.File.ReadAllBytes(".//wwwroot//images//Logo.png")
                            };

                            applicationContext.Posts.Add(postDataModel);
                        }

                        if (!applicationContext.Settings.Any())
                        {
                            SettingDataModel settingDataModel = new SettingDataModel
                            {
                                Title = "Reddnet",
                                Logo  = System.IO.File.ReadAllBytes(".//wwwroot//images//Logo.png")
                            };

                            applicationContext.Settings.Add(settingDataModel);
                        }

                        await applicationContext.SaveChangesAsync();
                    }
                }
            } catch { }
            await host.RunAsync();
        }
Exemple #14
0
 public BlogViewModel()
 {
     Blog        = new BlogDataModel();
     lst_Blog    = new List <BlogDataModel>();
     lst_Product = new List <Product_DataModel>();
 }