public ActionResult Index(string searchText, string message, int?i, bool update = false, int id = 0) { if (searchText != null) { searchText = searchText.ToLower(); } string messageType = null; if (update && db.authors.Count((a) => a.id == id) == 1) { authors targetAuthor = db.authors.Find(id); if (targetAuthor != null) { ViewData["Initials"] = targetAuthor.initials; ViewData["Update"] = update; ViewData["Id"] = id; } } if (message != null) { if (message == "Произошла ошибка или запись уже есть." || message == "Произошла непредвиденная ошибка." || message == "Произошла непредвиденная ошибка или автор с таким именем уже есть.") { messageType = "danger"; } else { messageType = "success"; } ViewData["messageType"] = messageType; ViewData["message"] = message; } return(View((db.authors.Where(author => author.initials.ToLower().Contains(searchText) || searchText == null)).OrderBy(x => x.initials).ToList().ToPagedList(i ?? 1, 10))); }
public ActionResult DeleteConfirmed(string id) { authors authors = db.authors.Find(id); db.authors.Remove(authors); db.SaveChanges(); return(RedirectToAction("Index")); }
private void SearchBtns_Click(object sender, EventArgs e) { All_form all_f = new All_form(); all_f.Hide(); authors auth = new authors(); auth.Show(); }
public ActionResult Edit([Bind(Include = "au_id,au_lname,au_fname,phone,address,city,state,zip,contract")] authors authors) { if (ModelState.IsValid) { db.Entry(authors).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authors)); }
public ActionResult Edit([Bind(Include = "author_id,author_name")] authors authors) { if (ModelState.IsValid) { db.Entry(authors).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authors)); }
public ActionResult Create([Bind(Include = "author_id,author_name")] authors authors) { if (ModelState.IsValid) { db.authors.Add(authors); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authors)); }
public ActionResult Create([Bind(Include = "au_id,au_lname,au_fname,phone,address,city,state,zip,contract")] authors authors) { if (ModelState.IsValid) { db.authors.Add(authors); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(authors)); }
// GET: authors/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } authors authors = db.authors.Find(id); if (authors == null) { return(HttpNotFound()); } return(View(authors)); }
// GET: Author/Edit/5 public ActionResult Edit(int?id) { string localMessage = "Произошла непредвиденная ошибка."; if (id != null) { authors targetAuthor = db.authors.Find(id); if (targetAuthor != null) { return(RedirectToAction("/Index", new { i = 1, id = id, update = true })); } } return(RedirectToAction("/Index", new { i = 1, message = localMessage })); }
public ActionResult Update(string authorInput, int idInput) { string localMessage = "Произошла непредвиденная ошибка или автор с таким именем уже есть."; if (ModelState.IsValid && db.authors.Count((a) => a.id == idInput) == 1 && db.authors.Count((a) => a.initials == authorInput) == 0) { authors targetAuthor = db.authors.Find(idInput); localMessage = $"Запись {targetAuthor.initials} успешно изменена на {authorInput}."; targetAuthor.initials = authorInput; db.Entry(targetAuthor).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("/Index", new { i = 1, message = localMessage })); }
public ActionResult CreateAP(string Authors, string[] Publications) { string localMessage = "Произошла ошибка или запись уже есть."; string Publications2 = Publications[0]; authors a = db.authors.Where(x => x.initials == Authors).FirstOrDefault(); publications p = db.publications.Where(x => x.title == Publications2).FirstOrDefault(); if (a != null && p != null && !p.authors.Contains(a)) { a.publications.Add(p); p.authors.Add(a); db.SaveChanges(); localMessage = $"Связь между автором: {a.initials} и публикацией: {p.title} успешно добавлена."; } return(RedirectToAction("/Index", new { message = localMessage })); }
private List <int> GetAuthors(string[] initials) { List <int> result = new List <int>(); if (initials.Count() > 0) { foreach (string s in initials) { authors a = db.authors.Where(x => x.initials == s).FirstOrDefault(); if (a != null) { result.Add(a.id); } } } return(result); }
// GET: Author/Delete/5 public ActionResult Delete(int?id) { string localMessage = null; if (id != null) { authors targetAuthor = db.authors.Find(id); if (targetAuthor != null) { db.authors.Remove(targetAuthor); db.SaveChanges(); localMessage = $"Запись {targetAuthor.initials} была успешно удалена."; return(RedirectToAction("/Index", new { i = 1, message = localMessage })); } } localMessage = "Произошла непредвиденная ошибка."; return(RedirectToAction("/Index", new { i = 1, message = localMessage })); }
public ActionResult Create(string authorInput) { string localMessage = "Произошла ошибка или запись уже есть."; if (ModelState.IsValid && db.authors.Count((a) => a.initials == authorInput) == 0) { int current_id = db.authors.Count(); while (db.authors.Count((a) => a.id == current_id) == 1) { current_id++; } authors newAuthor = new authors(); newAuthor.id = current_id; newAuthor.initials = authorInput; db.authors.Add(newAuthor); db.SaveChanges(); localMessage = $"Запись {authorInput} успешно добавлена."; } return(RedirectToAction("/Index", new { i = 1, message = localMessage })); }
public ActionResult DeleteConfirmed(string id) { var constring = System.Configuration.ConfigurationManager.ConnectionStrings["pubsEntities"].ConnectionString; if (constring.ToLower().StartsWith("metadata=")) { System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(constring); constring = efBuilder.ProviderConnectionString; } var con = new SqlConnection(constring); con.Open(); string query = "SELECT COUNT(*) FROM titleauthor"; var cmd = new SqlCommand(query, con); int rowsAmount = (int)cmd.ExecuteScalar(); titleauthor titleauthor; for (int i = 0; i < rowsAmount; i++) { titleauthor = db.titleauthor.FirstOrDefault(x => x.au_id == id); if (titleauthor == null) { } else { db.titleauthor.Remove(titleauthor); db.SaveChanges(); } } authors authors = db.authors.Find(id); db.authors.Remove(authors); db.SaveChanges(); return(RedirectToAction("Index")); }
partial void Updateauthors(authors instance);
public ActionResult Update(string titleInput, int idInput, int yearInput, string[] Authors, string Words, string Source, string Type, int issueInput = 0, int volumeInput = 0) { List <int> authorId = GetAuthors(Authors); string[] words = GetKeywords(Words); string localMessage = "Произошла непредвиденная ошибка или такая публикация уже есть."; try { if (ModelState.IsValid && db.publications.Count((a) => a.id == idInput) == 1 && db.publications.Count((a) => (a.title == titleInput) && (a.year == yearInput)) == 0) { publications targetPublication = db.publications.Find(idInput); localMessage = $"Запись {targetPublication.title} успешно изменена на {titleInput}."; targetPublication.title = titleInput; targetPublication.year = Convert.ToInt16(yearInput); foreach (authors au in targetPublication.authors) { au.publications.Remove(targetPublication); } targetPublication.authors.Clear(); foreach (int authorid in authorId) { authors a = db.authors.Find(authorid); if (a != null) { targetPublication.authors.Add(a); a.publications.Add(targetPublication); } } foreach (keywords kw in targetPublication.keywords) { kw.publications.Remove(targetPublication); } targetPublication.keywords.Clear(); foreach (string keyword in words) { keywords k = db.keywords.Where(x => x.keyword == keyword).FirstOrDefault(); if (k == null) { int k_id = db.keywords.Count(); while (db.keywords.Count((a) => a.id == k_id) == 1) { k_id++; } k = new keywords(); k.id = k_id; k.keyword = keyword; db.keywords.Add(k); db.SaveChanges(); } targetPublication.keywords.Add(k); k.publications.Add(targetPublication); } foreach (sources so in targetPublication.sources) { so.publications.Remove(targetPublication); } targetPublication.sources.Clear(); sources s = db.sources.Where(x => x.item_title == Source).FirstOrDefault(); if (s != null) { targetPublication.sources.Add(s); if (issueInput > 0 && volumeInput > 0) { s.journal_issue = issueInput; s.journal_volume = volumeInput; } else { s.journal_issue = null; s.journal_volume = null; } s.publications.Add(targetPublication); } foreach (types ty in targetPublication.types) { ty.publications.Remove(targetPublication); } targetPublication.types.Clear(); types t = db.types.Where(x => x.type_name == Type).FirstOrDefault(); if (t != null) { targetPublication.types.Add(t); t.publications.Add(targetPublication); } db.Entry(targetPublication).State = EntityState.Modified; db.SaveChanges(); } } catch { } return(RedirectToAction("/Index", new { i = 1, message = localMessage })); }
public ActionResult Create(string titleInput, int yearInput, string[] Authors, string Words, string Source, string Type, int issueInput = 0, int volumeInput = 0) { string localMessage = "Произошла ошибка или запись уже есть."; List <int> authorId = GetAuthors(Authors); string[] words = GetKeywords(Words); try { if (ModelState.IsValid && db.publications.Count((a) => a.title == titleInput) == 0 && authorId.Count != 0) { int current_id = db.publications.Count(); while (db.publications.Count((a) => a.id == current_id) == 1) { current_id++; } publications newPublication = new publications(); newPublication.id = current_id; newPublication.title = titleInput; newPublication.year = Convert.ToInt16(yearInput); foreach (int authorid in authorId) { authors a = db.authors.Find(authorid); if (a != null) { newPublication.authors.Add(a); a.publications.Add(newPublication); } } foreach (string keyword in words) { keywords k = db.keywords.Where(x => x.keyword == keyword).FirstOrDefault(); if (k == null) { int k_id = db.keywords.Count(); while (db.keywords.Count((a) => a.id == k_id) == 1) { k_id++; } k = new keywords(); k.id = k_id; k.keyword = keyword; db.keywords.Add(k); db.SaveChanges(); } newPublication.keywords.Add(k); k.publications.Add(newPublication); } sources s = db.sources.Where(x => x.item_title == Source).FirstOrDefault(); if (s != null) { newPublication.sources.Add(s); if (issueInput > 0 && volumeInput > 0) { s.journal_issue = issueInput; s.journal_volume = volumeInput; } else { s.journal_issue = null; s.journal_volume = null; } s.publications.Add(newPublication); } types t = db.types.Where(x => x.type_name == Type).FirstOrDefault(); if (t != null) { newPublication.types.Add(t); t.publications.Add(newPublication); } db.publications.Add(newPublication); db.SaveChanges(); localMessage = $"Запись {titleInput} успешно добавлена."; } } catch { } return(RedirectToAction("/Index", new { i = 1, message = localMessage })); }
partial void Insertauthors(authors instance);
partial void Deleteauthors(authors instance);
CreateAuthors(authors, article);