public ActionResult AddForm(Form form) { using (FormDbEntities db = new FormDbEntities()) { UsersEntities userDb = new UsersEntities(); Form newForm = new Form(); int userId = userDb.Users.FirstOrDefault(x => x.username == System.Web.HttpContext.Current.User.Identity.Name).Id; if (form.name != null && form.formUserName != null && form.formUserSurname != null) { newForm.Id = form.Id; newForm.name = form.name; newForm.description = form.description; newForm.createdAt = DateTime.Now; newForm.createdBy = Convert.ToInt32(userId); newForm.fields = form.fields; newForm.formUserName = form.formUserName; newForm.formUserSurname = form.formUserSurname; newForm.formUserAge = form.formUserAge; db.Form.Add(newForm); db.SaveChanges(); return(RedirectToAction("List")); } else { return(RedirectToAction("List")); } } }
public static List<Role> GetAll() { using(UsersEntities context = new UsersEntities()) { return context.Roles.Include(x => x.Users).ToList(); } }
private void check_Click(object sender, RoutedEventArgs e) { using (StreamReader sr = new StreamReader("../../../Reading/ReadingAnswers" + VarNum + "_" + j + ".txt")) { for (int i = 0; i < answerBoxes.Length; i++) { R_answers[i] = sr.ReadLine(); } } UsersEntities db = new UsersEntities(); for (int i = 0; i < answerBoxes.Length; i++) { string U_answer = answerBoxes[i].Text; if (U_answer == R_answers[i]) { answerBoxes[i].Background = Brushes.Green; } else { answerBoxes[i].Background = Brushes.Red; } } show.Visibility = Visibility.Visible; }
public bool Delete(int id) { try { //using (SqlConnection con = new SqlConnection(connectionString)) //{ // SqlCommand cmd = new SqlCommand("deleteEmployee", con); // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@EmpId", id); // con.Open(); // cmd.ExecuteNonQuery(); // con.Close(); // return true; // //return Request.CreateResponse(HttpStatusCode.OK ,"Record Deleted successfully"); //} using (var context = new UsersEntities()) { var emp = context.Employee.FirstOrDefault(e => e.EmpId == id); context.Employee.Remove(emp); context.SaveChanges(); return(true); } } catch (Exception error) { return(false); //return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error); } }
public static List <User> GetByRole(int roleID) { using (UsersEntities context = new UsersEntities()) { return(context.Users.Include(x => x.Roles).Include(x => x.Addresses).Where(x => x.Roles.Select(y => y.ID).Contains(roleID)).ToList()); } }
public static List<User> GetAll() { using (UsersEntities context = new UsersEntities()) { return context.Users.Include(x => x.Roles).Include(x => x.Addresses).ToList(); } }
public static List<User> GetByRole(int roleID) { using (UsersEntities context = new UsersEntities()) { return context.Users.Include(x => x.Roles).Include(x => x.Addresses).Where(x => x.Roles.Select(y => y.ID).Contains(roleID)).ToList(); } }
//public string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; //public List<EmployeeModal> getData() //{ // List<EmployeeModal> employeeList = new List<EmployeeModal>(); // using (SqlConnection conn = new SqlConnection(connectionString)) // { // string query = "select * from [dbo].[Employee]"; // conn.Open(); // using (SqlCommand command = new SqlCommand(query, conn)) // { // SqlDataReader reader = command.ExecuteReader(); // while (reader.Read()) // { // EmployeeModal emp = new EmployeeModal(); // emp.EmpId = Convert.ToInt32(reader.GetValue(0).ToString()); // emp.EmpName = reader.GetValue(1).ToString(); // emp.Email = reader.GetValue(2).ToString(); // emp.Salary = Convert.ToInt32(reader.GetValue(3).ToString()); // employeeList.Add(emp); // } // } // } // return employeeList; //} //[System.Web.Mvc.HttpGet] public async Task <List <Employee> > Get() { List <Employee> employeeList = new List <Employee>(); //using (SqlConnection conn = new SqlConnection(connectionString)) //{ // string query = "select * from [dbo].[Employee]"; // conn.Open(); // using (SqlCommand command = new SqlCommand(query, conn)) // { // SqlDataReader reader = command.ExecuteReader(); // while (reader.Read()) // { // EmployeeModal emp = new EmployeeModal(); // emp.EmpId = Convert.ToInt32(reader.GetValue(0).ToString()); // emp.EmpName = reader.GetValue(1).ToString(); // emp.Email = reader.GetValue(2).ToString(); // emp.Salary = Convert.ToInt32(reader.GetValue(3).ToString()); // employeeList.Add(emp); // } // } //} using (var context = new UsersEntities()) { employeeList = await context.Employee.ToListAsync(); } return(employeeList); //return Request.CreateResponse(HttpStatusCode.OK,employeeList); }
public Employee Get(int id) { Employee emp = new Employee(); //using (SqlConnection con = new SqlConnection(connectionString)) //{ // con.Open(); // SqlCommand cmd = new SqlCommand("Select * from Employee where EmpId=" + id, con); // cmd.Parameters.AddWithValue("@id", emp.EmpId); // SqlDataReader reader = cmd.ExecuteReader(); // while (reader.Read()) // { // emp.EmpId = Convert.ToInt32(reader.GetValue(0).ToString()); // emp.EmpName = reader.GetValue(1).ToString(); // emp.Email = reader.GetValue(2).ToString(); // emp.Salary = Convert.ToInt32(reader.GetValue(0).ToString()); // } // return emp; //} using (var context = new UsersEntities()) { var employ = context.Employee.FirstOrDefault(e => e.EmpId == id); emp = (Employee)employ; } return(emp); }
public async Task <HttpResponseMessage> Register([FromBody] User user) { try { using (var users = new UsersEntities()) { var encryptedUser = new User { EmailOrPhone = user.EmailOrPhone, Name = user.Name, Password = Encrypt.EncryptPassword(user.Password) }; users.Users.Add(encryptedUser); await users.SaveChangesAsync(); var message = Request.CreateResponse(HttpStatusCode.Created, encryptedUser); message.Headers.Location = new Uri(Request.RequestUri + user.Id.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public static User GetByID(int id) { using (UsersEntities context = new UsersEntities()) { return(context.Users.Include(x => x.Roles).Include(x => x.Addresses).Where(x => x.ID == id).First()); } }
public static Role GetByID(int id) { using (UsersEntities context = new UsersEntities()) { return context.Roles.Include(x => x.Users).Where(x=>x.ID == id).First(); } }
public ActionResult DevBlogPageFlip(int pageNum) { UsersEntities db = new UsersEntities(); List <UserTable> EmailList = db.UserTables.ToList(); List <EmailMember> EmailMemberPass = new List <EmailMember>(); if (EmailList[pageNum] != null) { for (int i = 0; i < 3; i++) { if (EmailList[pageNum + i] != null) { EmailMember temp = new EmailMember(); temp.Email = EmailList[pageNum + i].Email; temp.ID = EmailList[pageNum + i].ID; EmailMemberPass.Add(temp); } else { break; } } } else { } ViewBag.page = pageNum; return(View(EmailMemberPass)); }
public ActionResult DevBlog() { UsersEntities db = new UsersEntities(); List <Post> EmailList = db.Posts.ToList(); List <PostModel> EmailPostPass = new List <PostModel>(); if (EmailList.Count > 0) { if (EmailList[0] != null) { for (int i = 0; i < 3; i++) { if (EmailList[i] != null) { PostModel temp = new PostModel(); temp.Post1 = EmailList[i].Post1; temp.Id = EmailList[i].Id; EmailPostPass.Add(temp); } else { break; } } } else { } } return(View(EmailPostPass)); }
public async Task <HttpResponseMessage> CurrentUserCredentials([FromUri] int id) { using (var users = new UsersEntities()) { return(Request.CreateResponse(HttpStatusCode.OK, await users.Users.FindAsync(id))); } }
private bool Login(string username, string password) { using (var users = new UsersEntities()) { return(users.Users.Any(x => x.EmailOrPhone.Equals(username) && x.Password.Equals(password))); } }
//get all users public static List <UsersEntities> GetAllUsersList() { List <Users> lu = DB.Users.ToList(); return(UsersEntities.convertListUsersTblToListUsersEntities(lu)); }
public static List <Role> GetAll() { using (UsersEntities context = new UsersEntities()) { return(context.Roles.Include(x => x.Users).ToList()); } }
public static List <User> GetAll() { using (UsersEntities context = new UsersEntities()) { return(context.Users.Include(x => x.Roles).Include(x => x.Addresses).ToList()); } }
static void Main() { using (UsersEntities usersDb = new UsersEntities()) { using (TransactionScope scope = new TransactionScope()) { bool haveAdminGroup = usersDb.Groups.Where(x => x.GroupName == "Admins").ToList().Count > 0; if (!haveAdminGroup) { Group admins = new Group { GroupName = "Admins" }; usersDb.Groups.Add(admins); usersDb.SaveChanges(); } int adminsId = usersDb.Groups.Where(x => x.GroupName == "Admins").First().GroupId; User user = new User { UserName = "******", GroupId = adminsId }; usersDb.Users.Add(user); usersDb.SaveChanges(); scope.Complete(); } } }
public ActionResult GetUserList() { using (UsersEntities db = new UsersEntities()) { List <UserAccount> user = db.UserAccounts.ToList <UserAccount>(); return(Json(new { data = user }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// /// </summary> /// <returns></returns> /// public ActionResult PartialView() { using(UsersEntities u=new UsersEntities()) { var v = u.cars.OrderBy(a => a.Id).ToList(); return PartialView("_partialView", v); } }
public static void Edit(int id, string name) { using (UsersEntities context = new UsersEntities()) { Role role = context.Roles.Find(id); role.Name = name; context.SaveChanges(); } }
public ActionResult Edit(Int64?id) { var userentities = new UsersEntities(); var user = userentities.Users.Find(id); UsersViewModel objuser = new UsersViewModel(); objuser.UserEmail = user.UserEmail; objuser.UserName = user.UserName; objuser.UserId = user.UserId; return(View(objuser)); }
public ActionResult Edit(UsersViewModel objuser) { using (var user = new UsersEntities()) { var oneuser = user.Users.Find(objuser.UserId); oneuser.UserEmail = objuser.UserEmail; oneuser.UserName = objuser.UserName; user.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Delete(UsersViewModel objuser) { using (var user = new UsersEntities()) { var oneuser = user.People.Find(objuser.UserId); user.People.Attach(oneuser); user.Entry(oneuser).State = System.Data.EntityState.Deleted; user.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Details(Int64?id) { UsersViewModel objuser = new UsersViewModel(); using (var user = new UsersEntities()) { var oneuser = user.Users.Find(id); objuser.UserName = oneuser.UserName; objuser.UserEmail = oneuser.UserEmail; } return(View(objuser)); }
//add user public static void addUser(UsersEntities user, Car_DetailsEntities car) { if (user != null) { Users newUser = UsersEntities.convertUserEntitiesToUserTbl(user); // Car_Details newCar = Car_DetailsEntities.convertCarDetailsEntitiestoCarDetailsTbl(car); DB.Users.Add(newUser); // DB.Car_Details.Add(newCar); } }
/// <summary> /// 可以根据需要设置相应的Claim /// </summary> /// <returns></returns> private Claim[] GetUserClaims(UsersEntities model) { return(new Claim[] { new Claim("UserId", model.Id.ToString()), new Claim(JwtClaimTypes.Name, model.UserName), new Claim(JwtClaimTypes.GivenName, model.UserName), new Claim(JwtClaimTypes.FamilyName, model.UserName), new Claim(JwtClaimTypes.PhoneNumber, model.Mobile), new Claim(JwtClaimTypes.Role, "Company")//用户角色 }); }
public ActionResult Index(User user) { if (Session["UserID"] == null) { try { using (UsersEntities ue = new UsersEntities()) { var usr = ue.Users.Where(x => x.Username == user.Username).FirstOrDefault(); if (usr != null) { var hashCode = usr.VCode; var encodingPasswordString = Helper.EncodePassword(user.Password, hashCode); var usr2 = ue.Users.Where(x => x.Username == user.Username && usr.Password.Equals(encodingPasswordString)).FirstOrDefault(); if (usr2 != null) { Session["UserID"] = usr2.Id.ToString(); Session["Username"] = usr2.Username.ToString(); if (usr2.Role == true) { return(RedirectToAction("DodajUtakmicu", "Admin")); } else { return(RedirectToAction("Index", "Home")); } } else { ViewBag.UnsuccessfulMessage = "Unijeli ste krivu lozinku"; return(PartialView()); } } else { ViewBag.UnsuccessfulMessage = "Unijeli ste krivo korisničko ime"; return(PartialView()); } } } catch (Exception e) { ViewBag.ErrorMessage = " Error!!!"; return(PartialView()); } } else { ViewBag.UnsuccessfulMessage = "Drugi korisnik je ulogiran, zatvorite trenutnu sesiju ili koristite drugi preglednik"; return(PartialView()); } }
public ActionResult Create(UsersViewModel objuser) { var User = new Person { Birthdate = objuser.Birthdate, MartialStatus = objuser.MartialStatus, Phone = objuser.Phone, Birthplace = objuser.Birthplace, Employed = objuser.Employed, Gender = objuser.Gender, FirstName = objuser.FirstName, LastName = objuser.LastName }; using (var user = new UsersEntities()) { user.People.Add(User); user.SaveChanges(); } return(RedirectToAction("Index")); }
public static void Add(string name) { using(UsersEntities context = new UsersEntities()) { Role role = new Role() { Name = name }; context.Roles.Add(role); context.SaveChanges(); } }
public static void Add(string name) { using (UsersEntities context = new UsersEntities()) { Role role = new Role() { Name = name }; context.Roles.Add(role); context.SaveChanges(); } }
public ActionResult Create(UsersViewModel objuser) { var User = new User { UserName = objuser.UserName, UserEmail = objuser.UserEmail }; using (var user = new UsersEntities()) { user.Users.Add(User); user.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index() { using (var user = new UsersEntities()) { var users = user.Users.ToList().Select(x => new UsersViewModel { UserName = x.UserName, UserEmail = x.UserEmail, UserId = x.UserId }); return(View(users)); } }
//function that check if user is exists public static Boolean ExistUser(UsersEntities user) { Users u = UsersEntities.convertUserEntitiesToUserTbl(user); if (DB.Users.Any(x => x.Mail == u.Mail)) //when exists user { return(false); } return(true); }
public static void Edit(int userID, string firstName, string middleInitial, string lastName, DateTime dateOfBirth, string userName, bool isAdmin, List<int> roles) { using(UsersEntities context = new UsersEntities()) { var user = context.Users.Find(userID); user.FirstName = firstName; user.MiddleInitial = middleInitial; user.LastName = lastName; user.DateOfBirth = dateOfBirth; user.UserName = userName; user.IsAdmin = isAdmin; user.Roles = context.Roles.Where(x => roles.Contains(x.ID)).ToList(); context.SaveChanges(); } }
public static void Add(string firstName, string middleInitial, string lastName, DateTime dateOfBirth, string userName, bool isAdmin, List<int> roles) { using(UsersEntities context = new UsersEntities()) { User user = new User() { FirstName = firstName, MiddleInitial = middleInitial, LastName = lastName, DateOfBirth = dateOfBirth, UserName = userName, IsAdmin = isAdmin, Roles = context.Roles.Where(x=>roles.Contains(x.ID)).ToList() }; context.Users.Add(user); context.SaveChanges(); } }
private void check_Click(object sender, RoutedEventArgs e) { using (StreamReader sr = new StreamReader("../../../Reading/ReadingAnswers" + VarNum + "_" + j + ".txt")) { for (int i = 0; i < answerBoxes.Length; i++) R_answers[i] = sr.ReadLine(); } UsersEntities db = new UsersEntities(); for (int i = 0; i < answerBoxes.Length; i++) { string U_answer = answerBoxes[i].Text; if (U_answer == R_answers[i]) { answerBoxes[i].Background = Brushes.Green; } else answerBoxes[i].Background = Brushes.Red; } show.Visibility = Visibility.Visible; }