Esempio n. 1
0
 //
 // GET: /Photo/
 public ActionResult Index()
 {
     using (var context = new BlogDataContext())
     {
         return View(context.Events.ToList());
     }
 }
Esempio n. 2
0
 //
 // GET: /Post/
 public ActionResult Index()
 {
     // list all posts
     var db = new BlogDataContext();
     var posts = db.Posts;
     return View(posts);
 }
Esempio n. 3
0
        public IActionResult Post(long id)
        {
            var db = new BlogDataContext();

            var post = db.Posts.SingleOrDefault(x => x.Id == id);

            return(View(post));
        }
Esempio n. 4
0
 public SqlServerBlogService(BlogDataContext dataContext)
 {
     DataContext      = dataContext;
     PostService      = new PostService(this, DataContext);
     PageService      = new PageService(this, DataContext);
     LayoutService    = new LayoutService(this, DataContext);
     CommentService   = new CommentService(this, DataContext);
     StatisticService = new StatisticService(this, DataContext);
     UserService      = new UserService(this, DataContext);
 }
Esempio n. 5
0
        public ActionResult ShowImages(int eventID)
        {
            if (ViewData["UploadSucceed"] != null)
                ViewBag.UploadSucceed = ViewData["UploadSucceed"].ToString();

            using (var context = new BlogDataContext())
            {
                ViewBag.EventID = eventID;
                List<Image> dogShowImages = context.Images.Where(i => i.Event.EventID == eventID).ToList();
                return View(dogShowImages);
            }
        }
Esempio n. 6
0
        public ActionResult AddImage(int eventID)
        {
            using (var context = new BlogDataContext())
            {
                AddImageView imageView = new AddImageView()
                {
                    EventID = eventID
                };

                return View(imageView);
            }
        }
Esempio n. 7
0
 public BlogDatabaseInitializer()
 {
     Database.SetInitializer(new DropCreateDatabaseAlways<BlogDataContext>());
     if (!IsInitialized)
     {
         using (BlogDataContext dataCtx = new BlogDataContext())
         {
             dataCtx.Database.Initialize(false);
             Seed(dataCtx);
             IsInitialized = true;
         }
     }
 }
Esempio n. 8
0
        public ActionResult Login(UserViewModel userModel)
        {
            _context = new BlogDataContext();
            var users = _context.Users.Where(u => u.Email == userModel.Email && u.Password == userModel.Password).ToList();

            if (users.Count > 0)
            {
                FormsAuthentication.SetAuthCookie(userModel.Email, false);
                return(RedirectToAction("Index", "Admin"));
            }

            return(View());
        }
