Beispiel #1
0
        public ActionResult AddRandomPlant(long id)
        {
            PatchManager   patchManager   = new PatchManager();
            Patch          patch          = patchManager.Get(id);
            SubjectManager subjectManager = new SubjectManager();

            List <long> ids = subjectManager.GetAll <Plant>().Select(pa => pa.Id).ToList();


            Random random    = new Random();
            int    randomInt = random.Next(1, ids.Count - 1);

            long plantId = ids.ElementAt(randomInt);

            Plant p = subjectManager.Get(plantId) as Plant;

            Placement placement = new Placement();

            placement.Plant = p;
            placement.Patch = patch;

            patch.PatchElements.Add(placement);

            patchManager.Update(patch);

            PlacementModel model = PatchModelHelper.ConvertTo(placement);

            return(PartialView("Placement", model));
        }
Beispiel #2
0
        public ActionResult AddPlant(long id, long patchId)
        {
            try
            {
                PatchManager patchManager = new PatchManager();
                Patch        patch        = patchManager.Get(patchId);

                SubjectManager subjectManager = new SubjectManager();

                long plantId = id;

                Plant p = subjectManager.GetAll <Plant>().Where(x => x.Id.Equals(plantId)).FirstOrDefault();

                Placement placement = new Placement();
                placement.Plant = p;
                placement.Patch = patch;

                PlacementModel model = PatchModelHelper.ConvertTo(placement);

                return(PartialView("Placement", model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public ActionResult Save(PatchModel model)
        {
            if (model.Id == 0)
            {
                //create
                Patch        p            = PatchModelHelper.ConvertTo(model);
                PatchManager patchManager = new PatchManager();
                patchManager.Create(p);

                return(RedirectToAction("Index", "Patch"));
            }
            else
            {
                //update

                Patch        p            = PatchModelHelper.ConvertTo(model);
                PatchManager patchManager = new PatchManager();
                Patch        patch        = patchManager.Get(p.Id);

                if (patch != null)
                {
                    patch.Height        = p.Height;
                    patch.Width         = p.Width;
                    patch.NutrientClaim = p.NutrientClaim;
                    patch.LocationType  = p.LocationType;
                    patch.Name          = p.Name;
                    patch.Description   = p.Description;

                    patchManager.Update(patch);
                }
            }

            return(View("PatchEdit", model));
        }
Beispiel #4
0
        public ActionResult Patch(long id)
        {
            //get patch from db;
            PatchManager patchManager = new PatchManager();
            Patch        p            = patchManager.Get(id);

            PatchModel model = PatchModelHelper.ConvertTo(p);


            return(View(model));
        }
Beispiel #5
0
        // GET: Patch
        public ActionResult Index()
        {
            PatchManager patchManager = new PatchManager();

            var patches = patchManager.GetAll <Patch>();

            List <PatchModel> model = new List <PatchModel>();

            foreach (var patch in patches)
            {
                model.Add(PatchModelHelper.ConvertTo(patch));
            }

            return(View("Patches", model));
        }
Beispiel #6
0
        public ActionResult Edit(long id)
        {
            if (id <= 0)
            {
                return(View("PatchEdit", new PatchModel()));
            }


            PatchManager patchManager = new PatchManager();

            var patch = patchManager.Get(id);

            var model = PatchModelHelper.ConvertTo(patch);

            return(View("PatchEdit", model));
        }
Beispiel #7
0
        public JsonResult Save(List <PlacementJsonModel> placements)
        {
            long patchId = placements.First().PatchId;

            PatchManager patchManager = new PatchManager();
            Patch        patch        = patchManager.Get(patchId);


            //delete
            var x = new List <PatchElement>();

            foreach (var pe in patch.PatchElements)
            {
                if (!placements.Any(p => p.Id.Equals(pe.Id)))
                {
                    x.Add(pe);
                }
            }

            foreach (var e in x)
            {
                patch.PatchElements.Remove(e);
            }


            // add or update
            foreach (var placementJson in placements)
            {
                if (placementJson.Id == 0)
                {
                    patch.PatchElements.Add(PatchModelHelper.ConvertTo(placementJson));
                }
                else
                {
                    var pe = patch.PatchElements.FirstOrDefault(p => p.Id.Equals(placementJson.Id));
                    pe.Transformation = placementJson.Transformation;
                }
            }

            patchManager.Update(patch);

            //check deleted

            return(Json(true));
        }
Beispiel #8
0
        // GET: Patch
        public ActionResult Index(long id, bool reset = true)
        {
            PatchPlanerModel model = new PatchPlanerModel();

            #region create patch Model
            //get patch from db;
            PatchManager patchManager = new PatchManager();
            Patch        p            = patchManager.Get(id);
            PatchModel   patchModel   = PatchModelHelper.ConvertTo(p);

            #endregion

            #region create model for search

            getAllNames();

            if (reset)
            {
                ResetSearchProvider();
            }

            SearchProvider sp             = GetSearchProvider();
            SubjectManager subjectManager = new SubjectManager();

            SearchModel   searchModel   = new SearchModel();
            SearchManager searchManager = new SearchManager();

            var plants = searchManager.SearchPlants(sp.SearchCriterias);
            if (plants != null)
            {
                //convert all subjects to subjectModels
                plants = plants.OrderBy(s => s.Name);
                plants.ToList().ForEach(s => searchModel.Plants.Add(PlantModel.Convert(s)));
            }

            searchModel.SearchCriterias = sp.SearchCriterias;

            #endregion

            model.Patch  = patchModel;
            model.Search = searchModel;

            return(View(model));
        }