// PUT api/File/5
        public HttpResponseMessage PutFile(int id, CourseAider.Models.File file)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != file.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        // GET api/File/5
        public CourseAider.Models.File GetFile(int id)
        {
            CourseAider.Models.File file = db.Files.Find(id);
            if (file == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(file);
        }
        /*
         * // POST api/File
         * [System.Web.Mvc.Authorize]
         * public HttpResponseMessage PostFile(FileUploadModel fileModel, int id)
         * {
         *  if (ModelState.IsValid)
         *  {
         *      var file = db.Files.Create();
         *      var group = db.Groups.Find(id);
         *      if(group == null)
         *      {
         *          ModelState.AddModelError("File", new ArgumentException("No group with id:" + id));
         *          return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         *      }
         *
         *      file.Group = db.Groups.Find(id);
         *      var uploader = db.UserProfiles.FirstOrDefault(p => p.UserName == WebSecurity.CurrentUserName);
         *      if(uploader == null)
         *      {
         *          ModelState.AddModelError("File", new ArgumentException("Invalid uploader"));
         *          return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         *      }
         *      file.Uploader = uploader;
         *      file.Name = fileModel.File.FileName.Split('\\', '/').Last();
         *      file.UploadTime = DateTime.Now;
         *      file.Visibility = !fileModel.Private;
         *      db.Files.Add(file);
         *      db.SaveChanges();
         *
         *      file.Path = FileHelper.SaveFile(fileModel.File, "File", file.Id.ToString());
         *
         *      db.SaveChanges();
         *
         *      HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, file);
         *      response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = file.Id }));
         *      return response;
         *  }
         *  else
         *  {
         *      return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         *  }
         * }*/

        // DELETE api/File/5
        public HttpResponseMessage DeleteFile(int id)
        {
            CourseAider.Models.File file = db.Files.Find(id);
            if (file == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.Files.Remove(file);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, file));
        }