public async Task <IActionResult> GetOpportunity([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Opportunity opportunity = (await VollyMemoryCache.GetAllOpportunities(_memoryCache, _context)) .SingleOrDefault(m => m.Id == id); if (opportunity == null) { return(NotFound()); } return(Ok(OpportunityView.FromOpportunity(opportunity))); }
public IActionResult Index() { List <OpportunityView> opportunityViews = _context.Opportunities .Include(o => o.Category) .Include(o => o.Community) .Include(o => o.Organization) .ThenInclude(o => o.Cause) .Include(o => o.Location) .Include(o => o.Occurrences) .ThenInclude(o => o.Applications) .AsNoTracking() .Where(o => !o.Approved) .Select(o => OpportunityView.FromOpportunity(o)) .ToList(); return(View(opportunityViews)); }
public async Task <IActionResult> Create(OpportunityView opportunityView) { if (ModelState.IsValid) { Opportunity newOpportunity = new Opportunity() { Name = opportunityView.Name, Description = opportunityView.Description, SkillRequired = _context.Skills.Find(opportunityView.SkillRequiredId), Category = _context.Categories.Find(opportunityView.CategoryId), Organization = _context.Organizations.Find(opportunityView.OrganizationId), VolunteerType = _context.VolunteerTypes.Find(opportunityView.VolunteerTypeId), DateTime = opportunityView.DateTime }; _context.Add(newOpportunity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(opportunityView)); }
public async Task <IActionResult> PostOpportunity([FromBody] OpportunityView opportunityView) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Opportunity newOpportunity = new Opportunity { Name = opportunityView.Name, Description = opportunityView.Description, SkillRequired = _context.Skills.Find(opportunityView.SkillRequiredId), Category = _context.Categories.Find(opportunityView.CategoryId), Organization = _context.Organizations.Find(opportunityView.OrganizationId), VolunteerType = _context.VolunteerTypes.Find(opportunityView.VolunteerTypeId), DateTime = opportunityView.DateTime }; _context.Opportunities.Add(newOpportunity); await _context.SaveChangesAsync(); return(CreatedAtAction("GetOpportunity", new { id = newOpportunity.Id }, newOpportunity)); }