Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
        public ActionResult GetData()
        {
            // Initialization.
            JsonResult result = this.Json(new { draw = Convert.ToInt32(0), recordsTotal = 0, recordsFiltered = 0, data = Array.Empty <JournalTableDto>() }, JsonRequestBehavior.AllowGet);

            try
            {
                var strCurrentUserId = User.Identity.GetUserId();

                // Initialization.
                string search   = Request.Form.GetValues("search[value]")[0];
                string draw     = Request.Form.GetValues("draw")[0];
                string order    = Request.Form.GetValues("order[0][column]")[0];
                string orderDir = Request.Form.GetValues("order[0][dir]")[0];
                int    startRec = Convert.ToInt32(Request.Form.GetValues("start")[0]);
                int    pageSize = Convert.ToInt32(Request.Form.GetValues("length")[0]);


                var listOfJournals = JournalCRUD.Search(strCurrentUserId, search, orderDir, order, startRec, pageSize);
                var tableJournals  = new List <JournalTableDto>();
                foreach (var journal in listOfJournals)
                {
                    List <Images>   images   = ImageCRUD.GetByJournalID(journal.ID);
                    JournalTableDto tableDto = new JournalTableDto();
                    tableDto.JournalId = journal.ID.ToString();
                    tableDto.Name      = journal.Name;
                    tableDto.Date      = journal.DateModified.ToString();
                    string firstImage = "";
                    if (images.Count() > 0)
                    {
                        firstImage = images.First().ImageFilePath;
                        int idx = firstImage.ToLower().IndexOf(@"\images\");
                        firstImage = firstImage.Substring(idx);
                    }
                    tableDto.Image = firstImage;
                    tableJournals.Add(tableDto);
                }

                int totalRecords = PlantCRUD.GetByUserID(strCurrentUserId).Count();
                int recFilter    = listOfJournals.Count();

                // Loading drop down lists.
                result = this.Json(new { draw = Convert.ToInt32(draw), recordsTotal = listOfJournals.Count(), recordsFiltered = recFilter, data = tableJournals }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                //Loger.Log.Error(ex);
            }

            // Return info.
            return(result);
        }
Ejemplo n.º 4
0
        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"));
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
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.º 7
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));
        }