public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model) { string lLoginCookie = new Tuple<object, object>(model.AuthenticatedClient.GetHashCode(), DateTime.Now.GetHashCode()).GetHashCode().ToString(); using (umfrageDB db = new umfrageDB()) { string lAuthHash = MD5.Create() .ComputeHash(Encoding.UTF8.GetBytes(model.AuthenticatedClient.UserInformation.Id)) .ToHex(false); if ((from p in db.users where p.AuthenticationId == lAuthHash select p).Any()) { db.users.Where(user => user.AuthenticationId == lAuthHash) .Set(user => user.Guid, lLoginCookie).Set(user => user.LastLogin, DateTime.Now) .Update(); } else { user lUser = new user { AuthenticationId = lAuthHash, Guid = lLoginCookie, TimeCreated = DateTime.Now, LastLogin = DateTime.Now }; db.Insert(lUser); } } return nancyModule.Response.AsRedirect("/").WithCookie("id", lLoginCookie); }
private bool CheckIfCanAnswer(int frageId, user user) { using (umfrageDB db = new umfrageDB()) { if (!(from frage in db.questions where frage.Id == frageId select frage).Any()) return false; IQueryable<answer> lFragenLogs = from fragenLog in db.answers where fragenLog.UserId == user.AuthenticationId && fragenLog.FrageId == frageId select fragenLog; if (lFragenLogs.Any()) return false; } return true; }