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 IHttpActionResult PuttUsersAudit(int id, tUsersAudit tUsersAudit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tUsersAudit.Id) { return(BadRequest()); } db.Entry(tUsersAudit).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tUsersAuditExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "Gender_Id,Gender1")] Gender gender) { if (ModelState.IsValid) { db.Genders.Add(gender); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gender)); }
public ActionResult Create([Bind(Include = "ID,FullName,Gender,PhoneNumber,Age,Adress,City,Country,Email,WebSite,Photo,AltTxt")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "Emp_Id,Full_Names,Gender_Id,Email")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Gender_Id = new SelectList(db.Genders, "Gender_Id", "Gender1", employee.Gender_Id); return(View(employee)); }
public ActionResult Create([Bind(Include = "Temp_Id,Emp_Id,Temperature1")] Temperature temperature) { if (ModelState.IsValid) { db.Temperatures.Add(temperature); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Emp_Id = new SelectList(db.Employees, "Emp_Id", "Full_Names", temperature.Emp_Id); return(View(temperature)); }
public ActionResult Create(Blog blog) { if (ModelState.IsValid) { db.Blogs.Add(blog); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.userId = new SelectList(db.Users, "uId", "username", blog.userId); return(View(blog)); }
public ActionResult Kladionica(User user) { if (Session["UserID"] != null) { User u = users.Users.Where(p => p.Id == user.Id).FirstOrDefault(); u.stanjeRacuna = user.stanjeRacuna; users.SaveChanges(); ViewBag.Users = users.Users.ToList(); return(PartialView(utakmice.Utakmice.ToList())); } else { return(RedirectToRoute("Login")); } }
//確認註冊資料 public ActionResult CheckRegister(Memb p) { string s1 = (string)Session["s1"]; string verification = (string)Session["verification"]; p.UsEmail = (string)Session["email"]; p.UsPassword = (string)Session["pwd"]; p.UsJnD = DateTime.Now; if (s1 == AesDecryptBase64(verification)) { db.Memb.Add(p); db.SaveChanges(); } Session.Clear(); return(RedirectToAction("Login")); }
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 ActionResult VioMesOK(int msid) { var p = db.Mes.Where(m => m.MsId == msid).FirstOrDefault(); var q = db.MesR.Where(m => m.MsId == msid).ToList(); p.MsRpt = false; foreach (var item in q) { item.MsCheck = true; } db.SaveChanges(); return(RedirectToAction("Violmes")); }
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 Form_Save(tbl_Users u) { if (ModelState.IsValid) { db.tbl_Users.Add(u); db.SaveChanges(); return(RedirectToAction("Display", u)); } return(PartialView()); }
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 void Col(Collection col, int stid) { int usid = (int)Session["result"]; var result = db.Collection.Where(m => m.StId == stid && m.UsId == usid).FirstOrDefault(); if (result == null) { col.UsId = usid; col.StId = stid; db.Collection.Add(col); db.SaveChanges(); } }
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 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 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 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 Registracija(User user) { if (user.Role == false) { user.stanjeRacuna = 500; using (UsersEntities ue = new UsersEntities()) { if (ue.Users.Any(x => x.Username == user.Username)) { ViewBag.DuplicateMessage = "Korisničko ime već postoji!"; return(PartialView()); } else { var keyNew = Helper.GeneratePassword(10); var password = Helper.EncodePassword(user.Password, keyNew); user.Password = password; user.VCode = keyNew; ue.Users.Add(user); ue.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Registracija uspješna"; return(PartialView()); } } } else { using (UsersEntities ue = new UsersEntities()) { if (ue.Users.Any(x => x.Username == user.Username)) { ViewBag.DuplicateMessage = "Korisničko ime već postoji!"; return(PartialView()); } else { var keyNew = Helper.GeneratePassword(10); var password = Helper.EncodePassword(user.Password, keyNew); user.Password = password; user.VCode = keyNew; ue.Users.Add(user); ue.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Registracija uspješna"; return(PartialView()); } } } }
public ActionResult Register(Demo_Registration U) { if (ModelState.IsValid) { using (UsersEntities dc = new UsersEntities()) { dc.Demo_Registration.Add(U); dc.SaveChanges(); ModelState.Clear(); U = null; ViewBag.Message = "Successfully Registration Done"; } } return(View(U)); }
private void DeleteUserTableRecords(Guid userId, UsersEntities context) { var user = context.UserDbs.SingleOrDefault(elem => elem.Id == userId); if (user != null) { context.UserDbs.Remove(user); context.SaveChanges(); user = context.UserDbs.SingleOrDefault(elem => elem.Id == userId); if (user != null) { throw new ApplicationException(string.Format("User with Id: {0} was not deleted from table", userId)); } } }
// [HttpPost] public ActionResult Form(string EmailId) { tbl_Users u = new tbl_Users() { SlNo = 1, UserName = "******", EmailId = "sajal@gmail", ConfirmPassword = "******", Password = "******" }; if (ModelState.IsValid) { db.tbl_Users.Add(u); db.SaveChanges(); return(RedirectToAction("Display")); } return(PartialView()); }
public bool Post([FromBody] Employee employee) { //try //{ // using (SqlConnection con = new SqlConnection(connectionString)) // { // con.Open(); // SqlCommand cmd = new SqlCommand("addEmployee", con); // cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.AddWithValue("@EmpId", employee.EmpId); // cmd.Parameters.AddWithValue("@EmpName", employee.EmpName); // cmd.Parameters.AddWithValue("@Email", employee.Email); // cmd.Parameters.AddWithValue("@Salary", employee.Salary); // cmd.ExecuteNonQuery(); // con.Close(); // } // var message = Request.CreateResponse(HttpStatusCode.Created, employee); // message.Headers.Location = new Uri(Request.RequestUri + employee.EmpId.ToString()); // return true; //} //catch (Exception error) //{ // //return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error); // return false; //} try { using (var context = new UsersEntities()) { context.Employee.Add(new Employee() { EmpId = employee.EmpId, EmpName = employee.EmpName, Email = employee.Email, Salary = employee.Salary }); context.SaveChanges(); } return(true); } catch (Exception error) { return(false); } }
private void DeleteConfirmationCodes(Guid userId, UsersEntities context) { var confirmationCodes = context.ConfirmationCodeDbs.Where(elem => elem.UserId == userId); foreach (var confirmationCode in confirmationCodes) { context.ConfirmationCodeDbs.Remove(confirmationCode); } context.SaveChanges(); var confCount = context.ConfirmationCodeDbs.Count(elem => elem.UserId == userId); if (confCount > 0) { throw new ApplicationException(string.Format("User with Id: {0} was not deleted from table", userId)); } }
private void DeleteExternalUserTableRecords(Guid userId, UsersEntities context) { var records = context.ExternalUserDbs.Where(elem => elem.UserId == userId); foreach (var record in records) { context.ExternalUserDbs.Remove(record); } context.SaveChanges(); var count = context.ExternalUserDbs.Count(elem => elem.UserId == userId); if (count > 0) { throw new ApplicationException(string.Format("User with Id: {0} was not deleted from table", userId)); } }
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(); } }
private void DeleteEmailUnsubscribeUrl(Guid userId, UsersEntities context) { var emailUnsubs = context.EmailUnsubscribeUrlDbs.Where(elem => elem.UserId == userId); foreach (var unsub in emailUnsubs) { context.EmailUnsubscribeUrlDbs.Remove(unsub); } context.SaveChanges(); var unsubCount = context.EmailUnsubscribeUrlDbs.Count(elem => elem.UserId == userId); if (unsubCount > 0) { throw new ApplicationException(string.Format("User with Id: {0} was not deleted from table", userId)); } }
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 ActionResult Create(User userModel) { using (UsersEntities dbModel = new UsersEntities()) { if (dbModel.Users.Any(x => x.username == userModel.username)) { ViewBag.DuplicateMessage = "Username Already exist"; return(View("Create", userModel)); } dbModel.Users.Add(userModel); dbModel.SaveChanges(); } ModelState.Clear(); ViewBag.SuccessMessage = "Registration successful"; return(View("Create", new User())); }
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(); } }