public ActionResult Login() { if (Session["OpenId"] == null) return View("Logon"); string openId = Session["OpenId"].ToString(); if (string.IsNullOrEmpty(openId)) return View("Logon"); // Normalise it openId = openId.ToLower(); // Find it, and add the user if they don't exist FlabberUser user = FlabberUser.Repository.First("@OpenId", openId); string name = "No name set"; if (user == null) { user = new FlabberUser(); user.Id = Guid.NewGuid(); user.OpenId = openId; user.Name = name; FlabberUser.Repository.SaveOrUpdate(user); } else { name = user.Name; } Session["LoginName"] = name; return View("Index"); }
public ActionResult AutoComplete(string q, int?limit) { FlabberUser user = FlabberContext.CurrentUser; if (user == null) { return(Content("")); } List <FoodItem> list = FoodItem.Repository.ForUser(user); return(Content(list.AutoCompleteList(q))); }
public ActionResult AddEntry(string date, string title, float calories) { FlabberUser user = FlabberContext.CurrentUser; if (user == null) { return(RedirectToAction("Index", "Home")); } // Get the date. Force to UTC. DateTime userDate = DateTime.Parse(date); userDate = DateTime.SpecifyKind(userDate, DateTimeKind.Local); // Add the entry FoodEntry entry = new FoodEntry(); entry.Calories = calories; entry.Title = title; entry.Date = userDate; entry.User = user; entry.Id = Guid.NewGuid(); FoodEntry.Repository.SaveOrUpdate(entry); // Add to the autocomplete list title = title.Trim(); FoodItem item = FoodItem.Repository.First("@Title", title); if (item == null) { item = new FoodItem(); item.Title = title; item.User = user; item.Brand = "Notset"; item.Calories = calories; item.Id = Guid.NewGuid(); FoodItem.Repository.SaveOrUpdate(item); // Update the cache if it exists string cacheKey = string.Format("FoodItems{0}", user.Id); if (HttpContext.Cache[cacheKey] != null) { List <FoodItem> list = (List <FoodItem>)HttpContext.Cache[cacheKey]; list.Add(item); HttpContext.Cache[cacheKey] = list; } } return(RedirectToAction("Index", "Food")); }
public ActionResult Delete(Guid id) { FlabberUser user = FlabberContext.CurrentUser; if (user == null) { return(RedirectToAction("Index", "Home")); } if (id != Guid.Empty) { FoodEntry entry = FoodEntry.Repository.Read(id); FoodEntry.Repository.Delete(entry); } return(RedirectToAction("Index", "Food")); }
public ActionResult Login() { if (Session["OpenId"] == null) { return(View("Logon")); } string openId = Session["OpenId"].ToString(); if (string.IsNullOrEmpty(openId)) { return(View("Logon")); } // Normalise it openId = openId.ToLower(); // Find it, and add the user if they don't exist FlabberUser user = FlabberUser.Repository.First("@OpenId", openId); string name = "No name set"; if (user == null) { user = new FlabberUser(); user.Id = Guid.NewGuid(); user.OpenId = openId; user.Name = name; FlabberUser.Repository.SaveOrUpdate(user); } else { name = user.Name; } Session["LoginName"] = name; return(View("Index")); }
public ActionResult Wipe() { FlabberUser.Configure(FlabberApplication.ConnectionString, true); return(RedirectToAction("Index")); }
protected void Application_Start() { FlabberUser.Configure(ConnectionString, true); RegisterRoutes(RouteTable.Routes); }