public IHttpActionResult UpdateVolunteerPosition(int id, [FromBody] VolunteerPosition volunteerposition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != volunteerposition.CvpID)
            {
                return(BadRequest());
            }


            db.Entry(volunteerposition).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VolunteerPositionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Show(int id)
        {
            //preamble : make sure id is sanitized with input sql paramter
            //var query = "select * from volunteerpositions where volunteerpositionid=id"
            //postamble: have a result set and you want the first item of that result set
            VolunteerPosition selectedposition = db.VolunteerPosition.Where(vp => vp.VolunteerPositionID == id).FirstOrDefault();

            return(View(selectedposition)); //Now I know how to do this
        }
        public ActionResult Delete(int id)
        {
            VolunteerPosition position   = db.VolunteerPositions.SqlQuery("select * from VolunteerPositions where VolunteerPositionID = @id", new SqlParameter("@id", id)).FirstOrDefault();
            List <Department> department = db.Departments.SqlQuery("select * from Departments inner join VolunteerPositions on VolunteerPositions.DepartmentID = Departments.DepartmentID where VolunteerPositionID = @id", new SqlParameter("@id", id)).ToList();

            ShowVolunteerPosition ShowVolunteerPositionViewModel = new ShowVolunteerPosition();

            ShowVolunteerPositionViewModel.VolunteerPosition = position;
            ShowVolunteerPositionViewModel.Departments       = department;

            return(View(ShowVolunteerPositionViewModel));
        }
        public IHttpActionResult AddVolunteerPosition([FromBody] VolunteerPosition volunteerposition)
        {
            //Will Validate according to data annotations specified on model
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.VolunteerPositions.Add(volunteerposition);
            db.SaveChanges();

            return(Ok(volunteerposition.CvpID));
        }
        public IHttpActionResult DeleteVolunteerPosition(int id)
        {
            VolunteerPosition volunteerposition = db.VolunteerPositions.Find(id);

            if (volunteerposition == null)
            {
                return(NotFound());
            }

            db.VolunteerPositions.Remove(volunteerposition);
            db.SaveChanges();

            return(Ok());
        }
        public ActionResult Update(int id)
        {
            VolunteerPosition      selectedVolunteerPosition = db.VolunteerPositions.SqlQuery("select * from VolunteerPositions where VolunteerPositionID=@VolunteerPositionID", new SqlParameter("@VolunteerPositionID", id)).FirstOrDefault();
            List <Department>      departments = db.Departments.SqlQuery("select * from Departments").ToList();
            List <ApplicationUser> volunteers  = db.VolunteerPositions.Where(x => x.VolunteerPositionID == id).SelectMany(c => c.Users).ToList();
            // string userId = User.Identity.GetUserId();
            //ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.Id == userId);

            UpdateVolunteerPosition UpdateVolunteerPositionViewModel = new UpdateVolunteerPosition();

            UpdateVolunteerPositionViewModel.VolunteerPosition = selectedVolunteerPosition;
            UpdateVolunteerPositionViewModel.Departments       = departments;
            UpdateVolunteerPositionViewModel.Users             = volunteers;
            // UpdateJobListingViewModel.User = currentUser;

            return(View(UpdateVolunteerPositionViewModel));
        }
        public ActionResult Show(int?id)
        {
            VolunteerPosition volunteerPosition = db.VolunteerPositions.SqlQuery("select * from VolunteerPositions where VolunteerPositionID = @VolunteerPositionID", new SqlParameter("@VolunteerPositionID", id)).FirstOrDefault();
            //List <VolunteerPosition> volunteerPosition = db.VolunteerPositions.SqlQuery("select * from VolunteerPositions inner join VolunteerPositionApplicationUsers " +
            //    "on VolunteerPositionApplicationUsers.VolunteerPosition_VolunteerPositionID = VolunteerPositions.VolunteerPositionID " +
            //  "where VolunteerPosition_VolunteerPositionID = @VolunteerPositionID", new SqlParameter("@VolunteerPositionID", id)).ToList();


            List <Department>      department = db.Departments.SqlQuery("select * from Departments inner join VolunteerPositions on VolunteerPositions.DepartmentID = Departments.DepartmentID where VolunteerPositionID = @id", new SqlParameter("@id", id)).ToList();
            List <ApplicationUser> volunteers = db.VolunteerPositions.Where(x => x.VolunteerPositionID == id).SelectMany(c => c.Users).ToList();


            // string query = "select * from VolunteerPositionApplicationUsers where VolunteerPosition_VolunteerPositionID = @VolunteerPositionID";
            //  var fk_param = new SqlParameter("@VolunteerPositionID", id);

            //SqlParameter[] sqlparams = new SqlParameter[1];
            // sqlparams[0] = new SqlParameter("@VolunteerPositionID", id);
            //  List<ApplicationUser> volunteers = db.VolunteerPositions.SqlQuery(query, sqlparams).ToList();

            // string fk_query = "select * from VolunteerPositions inner join VolunteerPositionApplicationUsers " +
            //  "on VolunteerPositionApplicationUsers.VolunteerPosition_VolunteerPositionID = VolunteerPositions.VolunteerPositionID " +
            //   "where VolunteerPosition_VolunteerPositionID = @VolunteerPositionID";
            //  var fk_param = new SqlParameter("@VolunteerPositionID", id);
            // List<VolunteerPosition> volunteerPosition = db.VolunteerPositions.SqlQuery(fk_query, fk_param).ToList();



            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (volunteerPosition == null)
            {
                return(HttpNotFound());
            }
            ShowVolunteerPosition ShowVolunteerPositionViewModel = new ShowVolunteerPosition();

            ShowVolunteerPositionViewModel.VolunteerPosition = volunteerPosition;
            ShowVolunteerPositionViewModel.Departments       = department;
            ShowVolunteerPositionViewModel.Users             = volunteers;


            return(View(ShowVolunteerPositionViewModel));
        }
        public ActionResult Create(VolunteerPosition VolunteerPositionInfo)
        {
            Debug.WriteLine(VolunteerPositionInfo.Name);
            string url = "volunteerpositiondata/addvolunteerposition";

            Debug.WriteLine(jss.Serialize(VolunteerPositionInfo));
            HttpContent content = new StringContent(jss.Serialize(VolunteerPositionInfo));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = client.PostAsync(url, content).Result;

            if (response.IsSuccessStatusCode)
            {
                int volunteerpositionid = response.Content.ReadAsAsync <int>().Result;
                return(RedirectToAction("Details", new { id = volunteerpositionid }));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult FindVolunteerPosition(int id)
        {
            //Find the data
            VolunteerPosition VolunteerPosition = db.VolunteerPositions.Find(id);

            //if not found, return 404 status code.
            if (VolunteerPosition == null)
            {
                return(NotFound());
            }


            VolunteerPositionDto VolunteerPositionDto = new VolunteerPositionDto
            {
                CvpID        = VolunteerPosition.CvpID,
                Name         = VolunteerPosition.Name,
                Description  = VolunteerPosition.Description,
                DepartmentID = VolunteerPosition.DepartmentID
            };


            //pass along data as 200 status code OK response
            return(Ok(VolunteerPositionDto));
        }
        public ActionResult Edit(int id)
        {
            VolunteerPosition volunteerPosition = db.VolunteerPosition.Find(id);

            return(View(volunteerPosition));
        }