Ejemplo n.º 1
0
        public ActionResult GroupLeaderboard()
        {
            List<Group> groups = new List<Group>();
            var model = new Group
            {
                name = "Centre for Social Innovation",
                points = 100
            };
            groups.Add(model);

            model = new Group
            {
                name = "GameChangersTO",
                points = 50
            };
            groups.Add(model);

            model = new Group
            {
                name = "Random Hacks of Kindness",
                points = 300
            };
            groups.Add(model);

            model = new Group
            {
                name = "Hackernest",
                points = 200
            };
            groups.Add(model);

            return Json(groups.OrderByDescending(i => i.points), JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 2
0
        public ActionResult Create(Update update, HttpPostedFileBase image)
        {
            Update lastUpdate = null;
            User updater = db.Retrieve<User>(new QueryDocument("email", update.email)).FirstOrDefault();
            Plant plant = db.Retrieve<Plant>(new QueryDocument("name", update.key)).FirstOrDefault(); // new Plant() { key = update.key };
            Group group = db.Retrieve<Group>(new QueryDocument("name", update.group)).FirstOrDefault(); // new Group() { name = update.group };

            update.photoid = db.SaveFile(image.FileName, image.InputStream);

            // check if update.key exists in plant collection
            if (plant == null)
            {
                // create plant
                plant = new Plant();
                plant.name = update.key;
                plant.group = update.group;
                plant.key = update.key;
                plant.latitude = update.latitude;
                plant.longitude = update.longitude;
                plant.photoid = update.photoid;
                plant.description = update.notes;

                try { db.Create<Plant>(plant); }
                catch (Exception ex) { return Json(ex); }
            }
            else
            {
                // pull last update
                /*lastUpdate = db.RetrieveSortedCollection<Update>(new QueryDocument("key", update.key)).Last();
                if (lastUpdate != null)
                {
                    // handle points delegation
                }*/

                // update plant photoid with update photoid
                plant.longitude = update.longitude;
                plant.latitude = update.latitude;
                plant.photoid = update.photoid;
                plant.description = plant.description + "\n\n" + update.notes;

                /*try { db.Update<Plant>(plant); }
                catch (Exception ex) { return Json(ex); }*/
            }

            // check if group exists in  group collection, if not create plant
            if (group == null)
            {
                // create group
                group = new Group();
                group.name = update.group;
                group.points = 50;
                try { db.Create<Group>(group); }
                catch (Exception ex) { return Json(ex); }

                // update user to add group
                updater.groups.Add(group.name);
            }
            else
            {
                // update group points
                group.points = group.points + 50;
                /*try { db.Update<Group>(group); }
                catch (Exception ex) { return Json(ex); }*/
            }

            // update user points
            updater.points = updater.points + 50;
            /*
            try { db.Update<User>(updater); }
            catch (Exception ex) { return Json(ex); }*/

            // create update
            try { db.Create<Update>(update); }
            catch (Exception ex) { return Json(ex); }

            return Redirect("http://m.oneplantperclass.org/feed");
        }