Beispiel #1
0
        public ActionResult GetData()
        {
            // Initialization.
            JsonResult result = new JsonResult();

            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 listOfPlants = PlantCRUD.Search(strCurrentUserId, search, orderDir, order, startRec, pageSize);
                var tablePtants  = new List <PlantTableDto>();
                foreach (var plant in listOfPlants)
                {
                    List <Images> images   = ImageCRUD.GetByPlantID(plant.ID);
                    PlantTableDto tableDto = new PlantTableDto();
                    tableDto.PlantId     = plant.ID.ToString();
                    tableDto.Name        = plant.Name;
                    tableDto.Type        = plant.Type;
                    tableDto.Count       = plant.Count.ToString();
                    tableDto.Species     = plant.Species;
                    tableDto.Description = plant.Notes;
                    string firstImage = "";
                    if (images.Count() > 0)
                    {
                        firstImage = images.First().ImageFilePath;
                        int idx = firstImage.ToLower().IndexOf(@"\images\");
                        firstImage = firstImage.Substring(idx);
                    }
                    tableDto.Image = firstImage;
                    tablePtants.Add(tableDto);
                }

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

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

            // Return info.
            return(result);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public ActionResult NewJournal()
        {
            var journalDto = new JournalDto();
            List <PlantDAL.EDMX.Plant> plantList = new List <PlantDAL.EDMX.Plant>();

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

            return(View(journalDto));
        }
Beispiel #4
0
        public ActionResult JournalDetails(string journalId)
        {
            PlantDAL.EDMX.Journal journal = JournalCRUD.GetByID(Guid.Parse(journalId));
            JournalDto            dto     = Mappers.JournalMapper.MapDALToDto(journal);

            //PlantDAL.EDMX.Plant plant = PlantCRUD.GetByID(dto.PlantId);

            //dto.Plants.Add(new SelectListItem
            //{
            //    Text = plant.Name,
            //    Value = plant.ID.ToString()
            //});

            List <PlantDAL.EDMX.Plant> plantList = PlantCRUD.GetByUserID(User.Identity.GetUserId());

            foreach (var plant in plantList)
            {
                dto.Plants.Add(new SelectListItem
                {
                    Text  = plant.Name,
                    Value = plant.ID.ToString()
                });
            }

            List <Images> imgs = ImageCRUD.GetByJournalID(Guid.Parse(journalId));

            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);
                }
            }

            return(View(dto));
        }
Beispiel #5
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));
        }