Ejemplo n.º 1
0
        public ActionResult DeletePlant(string PlantId, 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(PlantId);
                if (idx != -1)
                {
                    fileDel = fileDel.Substring(0, idx + 36);
                    System.IO.Directory.Delete(fileDel, true);
                }
                Guid plantId = Guid.Parse(PlantId);
                PlantDAL.EDMX.Plant plant  = PlantCRUD.GetByID(plantId);
                List <Images>       images = ImageCRUD.GetByPlantID(plantId);
                foreach (var img in images)
                {
                    ImageCRUD.Delete(img);
                }


                if (plant.CustomValueOneID != null)
                {
                    CustomValues cv = CustomValueCRUD.GetByID(plant.CustomValueOneID);
                    CustomValueCRUD.Delete(cv);
                }
                if (plant.CustomValueTwoD != null)
                {
                    CustomValues cv = CustomValueCRUD.GetByID(plant.CustomValueTwoD);
                    CustomValueCRUD.Delete(cv);
                }
                if (plant.CustomValueThreeID != null)
                {
                    CustomValues cv = CustomValueCRUD.GetByID(plant.CustomValueThreeID);
                    CustomValueCRUD.Delete(cv);
                }
                if (plant.CustomValueFourID != null)
                {
                    CustomValues cv = CustomValueCRUD.GetByID(plant.CustomValueFourID);
                    CustomValueCRUD.Delete(cv);
                }
                if (plant.CustomValueFiveID != null)
                {
                    CustomValues cv = CustomValueCRUD.GetByID(plant.CustomValueFiveID);
                    CustomValueCRUD.Delete(cv);
                }

                List <PlantDAL.EDMX.Journal> journals = JournalCRUD.GetByPlantID(plant.ID);
                foreach (var jour in journals)
                {
                    List <Images> jourImages = ImageCRUD.GetByJournalID(jour.ID);
                    foreach (var img in jourImages)
                    {
                        ImageCRUD.Delete(img);
                    }

                    JournalCRUD.Delete(jour);
                }

                List <PlantDAL.EDMX.Plant> childrenPlants = PlantCRUD.GetByParentId(plant.ID);
                foreach (var plt in childrenPlants)
                {
                    if (plt.ParentOneID == plant.ID)
                    {
                        plt.ParentOneID = null;
                    }
                    if (plt.ParentTwoID == plant.ID)
                    {
                        plt.ParentTwoID = null;
                    }

                    PlantCRUD.Update(plt);
                }

                PlantCRUD.Delete(plant);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return(Json(new { IsError = false, message = "success", data = true }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult PlantDetails(string plantId)
        {
            PlantDAL.EDMX.Plant plant = PlantCRUD.GetByID(Guid.Parse(plantId));
            PlantDto            dto   = Mappers.PlantMapper.MapDALToDto(plant);

            List <PlantDAL.EDMX.Plant> plantList = new List <PlantDAL.EDMX.Plant>();

            plantList = PlantCRUD.GetByUserID(User.Identity.GetUserId());
            foreach (var plt in plantList)
            {
                dto.Plants.Add(new SelectListItem
                {
                    Text  = plt.Name,
                    Value = plt.ID.ToString()
                });
            }

            List <PlantDAL.EDMX.Journal> journalList = JournalCRUD.GetByPlantID(dto.ID);

            foreach (var jour in journalList)
            {
                dto.Journals.Add(new SelectListItem
                {
                    Text  = jour.Name,
                    Value = jour.ID.ToString()
                });
            }


            List <Images> imgs = ImageCRUD.GetByPlantID(Guid.Parse(plantId));

            var curUrl = ConfigurationManager.AppSettings["url"];

            curUrl = curUrl.TrimEnd('/');
            foreach (var img in imgs)
            {
                var idx = img.ImageFilePath.ToLower().IndexOf(@"\images\");
                if (idx != -1)
                {
                    if (dto.imageFilePath == null)
                    {
                        dto.imageFilePath = new List <string>();
                    }
                    var imgpath = curUrl + img.ImageFilePath.Substring(idx).Replace("\\", "/");
                    dto.imageFilePath.Add(imgpath);
                }
            }

            if (plant.CustomValueOneID != null || plant.CustomValueOneID == Guid.Empty)
            {
                plant.CustomValues = CustomValueCRUD.GetByID(plant.CustomValueOneID);
                dto.CustomValues1  = Mappers.CustomValueMapper.MapDALToDto(plant.CustomValues, 1) as CustomValueDto;
            }
            if (plant.CustomValueTwoD != null || plant.CustomValueOneID == Guid.Empty)
            {
                plant.CustomValues1 = CustomValueCRUD.GetByID(plant.CustomValueTwoD);
                dto.CustomValues2   = Mappers.CustomValueMapper.MapDALToDto(plant.CustomValues1, 2) as CustomValueDto;
            }
            if (plant.CustomValueThreeID != null || plant.CustomValueThreeID == Guid.Empty)
            {
                plant.CustomValues2 = CustomValueCRUD.GetByID(plant.CustomValueThreeID);
                dto.CustomValues3   = Mappers.CustomValueMapper.MapDALToDto(plant.CustomValues2, 3) as CustomValueDto;
            }
            if (plant.CustomValueFourID != null || plant.CustomValueFourID == Guid.Empty)
            {
                plant.CustomValues3 = CustomValueCRUD.GetByID(plant.CustomValueFourID);
                dto.CustomValues4   = Mappers.CustomValueMapper.MapDALToDto(plant.CustomValues3, 4) as CustomValueDto;
            }
            if (plant.CustomValueFiveID != null || plant.CustomValueFiveID == Guid.Empty)
            {
                plant.CustomValues4 = CustomValueCRUD.GetByID(plant.CustomValueFiveID);
                dto.CustomValues5   = Mappers.CustomValueMapper.MapDALToDto(plant.CustomValues4, 5) as CustomValueDto;
            }

            return(View(dto));
        }