コード例 #1
0
 public ActionResult AddOrEdit(Spendings spend)
 {
     try
     {
         if (spend.ImageUpload != null)
         {
             string fileName  = Path.GetFileNameWithoutExtension(spend.ImageUpload.FileName);
             string extension = Path.GetExtension(spend.ImageUpload.FileName);
             fileName        = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
             spend.ImagePath = "~/AppFiles/Images/" + fileName;
             spend.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
         }
         using (CashJugDBEntities db = new CashJugDBEntities())
         {
             if (spend.ItemID == 0)
             {
                 db.Spendings.Add(spend);
                 db.SaveChanges();
             }
             else
             {
                 db.Entry(spend).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
         return(RedirectToAction("Index"));
         //return Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "Index", GetAllSpendings()), message = "Submitted successfully" }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         return(Json(new { success = true, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #2
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (CashJugDBEntities db = new CashJugDBEntities())
         {
             Spendings spend = db.Spendings.Where(x => x.ItemID == id).FirstOrDefault <Spendings>();
             db.Spendings.Remove(spend);
             db.SaveChanges();
         }
         return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllSpendings()), message = "Deleted successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = true, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }