public async Task <IActionResult> Create([Bind("VCName")] VillageCouncil villageCouncil) { try { if (ModelState.IsValid) { _context.Add(villageCouncil); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(villageCouncil)); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(villageCouncil)); }
public static void Initialize(AgrarianContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.VillageCouncils.Any()) { return; // DB has been seeded } var villageCounsils = new VillageCouncil[] { new VillageCouncil { VCName = "Бабин" }, new VillageCouncil { VCName = "Лубни" }, new VillageCouncil { VCName = "Пирятин" } }; foreach (VillageCouncil vc in villageCounsils) { context.VillageCouncils.Add(vc); } context.SaveChanges(); var fields = new Field[] { new Field { FieldName = 11, VCID = 1 }, new Field { FieldName = 12, VCID = 1 }, new Field { FieldName = 13, VCID = 1 }, new Field { FieldName = 14, VCID = 1 }, new Field { FieldName = 21, VCID = 2 }, new Field { FieldName = 22, VCID = 2 }, new Field { FieldName = 23, VCID = 2 }, new Field { FieldName = 24, VCID = 2 }, new Field { FieldName = 25, VCID = 2 }, new Field { FieldName = 31, VCID = 3 }, new Field { FieldName = 32, VCID = 3 } }; foreach (Field f in fields) { context.Fields.Add(f); } context.SaveChanges(); var complications = new Complication[] { new Complication { ComplicationName = "немає", ComplicationInfo = "" }, new Complication { ComplicationName = "болото", ComplicationInfo = "" }, new Complication { ComplicationName = "ліс", ComplicationInfo = "" }, new Complication { ComplicationName = "рельєф", ComplicationInfo = "" } }; foreach (Complication c in complications) { context.Complications.Add(c); } context.SaveChanges(); var shares = new Share[] { new Share { ShareName = 111, FiledID = 1, ComplicationID = 1, ShareArea = 6.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2345" }, new Share { ShareName = 112, FiledID = 1, ComplicationID = 1, ShareArea = 7.05, ShareRealArea = 7.00, ShareCN = "1234567891:34:345:2346" }, new Share { ShareName = 113, FiledID = 2, ComplicationID = 1, ShareArea = 8.05, ShareRealArea = 8.00, ShareCN = "1234567891:34:345:2347" }, new Share { ShareName = 114, FiledID = 2, ComplicationID = 2, ShareArea = 5.05, ShareRealArea = 4.05, ShareCN = "1234567891:34:345:2348" }, new Share { ShareName = 211, FiledID = 2, ComplicationID = 1, ShareArea = 2.05, ShareRealArea = 1.05, ShareCN = "1234567891:34:345:2349" }, new Share { ShareName = 212, FiledID = 3, ComplicationID = 1, ShareArea = 5.45, ShareRealArea = 3.05, ShareCN = "1234567891:34:345:2323" }, new Share { ShareName = 311, FiledID = 4, ComplicationID = 1, ShareArea = 7.45, ShareRealArea = 7.45, ShareCN = "1234567891:34:345:2324" }, new Share { ShareName = 411, FiledID = 5, ComplicationID = 3, ShareArea = 2.05, ShareRealArea = 2.05, ShareCN = "1234567891:34:345:2325" }, new Share { ShareName = 234, FiledID = 5, ComplicationID = 1, ShareArea = 6.35, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2326" }, new Share { ShareName = 345, FiledID = 6, ComplicationID = 1, ShareArea = 34.5, ShareRealArea = 34.5, ShareCN = "1234567891:34:345:2327" }, new Share { ShareName = 657, FiledID = 7, ComplicationID = 1, ShareArea = 3.05, ShareRealArea = 3.05, ShareCN = "1234567891:34:345:2328" }, new Share { ShareName = 745, FiledID = 8, ComplicationID = 1, ShareArea = 4.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2329" }, new Share { ShareName = 239, FiledID = 9, ComplicationID = 2, ShareArea = 6.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2330" }, new Share { ShareName = 269, FiledID = 9, ComplicationID = 1, ShareArea = 6.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2331" }, new Share { ShareName = 568, FiledID = 9, ComplicationID = 1, ShareArea = 1.05, ShareRealArea = 1.05, ShareCN = "1234567891:34:345:2332" }, new Share { ShareName = 340, FiledID = 10, ComplicationID = 4, ShareArea = 3.05, ShareRealArea = 3.05, ShareCN = "1234567891:34:345:2333" }, new Share { ShareName = 415, FiledID = 10, ComplicationID = 1, ShareArea = 4.05, ShareRealArea = 4.05, ShareCN = "1234567891:34:345:2334" }, new Share { ShareName = 336, FiledID = 10, ComplicationID = 1, ShareArea = 8.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2335" }, new Share { ShareName = 444, FiledID = 10, ComplicationID = 3, ShareArea = 3.05, ShareRealArea = 3.05, ShareCN = "1234567891:34:345:2336" }, new Share { ShareName = 555, FiledID = 11, ComplicationID = 1, ShareArea = 6.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2337" }, new Share { ShareName = 666, FiledID = 11, ComplicationID = 1, ShareArea = 4.05, ShareRealArea = 4.05, ShareCN = "1234567891:34:345:2338" }, new Share { ShareName = 777, FiledID = 11, ComplicationID = 1, ShareArea = 6.05, ShareRealArea = 6.05, ShareCN = "1234567891:34:345:2339" } }; foreach (Share sh in shares) { context.Shares.Add(sh); } context.SaveChanges(); var landLords = new LandLord[] { new LandLord { LLName = "Ткаленко Наталія Павлівна", LLPassID = "1234567891", LLPhone = "+380501234567", LLAdress = "Київ" }, new LandLord { LLName = "Іванчук Віктор Сергійович", LLPassID = "1234567892", LLPhone = "+380502234567", LLAdress = "Київ" }, new LandLord { LLName = "Мельник Іван Степанович", LLPassID = "1234567893", LLPhone = "+380503234567", LLAdress = "ЛЬвів" }, new LandLord { LLName = "Пшенична Любов Олександрівна", LLPassID = "1234567894", LLPhone = "+380504234567", LLAdress = "Львів" }, new LandLord { LLName = "Панасюк Антоніна Ярославівна", LLPassID = "1234567895", LLPhone = "+380505234567", LLAdress = "Тернопіль" }, new LandLord { LLName = "Максимчук Олександр Григорович", LLPassID = "1234567896", LLPhone = "+380506234567", LLAdress = "Тернопіль" }, new LandLord { LLName = "Абрамчук Віталій Ігорович", LLPassID = "1234567897", LLPhone = "+380507234567", LLAdress = "Тернопіль" }, new LandLord { LLName = "Василенко Ігор Васильвоич", LLPassID = "1234567898", LLPhone = "+380508234567", LLAdress = "Суми" }, new LandLord { LLName = "Дивак Галина Володимирівна", LLPassID = "1234567899", LLPhone = "+380509234567", LLAdress = "Суми" }, new LandLord { LLName = "Ковальчук Олег Павлович", LLPassID = "1234567811", LLPhone = "+380501034567", LLAdress = "Суми" } }; foreach (LandLord ll in landLords) { context.LandLords.Add(ll); } context.SaveChanges(); var contracts = new Contract[] { new Contract { LLID = 1, ShareID = 1, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 1, ShareID = 2, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 1, ShareID = 3, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 2, ShareID = 4, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 2, ShareID = 5, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 2, ShareID = 6, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 3, ShareID = 7, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 3, ShareID = 8, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 4, ShareID = 9, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 4, ShareID = 10, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 5, ShareID = 11, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 5, ShareID = 12, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 6, ShareID = 13, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 6, ShareID = 14, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 7, ShareID = 15, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 7, ShareID = 16, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 8, ShareID = 17, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 8, ShareID = 18, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 9, ShareID = 19, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 9, ShareID = 20, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 10, ShareID = 21, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, new Contract { LLID = 10, ShareID = 22, ContractBegin = DateTime.Parse("2018-09-01"), ContractEnd = DateTime.Parse("2023-09-01") }, }; foreach (Contract c in contracts) { context.Contracts.Add(c); } context.SaveChanges(); }