private List <ТаблицаКниг> GetBooks(ТаблицаЗданий building) { List <ТаблицаКниг> Books = context.ТаблицаКниг.ToList(); List <string> NeededISBNs = new List <string>(); List <ТаблицаКниг> FinalBooks = new List <ТаблицаКниг>(); context.Entry(building).Collection(x => x.ЗданиеКнига).Load(); foreach (ЗданиеКнига instance in building.ЗданиеКнига) { NeededISBNs.Add(instance.ISBN); } // получен список ISBNs книг в данном здании for (int i = 0; i < Books.Count; i++) { for (int j = 0; j < NeededISBNs.Count; j++) { if (Books[i].ISBN == NeededISBNs[j]) { FinalBooks.Add(Books[i]); } } } return(FinalBooks); }
public ActionResult Edit(int Id) { if (Session["CurrentAdmin"] == null) { return(RedirectToAction("SignIn", new RouteValueDictionary(new { Controller = "SignIn", Action = "SignIn" }))); } ТаблицаЗданий building = new ТаблицаЗданий(); try { building = context.ТаблицаЗданий.Single(x => x.КодЗдания == Id); } catch (Exception) { } return(View(building)); }
public ActionResult SaveChanges(int BuildingCode, string Name, string City, string Street, string Number, int Floor, string Usage) { ТаблицаЗданий building = context.ТаблицаЗданий.Single(x => x.КодЗдания == BuildingCode); try { building.НазваниеЗдания = Name; building.Город = City; building.Улица = Street; building.НомерЗдания = Number; building.Этаж = Floor; building.Назначение = Usage; context.SaveChanges(); } catch (Exception) { return(RedirectToAction("Edit", new RouteValueDictionary(new { Controller = "Buildings", Action = "Edit", Id = BuildingCode }))); } return(RedirectToAction("Edit", new RouteValueDictionary(new { Controller = "Buildings", Action = "Edit", Id = BuildingCode }))); }
public ActionResult SaveNewBuilding(int BuildingCode, string Name, string City, string Street, string Number, int Floor, string Usage) { try { ТаблицаЗданий Building = new ТаблицаЗданий { КодЗдания = BuildingCode, НазваниеЗдания = Name, Город = City, Улица = Street, НомерЗдания = Number, Этаж = Floor, Назначение = Usage }; context.ТаблицаЗданий.Add(Building); context.SaveChanges(); } catch (Exception) { } return(RedirectToAction("Create", new RouteValueDictionary(new { Controller = "Buildings", Action = "Create" }))); }