public async Task <IActionResult> Edit(EditApplicationViewModel request, List <string> Transport, string OtherTransport, List <string> Foundation, string OtherFoundation) { // получаем текущего пользователя Application app = _context.Application.Where(m => m.Id == request.Id).FirstOrDefault(); if (app == null) { return(RedirectToAction("Index", "Applications")); } if (ModelState.IsValid) { //получаем время открытия DateTime current = DateTime.Now; string temp; foreach (string f in Foundation) { temp = f; if (f == "Інше") { temp = OtherFoundation; } if (!_context.Foundation.Select(n => n.Trip_Foundation).Contains(temp)) { _context.Foundation.Add(new Foundation { Trip_Foundation = temp }); _context.SaveChanges(); } if (_context.App_Fundation.Where(af => af.ApplicationId == request.Id && af.FundationId == _context.Foundation.FirstOrDefault(f => f.Trip_Foundation == temp).Id).Count() == 0) { _context.App_Fundation.Add(new App_Fundation { ApplicationId = request.Id, FundationId = _context.Foundation.FirstOrDefault(n => n.Trip_Foundation == temp).Id }); } _context.SaveChanges(); } foreach (string t in Transport) { temp = t; if (t == "Інше") { temp = OtherTransport; } if (!_context.Transport.Select(n => n.TransportType).Contains(temp)) { _context.Transport.Add(new Transport { TransportType = temp }); _context.SaveChanges(); } if (_context.App_Transport.Where(at => at.ApplicationId == request.Id && at.TransportId == _context.Transport.FirstOrDefault(t => t.TransportType == temp).Id).Count() == 0) { _context.App_Transport.Add(new App_Transport { ApplicationId = request.Id, TransportId = _context.Transport.FirstOrDefault(n => n.TransportType == temp).Id }); } _context.SaveChanges(); } app.Institution = request.Institution; app.Email = request.Email; app.End_date = request.End_date; app.Fullname = request.Fullname; app.InstitutionLocation = request.InstitutionLocation; app.Itinerary = request.Itinerary; app.Main_place_of_work = request.Main_place_of_work; app.Payment = request.Payment; app.Position_in_combination = request.Position_in_combination; app.Purpose = request.Purpose; app.Saving_salary = request.Saving_salary; app.Start_date = request.Start_date; app.Trip_city = request.Trip_city; app.Trip_country = request.Trip_country; app.App_fundation_Id = request.Id; app.App_transport_Id = request.Id; if (ModelState.IsValid) { try { _context.Update(app); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationExists(app.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } } return(RedirectToAction("Edit")); }