public IHttpActionResult UpdateVolunteerOpportunity(int id, [FromBody] VolunteerOpportunity VolunteerOpportunity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != VolunteerOpportunity.OpportunityID) { return(BadRequest()); } db.Entry(VolunteerOpportunity).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VolunteerOpportunityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult AddOpportunity(VolunteerOpportunity vo) { if (ModelState.IsValid) { using (VolunteerOpportunityDBContext db = new VolunteerOpportunityDBContext()) { db.VO.Add(vo); db.SaveChanges(); } ModelState.Clear(); } return(View()); }
public IHttpActionResult AddVolunteerOpportunity([FromBody] VolunteerOpportunity VolunteerOpportunity) { //Will Validate according to data annotations specified on model if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.VolunteerOpportunities.Add(VolunteerOpportunity); db.SaveChanges(); return(Ok(VolunteerOpportunity.OpportunityID)); }
public IHttpActionResult DeleteVolunteerOpportunity(int id) { VolunteerOpportunity VolunteerOpportunity = db.VolunteerOpportunities.Find(id); if (VolunteerOpportunity == null) { return(NotFound()); } db.VolunteerOpportunities.Remove(VolunteerOpportunity); db.SaveChanges(); return(Ok()); }
public ActionResult Edit(int id, VolunteerOpportunity VolunteerOpportunityInfo) { GetApplicationCookie(); Debug.WriteLine(VolunteerOpportunityInfo.OpportunityName); string url = "volunteeropportunitydata/updatevolunteeropportunity/" + id; Debug.WriteLine(jss.Serialize(VolunteerOpportunityInfo)); HttpContent content = new StringContent(jss.Serialize(VolunteerOpportunityInfo)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PostAsync(url, content).Result; if (response.IsSuccessStatusCode) { return(RedirectToAction("Details", new { id = id })); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindVolunteerOpportunity(int id) { //Find the data VolunteerOpportunity VolunteerOpportunity = db.VolunteerOpportunities.Find(id); //if not found, return 404 status code. if (VolunteerOpportunity == null) { return(NotFound()); } //put into a 'friendly object format' VolunteerOpportunityDto VolunteerOpportunityDto = new VolunteerOpportunityDto { OpportunityID = VolunteerOpportunity.OpportunityID, OpportunityName = VolunteerOpportunity.OpportunityName, Description = VolunteerOpportunity.Description }; //pass along data as 200 status code OK response return(Ok(VolunteerOpportunityDto)); }
public async Task <IActionResult> Edit(ICollection <IFormFile> images, IFormFile MainImg, int id, [Bind("Id,Featured,MemberId,Title,VolunteerOpp,InvestOpp,StartDate,FinishDate,ShortDesc,Description,Location,LatLng,SocialLinks,Status")] Project project) { if (id != project.Id) { return(NotFound()); } if (ModelState.IsValid) { try { // Image upload --- rewrite with good structure if (MainImg != null) { long size = MainImg.Length; // full path to file in temp location var filePath = Path.Combine("wwwroot/uploads/", MainImg.FileName); if (MainImg.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await MainImg.CopyToAsync(stream); } } //Database save project.MainImg = MainImg.FileName; } else { project.MainImg = (await _context.Projects.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id)).MainImg; } _context.Update(project); await _context.SaveChangesAsync(); if (project.VolunteerOpp && _context.VolunteerOpportunities.Any(opp => opp.ProjectId == project.Id)) { VolunteerOpportunity task = new VolunteerOpportunity(); task.JobType = "Help"; task.ProjectId = project.Id; task.Title = project.Title + " hepl!"; _context.Add(task); await _context.SaveChangesAsync(); } if (images != null) { foreach (var img in images) { var filePath = Path.Combine("wwwroot/uploads/", img.FileName); if (img.Length > 0) { using (var fileStream = new FileStream(filePath, FileMode.Create)) { await img.CopyToAsync(fileStream); Image tmpImg = new Image(); tmpImg.Name = "Image"; tmpImg.Path = img.FileName; tmpImg.ProjectId = id; _context.Images.Add(tmpImg); await _context.SaveChangesAsync(); } } } } } catch (DbUpdateConcurrencyException) { if (!ProjectExists(project.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["MemberId"] = new SelectList(_context.Members, "Id", "LastName", project.MemberId); ViewData["SocialId"] = new SelectList(_context.SocialServices, "Id", "Title"); return(View(project)); }
public async Task <IActionResult> Create(ICollection <IFormFile> images, IFormFile MainImg, [Bind("Id,Featured,MemberId,Title,VolunteerOpp,InvestOpp,StartDate,FinishDate,ShortDesc,Description,Location,LatLng,SocialLinks,Status")] Project project) { if (ModelState.IsValid) { // Image upload --- rewrite with good structure if (MainImg != null) { long size = MainImg.Length; // full path to file in temp location var filePath = Path.Combine("wwwroot/uploads/", MainImg.FileName); if (MainImg.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await MainImg.CopyToAsync(stream); } } //Database save project.MainImg = MainImg.FileName; } _context.Add(project); await _context.SaveChangesAsync(); if (project.VolunteerOpp) { VolunteerOpportunity task = new VolunteerOpportunity(); task.JobType = "Help"; task.ProjectId = project.Id; task.Title = project.Title + " hepl!"; _context.Add(task); await _context.SaveChangesAsync(); } if (images != null) { foreach (var img in images) { var filePath = Path.Combine("wwwroot/uploads/", img.FileName); if (img.Length > 0) { using (var fileStream = new FileStream(filePath, FileMode.Create)) { await img.CopyToAsync(fileStream); Image tmpImg = new Image(); tmpImg.Name = "Image"; tmpImg.Path = img.FileName; tmpImg.ProjectId = project.Id; _context.Images.Add(tmpImg); await _context.SaveChangesAsync(); } } } } return(RedirectToAction("Index")); } ViewData["MemberId"] = new SelectList(_context.Members, "Id", "LastName", project.MemberId); return(View(project)); }