// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Name"); return(Page()); } Location location = null; City city = await _context.City.FirstOrDefaultAsync(c => c.Name == CityName && c.CountryId == CountryId); if (city == null) { city = new City(); city.Name = CityName; city.CountryId = CountryId; } location = new Location(); location.City = city; Vacancy.Location = location; _context.Vacancy.Add(Vacancy); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Name"); return(Page()); } var location = await _context.Location .Include(l => l.City) .FirstOrDefaultAsync(m => m.Id == Vacancy.LocationId); if (location == null) { location = new Location(); Vacancy.Location = location; } City city = await _context.City.FirstOrDefaultAsync(c => c.Name == CityName && c.CountryId == CountryId); if (city == null) { city = new City(); city.Name = CityName; city.CountryId = CountryId; } location.City = city; _context.Attach(Vacancy).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VacancyExists(Vacancy.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Vacancy = await _context.Vacancy.FindAsync(id); if (Vacancy != null) { _context.Vacancy.Remove(Vacancy); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Project = await _context.Project .Include(p => p.Project_Language) .Include(p => p.Project_Skill) .FirstOrDefaultAsync(p => p.Id == id); if (Project != null) { _context.Project.Remove(Project); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index", new { place = Place })); }
public async Task <IActionResult> OnPostApplyAsync(int?id) { if (!id.HasValue) { return(new JsonResult(new { applied = false })); } var user = await _userManager.GetUserAsync(User); if (user == null || !user.VolunteerId.HasValue) { return(new JsonResult(new { applied = false })); } var userVacancy = await _context.User_Vacancy.FirstOrDefaultAsync(uv => uv.VacancyId == id.Value && uv.UserId == user.Id); var volunteer = await _context.Volunteer.FirstOrDefaultAsync(v => v.Id == user.VolunteerId); Vacancy = await _context.Vacancy.FirstOrDefaultAsync(v => v.Id == id); if (userVacancy != null || volunteer == null || !volunteer.NumberOfCoins.HasValue || volunteer.NumberOfCoins < Vacancy.Price) { return(new JsonResult(new { applied = false })); } else { volunteer.NumberOfCoins -= Vacancy.Price; _context.Attach(volunteer).State = EntityState.Modified; _context.User_Vacancy.Add(new User_Vacancy { VacancyId = id.Value, UserId = user.Id }); await _context.SaveChangesAsync(); } return(new JsonResult(new { applied = true })); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!IsRemote && string.IsNullOrEmpty(CityName)) { ModelState.AddModelError("CityName", "The field is required"); } if (!ModelState.IsValid) { ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Name"); ViewData["TopicId"] = new SelectList(_context.Topic, "Id", "Name"); return(Page()); } if (!IsRemote) { Location location = null; if (!string.IsNullOrEmpty(CityName)) { City city = await _context.City.FirstOrDefaultAsync(c => c.Name == CityName); if (city == null) { city = new City(); city.Name = CityName; city.CountryId = CountryId; } location = new Location(); location.StreetName = StreetName; location.StreetNumber = StreetNumber; location.City = city; } Project.Location = location; } var projectLanguagePage = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Project_Language> >(ProjectLanguageList); foreach (var pl in projectLanguagePage) { pl.LanguageId = pl.Language.Id; pl.ProjectId = Project.Id; pl.Language = null; } foreach (var pl in projectLanguagePage) { pl.Project = Project; _context.Project_Language.Add(pl); } var projectSkillPage = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Project_Skill> >(ProjectSkillList); foreach (var pl in projectSkillPage) { pl.SkillId = pl.Skill.Id; pl.ProjectId = Project.Id; pl.Skill = null; } foreach (var pl in projectSkillPage) { pl.Project = Project; _context.Project_Skill.Add(pl); } _context.Project.Add(Project); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { place = Place })); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!IsRemote && string.IsNullOrEmpty(CityName)) { ModelState.AddModelError("CityName", "The field is required"); } if (!ModelState.IsValid) { ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Name"); ViewData["TopicId"] = new SelectList(_context.Topic, "Id", "Name"); return(Page()); } var location = await _context.Location .Include(l => l.City) .FirstOrDefaultAsync(m => m.Id == Project.LocationId); if (location == null) { location = new Location(); Project.Location = location; } if (!string.IsNullOrEmpty(CityName)) { City city = await _context.City.FirstOrDefaultAsync(c => c.Name == CityName && c.CountryId == CountryId); if (city == null) { city = new City(); city.Name = CityName; city.CountryId = CountryId; } location.StreetName = StreetName; location.StreetNumber = StreetNumber; location.City = city; } if (IsRemote) { Project.Location = null; Project.LocationId = null; } var projectLanguageDB = await _context.Project_Language.Where(l => l.ProjectId == Project.Id).ToListAsync(); var projectLanguagePage = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Project_Language> >(ProjectLanguageList); foreach (var pl in projectLanguagePage) { pl.LanguageId = pl.Language.Id; pl.ProjectId = Project.Id; pl.Language = null; } foreach (var pl in projectLanguageDB) { if (projectLanguagePage.Where(l => l.LanguageId == pl.LanguageId).Count() == 0) { _context.Project_Language.Remove(pl); } } foreach (var pl in projectLanguagePage) { if (projectLanguageDB.Where(l => l.LanguageId == pl.LanguageId).Count() == 0) { _context.Project_Language.Add(pl); } } var projectSkillDB = await _context.Project_Skill.Where(l => l.ProjectId == Project.Id).ToListAsync(); var projectSkillPage = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Project_Skill> >(ProjectSkillList); foreach (var pl in projectSkillPage) { pl.SkillId = pl.Skill.Id; pl.ProjectId = Project.Id; pl.Skill = null; } foreach (var pl in projectSkillDB) { if (projectSkillPage.Where(l => l.SkillId == pl.SkillId).Count() == 0) { _context.Project_Skill.Remove(pl); } } foreach (var pl in projectSkillPage) { if (projectSkillDB.Where(l => l.SkillId == pl.SkillId).Count() == 0) { _context.Project_Skill.Add(pl); } } _context.Attach(Project).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(Project.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index", new { place = Place })); }