コード例 #1
0
 public ActionResult AddOrEdit(imageModel img)
 {
     if (img.ImageUpload != null)
     {
         string fileName  = Path.GetFileNameWithoutExtension(img.ImageUpload.FileName);
         string extension = Path.GetExtension(img.ImageUpload.FileName);
         fileName      = img.Name + extension;
         img.ImagePath = "/File/image/" + fileName;
         img.ImageUpload.SaveAs(Path.Combine(Server.MapPath("/File/image/"), fileName));
     }
     using (UploadImageContext db = new UploadImageContext())
     {
         if (img.Id == 0)
         {
             image obj = new image();
             obj.ImagePath = img.ImagePath;
             obj.Name      = img.Name;
             db.images.Add(obj);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved successfully!!!" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(img).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated successfully!!!" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
コード例 #2
0
 public ActionResult Delete(int id)
 {
     using (UploadImageContext db = new UploadImageContext())
     {
         image img = db.images.Where(x => x.Id == id).FirstOrDefault <image>();
         db.images.Remove(img);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted successfully!!!" }, JsonRequestBehavior.AllowGet));
     }
 }