/// <summary> /// Create the specified model. /// </summary> /// <param name='model'> /// The user model. /// </param> public User Create(User model) { using (var session = Database.DocumentStore.OpenSession()) { session.Store(model); session.SaveChanges(); return model; } }
public ValidationModule() { Get ["/validation/user/validate-exists-username"] = x => { return Response.AsJson<bool>(true); }; Get ["/validation/user/validate-exists-email"] = x => { var user = new User(); var q = DeserializeQueryString(Request.Query["*"]); user.Username = q.Username; user.FirstName = q.FirstName; user.LastName = q.LastName; user.Email = q.Email; var result = new UserValidator().Validate(user, y => y.Email); if (result.IsValid) { return Response.AsJson<bool>(true); } return Response.AsJson<bool>(false); }; }
/// <summary> /// Delete the specified model. /// </summary> /// <param name='model'> /// If set to <c>true</c> model. /// </param> public bool Delete(User model) { using (var session = Database.DocumentStore.OpenSession()) { var user = session.Query<User>("UsersByUserName") .Where(n => n.UserName == model.UserName) .FirstOrDefault(); if (user == null) return false; session.Delete(user); session.SaveChanges(); return true; } }
/// <summary> /// Update the specified id and newT. /// </summary> /// <param name='id'> /// If set to <c>true</c> identifier. /// </param> /// <param name='newT'> /// If set to <c>true</c> new t. /// </param> public bool Update(string id, User newT) { using (var session = Database.DocumentStore.OpenSession()) { var saved = session.Query<User>("UsersByUserName") .Where(n => n.UserName == id) .FirstOrDefault(); if (saved == null) return false; saved.Fill(newT); session.SaveChanges(); return true; } }