public ActionResult UpdateDetail() { int repID = Int32.Parse(Request.Params["repID"]); int repStatusID = Int32.Parse(Request.Params["repStatusID"]); string repDetail = Request.Params["repDetail"]; string chkpic = Request.Params["oldPic"].ToString(); string fileName = ""; Database db = new Database(); RepairDAO rDAO = new RepairDAO(db); RepairModel rModel = rDAO.FindById(repID); db.Close(); if (Request.Files[0] != null) { var file = Request.Files[0]; if (file.ContentLength > 0) { UID uid = new UID(); fileName = uid.DateTimeToGuid(DateTime.Now).ToString() + Path.GetExtension(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/img_repair/"), fileName); file.SaveAs(path); // ลบไฟล์เก่าทิ้ง if (System.IO.File.Exists(Server.MapPath("~/Content/img_repair/") + rModel.IMAGES)) { System.IO.File.Delete(Server.MapPath("~/Content/img_repair/") + rModel.IMAGES); } } else { fileName = rModel.IMAGES; } } else { fileName = rModel.IMAGES; } RepairModel model = new RepairModel(); model.REPAIR_NO = repID; model.STATUS = new RepStatusModel(); model.STATUS.STATUS_ID = repStatusID; model.REPAIR_DETAIL = repDetail; model.IMAGES = fileName; model.ALERT_STATUS = "1"; db = new Database(); rDAO = new RepairDAO(db); rDAO.UpdateDetail(model); db.Close(); return(Redirect("~/Services/RepairDescription?repID=" + repID)); }