// // GET: /Photo/ public ActionResult Index() { using (var context = new BlogDataContext()) { return View(context.Events.ToList()); } }
// // GET: /Post/ public ActionResult Index() { // list all posts var db = new BlogDataContext(); var posts = db.Posts; return View(posts); }
public IActionResult Post(long id) { var db = new BlogDataContext(); var post = db.Posts.SingleOrDefault(x => x.Id == id); return(View(post)); }
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); }
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); } }
public ActionResult AddImage(int eventID) { using (var context = new BlogDataContext()) { AddImageView imageView = new AddImageView() { EventID = eventID }; return View(imageView); } }
public BlogDatabaseInitializer() { Database.SetInitializer(new DropCreateDatabaseAlways<BlogDataContext>()); if (!IsInitialized) { using (BlogDataContext dataCtx = new BlogDataContext()) { dataCtx.Database.Initialize(false); Seed(dataCtx); IsInitialized = true; } } }
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()); }
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")); }
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); } }
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)); }
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()); }
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()); }
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); } }
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() })); }
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()); }
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()); }
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)); }
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 })); }
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")); }
// 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)); }
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; }
public RecordDBRepository(BlogDataContext dataSource) => DataSource = dataSource;
public StatisticDBRepository(BlogDataContext dataSource) : base(dataSource) { }
public CommentsController(BlogDataContext db) { _db = db; }
public PostDBRepository(BlogDataContext dataSource) : base(dataSource) { }
public MonthlySpecialsViewComponent(BlogDataContext db) { this.db = db; }
//Injected via StructureMap public PostsController(BlogDataContext context) { this.context = context; }
public EFRoleRepo(BlogDataContext context) { this.context = context; }
public PageService(IBlogService blog, BlogDataContext dataContext) : base(blog, new PageDBRepository(dataContext)) { }
public PostsController(BlogDataContext dataContext) { _dataContext = dataContext; }
// // 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; }
public EFUserCredentialRepo(BlogDataContext context) { this.context = context; }