public ActionResult Edit(int Id) { if (Session["CurrentAdmin"] == null) { return(RedirectToAction("SignIn", new RouteValueDictionary(new { Controller = "SignIn", Action = "SignIn" }))); } ТаблицаАвторов author = new ТаблицаАвторов(); try { author = context.ТаблицаАвторов.Single(x => x.КодАвтора == Id); } catch (Exception) { } return(View(author)); }
public ActionResult SaveChanges(int AuthorCode, string Name, string Patronymic, string Surname, HttpPostedFileBase file) { ТаблицаАвторов author = context.ТаблицаАвторов.Single(x => x.КодАвтора == AuthorCode); try { if (file != null) { byte[] picture = new byte[file.ContentLength]; file.InputStream.Read(picture, 0, file.ContentLength); author.Фотография = picture; } author.Имя = Name; author.Отчество = Patronymic; author.Фамилия = Surname; context.SaveChanges(); } catch (Exception) { return(RedirectToAction("Edit", new RouteValueDictionary(new { Controller = "Authors", Action = "Edit", Id = AuthorCode }))); } return(RedirectToAction("Edit", new RouteValueDictionary(new { Controller = "Authors", Action = "Edit", Id = AuthorCode }))); }
public ActionResult SaveNewAuthor(int AuthorCode, string Name, string Surname, string Patronymic, HttpPostedFileBase file) { try { byte[] picture = new byte[file.ContentLength]; file.InputStream.Read(picture, 0, file.ContentLength); ТаблицаАвторов author = new ТаблицаАвторов { КодАвтора = AuthorCode, Имя = Name, Фамилия = Surname, Отчество = Patronymic, Фотография = picture }; context.ТаблицаАвторов.Add(author); context.SaveChanges(); } catch (Exception) { } return(RedirectToAction("Create", new RouteValueDictionary(new { Controller = "Authors", Action = "Create" }))); }