Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using BlackHoles.DataContexts;
using BlackHoles.Entities;
using BlackHoles.Utils;
namespace BlackHoles.Controllers
{
public class ArticlesController : Controller
{
private IssuesDb db = new IssuesDb();
// GET: Articles
public ActionResult Index()
{
var userId = User.GetUserId();
return View(db.Articles.Where(a => a.Owner.Id == userId).ToList());
}
// GET: Articles/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Article article = db.Articles.Find(id);
if (article == null || article.Owner.Id != User.GetUserId())
{
return HttpNotFound();
}
return View(article);
}
// GET: Articles/Create
public ActionResult Create()
{
return View();
}
// POST: Articles/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Specialty,RusArtTitles,ShortArtTitles,RusAbstract,RusKeywords,EnuArtTitles,EnuAbstract,EnuKeywords")] Article article)
{
article.Owner = User.GetApplicationUser();
if (ModelState.IsValid)
{
db.Articles.Add(article);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(article);
}
// GET: Articles/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Article article = db.Articles.Find(id);
if (article == null)
{
return HttpNotFound();
}
return View(article);
}
[HttpPost]
public ActionResult AddAuthors(int autorId)
{
return View();
}
//[HttpPost]
public ActionResult AddAuthorsAjax(int autorId)
{
if (ViewBag.Autors == null)
ViewBag.Autors = new List<Author>();
var autors = (List<Author>)ViewBag.Autors;
var autor = db.Authors.Where(a => a.Id == autorId).FirstOrDefault();
if (autor != null)
autors.Add(autor);
return PartialView("Autors", autors);
}
// POST: Articles/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Id,Specialty,RusArtTitles,ShortArtTitles,RusAbstract,RusKeywords,EnuArtTitles,EnuAbstract,EnuKeywords")] Article article)
{
if (ModelState.IsValid)
{
db.Entry(article).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(article);
}
// GET: Articles/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Article article = db.Articles.Find(id);
if (article == null)
{
return HttpNotFound();
}
return View(article);
}
// POST: Articles/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Article article = db.Articles.Find(id);
db.Articles.Remove(article);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.