/// <summary> /// 录入图片路径信息 /// </summary> /// <param name="id"></param> /// <param name="imgPaths"></param> /// <returns></returns> public ActionResult EnteringPics(int id, string imgPaths) { var res = new JsonResult(); try { string[] getImgPathArry = imgPaths.Split(';'); foreach (var item in getImgPathArry) { if (item.Length > 0) { PointPicture newPic = new PointPicture(); newPic.DeviceInfoId = id; newPic.PicPath = item; pointPictureService.Add(newPic); } } res.Data = new { state = true }; } catch (Exception) { res.Data = new { state = false }; } return(res); }
public ActionResult editUploadImgs(int DevieceID, string path) { //将新增的图片目录录入数据库 PointPicture newPic = new PointPicture(); newPic.DeviceInfoId = DevieceID; newPic.PicPath = path; PointPicture addPic = pointPictureService.Add(newPic); var res = new JsonResult(); if (addPic.Id > 0) { res.Data = new { msg = true }; } else { res.Data = new { msg = false }; } return(res); }
/// <summary> /// 通过id删除已经存在的图片 /// </summary> /// <param name="context"></param> /// <returns></returns> public ActionResult DeleteExistImgs(int key) { //string getId = context.Request["key"]; //int idNum = Convert.ToInt32(getId); int idNum = key; var res = new JsonResult(); try { PointPicture deletePic = pointPictureService.Get(a => a.Id == idNum).First(); //相对路径 string filePath = deletePic.PicPath; //图片绝对路径 string absolutePath = Server.MapPath(filePath); //判断文件是否存在 if (System.IO.File.Exists(absolutePath)) { //如果文件存在,则删除 System.IO.File.Delete(absolutePath); } //从数据库中删除 if (pointPictureService.Delete(a => a.Id == idNum) > 0) { res.Data = new { msg = true }; } else { res.Data = new { msg = false }; } } catch (Exception) { res.Data = new { msg = false }; } return(res); }