public IActionResult Index() { MiastoAddViewModel model = new MiastoAddViewModel(); model.Tagi = _tagRepozytory.PobierzWszustkieTagi().ToList(); return(View(model)); }
public IActionResult Index(MiastoAddViewModel model) { if (ModelState.IsValid) { string uniquefileName = null; if (model.Zdiencie != null) { string uploatFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniquefileName = Guid.NewGuid().ToString() + "_" + model.Zdiencie.FileName; string filePath = Path.Combine(uploatFolder, uniquefileName); model.Zdiencie.CopyTo(new FileStream(filePath, FileMode.Create)); //_zdjecieRepozytory.dodajZdjecie(newZdjecie); Miejsce newMiejsce = new Miejsce { Nazwa = model.Nazwa, Opis = model.Opis, ZdieciaList = new List <Zdjecie>(), MiejsceTag = new List <MiejsceTag>(), szerokosc = model.szerokosc, wysokosc = model.wysokosc }; newMiejsce.ZdieciaList.Add(new Zdjecie { Url = uniquefileName }); if (model.AreChecked == null) { newMiejsce.MiejsceTag.Add(new MiejsceTag { TagId = 9, Tag = _tagRepozytory.PobierzTagId(9), MiejsceId = newMiejsce.MiejsceId, Miejsce = newMiejsce });; } else { foreach (int item in model.AreChecked) { newMiejsce.MiejsceTag.Add(new MiejsceTag { TagId = item, Tag = _tagRepozytory.PobierzTagId(item), MiejsceId = newMiejsce.MiejsceId, Miejsce = newMiejsce });; } } _IMiejscaRepozytory.dodajMiejsce(newMiejsce); return(RedirectToAction("miejsceZgloszone")); } } model.Tagi = _tagRepozytory.PobierzWszustkieTagi().ToList(); return(View(model)); }