Esempio n. 1
0
        public ActionResult GardenDetail(int?id)
        {
            ActionResult viewResult = RedirectToAction("Index", "Garden");

            if (id.HasValue)
            {
                GardenDetailViewModel model = new GardenDetailViewModel()
                {
                    GardenID = id.Value
                };

                int userId = RetrieveUserId();

                GardenNeedsManager needsManager = new GardenNeedsManager(userId, id.Value);

                model.ActiveNeeds = needsManager.RetrieveActiveNeeds();

                ViewBag.GroupLeader = new GroupManager().
                                      GetLeaderStatus(
                    userId, new GardenManager().RetrieveGardenGroupId(id.Value)
                    );

                if (ViewBag.GroupLeader)
                {
                    model.PendingContributions = needsManager.RetrievePendingContributions();
                }

                model.CompletedNeeds = needsManager.RetrieveCompletedNeeds();

                viewResult = View(model);
            }

            return(viewResult);
        }
Esempio n. 2
0
        public ActionResult AddNeed(CreateNeedViewModel model)
        {
            ActionResult viewResult = View(model);

            if (ModelState.IsValid)
            {
                int userId = RetrieveUserId();

                GardenNeedsManager needsManager = new GardenNeedsManager(userId, model.GardenId);

                GardenNeed need = new GardenNeed()
                {
                    Title
                        = model.Title,
                    Description
                        = model.Description,
                };

                if (needsManager.AddNeed(need))
                {
                    viewResult = RedirectToAction("GardenDetail", new { id = model.GardenId });
                }
                else
                {
                    viewResult = View("Error"); // CHANGE
                }
            }

            return(viewResult);
        }
Esempio n. 3
0
        public ActionResult ViewGardenNeeds(int?id)
        {
            ActionResult view = View("Error");

            if (id.HasValue)
            {
                GardenNeedsDetailViewModel model = new GardenNeedsDetailViewModel();

                model.ActiveNeeds = GardenNeedsManager.RetrieveGardenNeeds(id.Value);

                if (null != model.ActiveNeeds)
                {
                    view = View(model);
                }
            }

            return(view);
        }
Esempio n. 4
0
        public ActionResult ViewGroupNeeds(int?id)
        {
            ActionResult view = View("Error");

            if (id.HasValue)
            {
                GroupNeedsDetailViewModel model = new GroupNeedsDetailViewModel();

                model.GardenSummaries = UserNeedsManager.RetrieveGroupGardensOfNeed(id.Value);

                if (null != model.GardenSummaries)
                {
                    model.ActiveNeeds = GardenNeedsManager.RetrieveGroupNeeds(id.Value);
                }

                if (null != model.ActiveNeeds || null != model.GardenSummaries)
                {
                    view = View(model);
                }
            }

            return(view);
        }