Esempio n. 9
0
        public ActionResult DeleteBlog(int id)
        {
            _context = new BlogDataContext();
            var blog = _context.Blogs.SingleOrDefault(b => b.Id == id);

            if (blog != null)
            {
                _context.Blogs.Remove(blog);
                _context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 10
0
 public ActionResult Create(Post post)
 {
     var db = new BlogDataContext();
     try
     {
         // TODO: Add insert logic here
         db.Posts.InsertOnSubmit(post);
         db.SubmitChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View(post);
     }
 }
Esempio n. 11
0
        public ActionResult Blog(int id)
        {
            _context = new BlogDataContext();

            var blog = new BlogViewModel();
            var data = _context.Blogs.FirstOrDefault(i => i.Id == id);

            blog.Id       = data.Id;
            blog.Photo    = data.Photo;
            blog.PostDate = data.PostDate;
            blog.Title    = data.Title;
            blog.UserId   = data.UserId;
            blog.Content  = data.Content;
            return(View(blog));
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            using (BlogDataContext db = new BlogDataContext())
            {
                Blog blog = new Blog
                {
                    BlogId = 0,
                    Name   = "New blog",
                    Url    = "teste"
                };
                db.Blogs.Add(blog);
                db.SaveChanges();
            }

            Console.ReadKey();
        }
        public async Task <IActionResult> Create(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            post.PostedDate = DateTime.Now;
            post.Author     = User.Identity.Name;

            var db = new BlogDataContext();

            db.Posts.Add(post);
            await db.SaveChangesAsync();

            return(View());
        }
Esempio n. 14
0
        public ActionResult Delete(int id, Category category)
        {
            try
            {
                BlogDataContext.Delete(category);
                SaveChanges();
                ShowSuccess(SusuCMS.MessageResource.DeleteSuccess);

                return(RedirectToIndex());
            }
            catch
            {
                ShowError(SusuCMS.MessageResource.DeleteFailed);
            }

            return(RedirectToIndex());
        }
Esempio n. 15
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            var db = new BlogDataContext();
            var post = db.Posts.FirstOrDefault(x => x.PK_PostID == id);

            try
            {
                // TODO: Add update logic here
                UpdateModel(post);
                db.SubmitChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View(post);
            }
        }
Esempio n. 16
0
        public ActionResult Delete(int id, Article article)
        {
            try
            {
                BlogDataContext.Delete(article);
                SaveChanges();

                CalculateCount(article);

                ShowSuccess(SusuCMS.MessageResource.DeleteSuccess);

                return(RedirectToIndex());
            }
            catch
            {
                ShowError(SusuCMS.MessageResource.DeleteFailed);
            }

            return(RedirectToIndex());
        }
        public ActionResult Delete(int id)
        {
            var result = true;

            try
            {
                var draft = GetArticleDrafts().First(i => i.Id == id);

                BlogDataContext.Delete(draft);
                SaveChanges();
            }
            catch (Exception ex)
            {
                LogError(ex.ToString());

                result = false;
            }

            return(Json(new { IsSuccess = result, DraftCount = GetArticleDrafts().Count() }));
        }
Esempio n. 18
0
        public string Delete(int id)
        {
            var result = true;

            try
            {
                var tag = BlogDataContext.Tags.WithSiteId(CurrentSiteId).First(i => i.Id == id);
                tag.Articles.Clear();

                BlogDataContext.Delete(tag);
                SaveChanges();
            }
            catch (Exception ex)
            {
                LogError(ex.ToString());

                result = false;
            }

            return(result.ToString().ToLower());
        }
Esempio n. 19
0
        public ActionResult EditBlog(int id)
        {
            _context = new BlogDataContext();

            var getBlog = _context.Blogs.SingleOrDefault(b => b.Id == id);

            BlogViewModel blogModel = new BlogViewModel
            {
                Id       = getBlog.Id,
                Photo    = getBlog.Photo,
                PostDate = getBlog.PostDate,
                Title    = getBlog.Title,
                UserId   = getBlog.UserId,
                Content  = getBlog.Content
            };

            if (getBlog != null)
            {
                return(View(blogModel));
            }
            return(View());
        }
Esempio n. 20
0
        public ActionResult Index()
        {
            _context = new BlogDataContext();

            var blogContents = _context.Blogs.ToList();

            //List<BlogViewModel> blogViewModel = blogContents
            //    .Select(
            //        b => new BlogViewModel
            //        {
            //            Content = b.Content,
            //            Title = b.Title,
            //            Id = b.Id,
            //            Photo = b.Photo,
            //            PostDate = b.PostDate,
            //            UserId = b.UserId
            //        }
            //    ).ToList();

            List <BlogViewModel> blogViewModel = new List <BlogViewModel>();

            foreach (var item in blogContents)
            {
                blogViewModel.Add(
                    new BlogViewModel()
                {
                    Content  = item.Content,
                    Title    = item.Title,
                    Id       = item.Id,
                    Photo    = item.Photo,
                    PostDate = item.PostDate,
                    UserId   = item.UserId
                }
                    );
            }

            return(View(blogViewModel));
        }
Esempio n. 21
0
        public ActionResult EditBlog(BlogViewModel blogView, HttpPostedFileBase photoFile)
        {
            _context = new BlogDataContext();
            var blog = _context.Blogs.SingleOrDefault(b => b.Id == blogView.Id);

            if (blog != null)
            {
                blog.Content = blogView.Content;
                blog.Title   = blogView.Title;
                if (photoFile != null)
                {
                    blog.Photo = $@"{DateTime.UtcNow.Ticks}_{photoFile.FileName}";
                    //_blog.Photo = $@"{Guid.NewGuid()}{photoFile.FileName}";

                    var path = Path.Combine(Server.MapPath("~/Content/Upload/Photos"), blog.Photo);
                    photoFile.SaveAs(path);
                }

                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("EditBlog", new { id = blogView.Id }));
        }
Esempio n. 22
0
        public ActionResult Create(BlogViewModel model, HttpPostedFileBase photoFile)
        {
            var _blog = new Blogs();

            _blog.Title    = model.Title;
            _blog.Content  = model.Content;
            _blog.PostDate = DateTime.Now;

            if (photoFile != null)
            {
                _blog.Photo = $@"{DateTime.UtcNow.Ticks}_{photoFile.FileName}";
                //_blog.Photo = $@"{Guid.NewGuid()}{photoFile.FileName}";

                var path = Path.Combine(Server.MapPath("~/Content/Upload/Photos"), _blog.Photo);
                photoFile.SaveAs(path);
            }

            BlogDataContext _context = new BlogDataContext();

            _context.Blogs.Add(_blog);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
        // GET: Admin
        public ActionResult Index()
        {
            // creating or initializing object instance
            _context = new BlogDataContext();

            List <Blogs> getBlogs = _context.Blogs.ToList();

            List <BlogViewModel> model = new List <BlogViewModel>();

            foreach (var blog in getBlogs)
            {
                model.Add(new BlogViewModel
                {
                    Id       = blog.Id,
                    Content  = blog.Content,
                    Photo    = blog.Photo,
                    PostDate = blog.PostDate,
                    Title    = blog.Title,
                    UserId   = blog.UserId
                });
            }

            return(View(model));
        }
Esempio n. 24
0
 public CommentDBRepository(BlogDataContext dataSource) : base(dataSource)
 {
 }
 public HomeController(ILogger <HomeController> logger, BlogDataContext dbcontext)
 {
     _logger         = logger;
     this._dbcontext = dbcontext;
 }
 public HomeController(BlogDataContext blogDataContext)
 {
     _blogDataContext = blogDataContext;
 }
 public MonthlySpecialsViewComponent(BlogDataContext dp)
 {
     this._dp = dp;
 }
Esempio n. 28
0
 public RecordDBRepository(BlogDataContext dataSource) => DataSource = dataSource;
Esempio n. 29
0
 public StatisticDBRepository(BlogDataContext dataSource) : base(dataSource)
 {
 }
Esempio n. 30
0
 public CommentsController(BlogDataContext db)
 {
     _db = db;
 }
Esempio n. 31
0
 public PostDBRepository(BlogDataContext dataSource) : base(dataSource)
 {
 }
Esempio n. 32
0
 public MonthlySpecialsViewComponent(BlogDataContext db)
 {
     this.db = db;
 }
Esempio n. 33
0
 //Injected via StructureMap
 public PostsController(BlogDataContext context)
 {
     this.context = context;
 }
Esempio n. 34
0
 public EFRoleRepo(BlogDataContext context)
 {
     this.context = context;
 }
Esempio n. 35
0
 public PageService(IBlogService blog, BlogDataContext dataContext) : base(blog, new PageDBRepository(dataContext))
 {
 }
Esempio n. 36
0
 public PostsController(BlogDataContext dataContext)
 {
     _dataContext = dataContext;
 }
Esempio n. 37
0
 //
 // GET: /Post/Edit/5
 public ActionResult Edit(int id)
 {
     var db = new BlogDataContext();
     var post = db.Posts.FirstOrDefault(x => x.PK_PostID == id);
     return View(post);
 }
 public BlogController(BlogDataContext db)
 {
     _db = db;
 }
Esempio n. 39
0
 public EFUserCredentialRepo(BlogDataContext context)
 {
     this.context = context;
 }