public static bool Authenticate(User user) { MongoDatabaseService db = null; User entity = null; bool authorized = false; if (!String.IsNullOrWhiteSpace(user.email) && !String.IsNullOrWhiteSpace(user.userid)) { db = new MongoDatabaseService(); entity = db.Retrieve<User>(new QueryDocument("userid", user.userid)).FirstOrDefault(); if (entity != null) { authorized = true; } else { // create user account if (db.Create<User>(user) != null) { authorized = true; } } } return authorized; }
public ActionResult Authenticate(User user) { bool authorized = OnePlant.Models.User.Authenticate(user); User result = null; if (authorized) { result = MongoDatabaseService.Retrieve<User>(new QueryDocument("email", user.email)).FirstOrDefault(); FormsAuthentication.SetAuthCookie(user.email, true); } return Json(new { success = authorized, user = result }); }
public ActionResult Delete(User user) { User existingUser = getUser(user.email); if (existingUser == null) { return Json(new ArgumentException()); } else { try { var deleted = MongoDatabaseService.Delete<User>(user.email); return Json(deleted); } catch (Exception emAll) { return Json(emAll); } } }
public ActionResult Create(User user) { User existingUser = getUser(user.email); if (existingUser == null) { //new user try { user = MongoDatabaseService.Create<User>(user); } catch (Exception emAll) { return Json(emAll); } } else { //user already exists user = existingUser; } return Json(user); }
public ActionResult PeopleLeaderboard() { List<User> people = new List<User>(); var model = new User { firstName = "Jack", lastName = "Matthews", points = 200 }; people.Add(model); model = new User { firstName = "Rob", lastName = "Johnson", points = 80 }; people.Add(model); model = new User { firstName = "Diveo", lastName = "Hawaii", points = 230 }; people.Add(model); model = new User { firstName = "Eric", lastName = "Cantona", points = 290 }; people.Add(model); return Json(people.OrderByDescending(i => i.points), JsonRequestBehavior.AllowGet); }
public ActionResult Update(User user) { try { bool updated = MongoDatabaseService.Update<User>(user); return Json(updated); } catch (Exception emAll) { return Json(emAll); } }