示例#1
0
        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));
        }