public ActionResult DeleteJournal(string JournalId, string FilePath) { try { var curUrl = ConfigurationManager.AppSettings["url"].TrimEnd('/'); var pathDelete = FilePath.Replace(curUrl, "").Replace("/", "\\"); var serverDir = Server.MapPath("/").TrimEnd('\\'); var fileDel = serverDir + pathDelete; int idx = fileDel.IndexOf(JournalId); if (idx != -1) { fileDel = fileDel.Substring(0, idx + 36); System.IO.Directory.Delete(fileDel, true); } Guid journalId = Guid.Parse(JournalId); PlantDAL.EDMX.Journal journal = JournalCRUD.GetByID(journalId); List <Images> images = ImageCRUD.GetByJournalID(journalId); foreach (var img in images) { ImageCRUD.Delete(img); } JournalCRUD.Delete(journal); } catch (Exception ex) { ex.ToString(); } return(Json(new { IsError = false, message = "success", data = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult JournalDisplay(string journalId) { var curUrl = ConfigurationManager.AppSettings["url"]; curUrl = curUrl.TrimEnd('/'); PlantDAL.EDMX.Journal journal = JournalCRUD.GetByID(Guid.Parse(journalId)); JournalDto dto = Mappers.JournalMapper.MapDALToDto(journal); List <Images> imgs = ImageCRUD.GetByJournalID(Guid.Parse(journalId)); foreach (var img in imgs) { var idx = img.ImageFilePath.ToLower().IndexOf(@"\images\"); if (dto.imageFilePath == null) { dto.imageFilePath = new List <string>(); } if (idx != -1) { var imgpath = curUrl + img.ImageFilePath.Substring(idx).Replace("\\", "/"); dto.imageFilePath.Add(imgpath); } } PlantDAL.EDMX.Plant plant = PlantCRUD.GetByID(dto.PlantId); dto.Plants.Add(new SelectListItem { Text = plant.Name, Value = plant.ID.ToString() }); return(View(dto)); }
public ActionResult NewJournal(JournalDto journalDto) { Guid id = Guid.NewGuid(); journalDto.ID = id; journalDto.UserID = User.Identity.GetUserId(); var plantDir = Server.MapPath("~/Images/Journal/" + id.ToString()); List <Images> imgList = Mappers.ImageMapper.MapHTTPToImage(journalDto.Images, journalDto, plantDir); PlantDAL.EDMX.Journal journal = Mappers.JournalMapper.MapDtoToDAL(journalDto, imgList); journal.DateModified = DateTime.Now; JournalCRUD.Insert(journal); return(RedirectToAction("JournalTable")); }
public ActionResult JournalDetails(JournalDto journalDto) { var plantDir = Server.MapPath("~/Images/Journal/" + journalDto.ID.ToString()); List <Images> imgList = Mappers.ImageMapper.MapHTTPToImage(journalDto.Images, journalDto, plantDir); foreach (var img in imgList) { ImageCRUD.Insert(img); } PlantDAL.EDMX.Journal journal = Mappers.JournalMapper.MapDtoToDAL(journalDto, imgList); journal.UserID = User.Identity.GetUserId(); JournalCRUD.Update(journal); return(RedirectToAction("JournalTable")); }