Esempio n. 1
0
      public ActionResult Edit(int id, fileViewModel vf)
      {
          try
          {
              // TODO: Add update logic here
              var oldfile = db.tbl_files.SingleOrDefault(x => x.fileID == id);
              if (vf.file != null && oldfile.fileDispName != Path.GetFileName(vf.file.FileName))
              {
                  delete_file(oldfile.filePath);
                  var newfile = editfile(vf);
                  oldfile.fileCourse      = newfile.fileCourse;
                  oldfile.fileDispName    = newfile.fileDispName;
                  oldfile.filePath        = newfile.filePath;
                  oldfile.fileType        = newfile.fileType;
                  oldfile.fileDescription = newfile.fileDescription;

                  db.SaveChanges();
              }
              else
              {
                  oldfile.fileDescription = vf.description;
                  oldfile.fileCourse      = vf.courseID;
                  db.SaveChanges();
              }



              return(Json("success", JsonRequestBehavior.AllowGet));
          }
          catch (Exception ex)
          {
              return(Json(ex.Message, JsonRequestBehavior.AllowGet));
          }
      }
Esempio n. 2
0
      private tbl_files editfile(fileViewModel vf)
      {
          tbl_files f = null;

          try
          {
              f              = new tbl_files();
              f.fileID       = 1;
              f.fileDispName = Path.GetFileName(vf.file.FileName);
              //if (f.fileDispName.Length > 50) { f = null; return f; }
              f.fileDescription = vf.description;
              f.fileCourse      = vf.courseID;
              f.fileType        = Path.GetExtension(vf.file.FileName);

              string filepath = System.Web.HttpContext.Current.Server.MapPath($"../assets/files/{f.fileDispName}");
              filepath = filepath.Replace("\\Files", "");
              if (!System.IO.File.Exists(filepath))
              {
                  vf.file.SaveAs(filepath);
                  f.filePath = filepath;
                  return(f);
              }
              else
              {
                  f = null;
                  return(f);
              }
          }
          catch (Exception ex)
          {
              return(f);
          }
      }
Esempio n. 3
0
 public async Task <IActionResult> changeAvatarAsync([FromForm] fileViewModel model)
 {
     try
     {
         return(Ok(await this._fileService.saveProfileImage(User.Identity.Name, model.file)));
     } catch (Exception e)
     {
         return(BadRequest(e.Data["ERROR"]));
     }
 }
Esempio n. 4
0
      public ActionResult Create(fileViewModel vf)
      {
          try
          {
              tbl_files files = savefile(vf);
              if (files != null)
              {
                  db.tbl_files.Add(files);

                  db.SaveChanges();
                  return(Json("success", JsonRequestBehavior.AllowGet));
              }
              else
              {
                  return(Json("Failed to upload file Please rename the file to smaller name and reupload it", JsonRequestBehavior.AllowGet));
              }
          }
          catch (Exception ex)
          {
              return(Json(ex.Message, JsonRequestBehavior.AllowGet));
          }
      }