public async Task <ActionResult> Create([Bind(Include = "S_Id,SchoolName,Address,ContactNo,AltContactNo,FaxNo,Email,Website,Logo,RegistrationNo,DiseNo,IndexNo,EstablishedYear,Class,SchoolType")] SchoolInfo schoolInfo) { if (ModelState.IsValid) { db.SchoolInfoes.Add(schoolInfo); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.SchoolType = new SelectList(db.SchoolTypes, "Type", "Type", schoolInfo.SchoolType); return(View(schoolInfo)); }
public async Task <ActionResult> Create([Bind(Include = "RoleId,RoleName,Description")] Role role) { var name = db.Users.ToList().Where(a => a.Email == WebSecurity.CurrentUserName); string username = ""; foreach (var p in name) { username = p.Username; } if (ModelState.IsValid) { db.Roles.Add(role); await db.SaveChangesAsync(username); System.Web.HttpContext.Current.Session["NOT"] = "You have successfully added the Role"; return(RedirectToAction("Index")); } return(View(role)); }
public async Task <ActionResult> Create([Bind(Include = "ModulesID,ModulesName,RoleID,glyphicon,ControllerName,ViewName,Name,IsWebForm,webFormUrl,MenuRank")] Module modules) { var name = db.Users.ToList().Where(a => a.Email == WebSecurity.CurrentUserName); string username = ""; foreach (var p in name) { username = p.Username; } if (ModelState.IsValid) { db.Modules.Add(modules); await db.SaveChangesAsync(username); System.Web.HttpContext.Current.Session["NOT"] = "You have successfully added the Module"; return(RedirectToAction("Index")); } ViewBag.RoleID = new SelectList(db.Roles, "RoleId", "RoleName", modules.RoleID); var list4 = db.glyphicons.ToList(); //Create List of SelectListItem List <SelectListItem> selectlist4 = new List <SelectListItem>(); selectlist4.Add(new SelectListItem() { Text = "", Value = "" }); foreach (var row in list4) { //Adding every record to list selectlist4.Add(new SelectListItem { Text = row.glyphiconname, Value = row.glyphiconname.ToString() }); } ViewBag.Dlyp = selectlist4; return(View(modules)); }
public async Task <ActionResult> Edit([Bind(Include = "UserId,Username,Email,Password,ConfirmPassword,FirstName,LastName,IsActive,LockCount,CreateDate,role,BrokerName,BrokerCode")] User user) { var name = db.Users.ToList().Where(a => a.Email == WebSecurity.CurrentUserName); string username = ""; foreach (var p in name) { username = p.Username; } string name3 = WebSecurity.CurrentUserName; var userw = db.Users.ToList().Where(a => a.Email == name3); int? myid = 0; string names = ""; foreach (var row in userw) { myid = row.UserId; names = row.Username; } int check = db.Users.ToList().Where(a => a.Email == user.Email && a.UserId != user.UserId).Count(); if (ModelState.IsValid) { //db.Entry(user).State = EntityState.Modified; db.Users.AddOrUpdate(user); await db.SaveChangesAsync(names); System.Web.HttpContext.Current.Session["NOT"] = "You have successfully updated the user"; //updateuserroles //var roles = db.Roles.ToList().Where(a => a.RoleName == user.role); //int role = 0; //foreach (var c in roles) //{ // role = c.RoleId; //} //openconn(); //sql = "Update UserRoles set RoleId='" + role + "' where UserId='" + user.UserId + "'"; //cmd = new System.Data.SqlClient.SqlCommand(sql, conn); //cmd.ExecuteNonQuery(); //closeconn(); return(RedirectToAction("Index")); } string name2 = WebSecurity.CurrentUserName; var user2 = db.Users.ToList().Where(a => a.Email == name2); ViewBag.Users = ""; foreach (var row in user2) { ViewBag.Users = row.FirstName + " " + row.LastName; } if (check >= 1) { var mod = ModelState.First(c => c.Key == "Email"); // this mod.Value.Errors.Add("Duplicate emails are not allowed"); } ////Create List of SelectListItem List <SelectListItem> selectlist2 = new List <SelectListItem>(); selectlist2.Add(new SelectListItem() { Text = user.BrokerName, Value = user.BrokerName }); ViewBag.Sell = selectlist2; return(View(user)); }
public async Task <ActionResult> Create([Bind(Include = "UserId,Username,Email,Password,ConfirmPassword,FirstName,LastName,IsActive,LockCount,CreateDate,role,BrokerName,BrokerCode")] User user) { var name = db.Users.ToList().Where(a => a.Email == WebSecurity.CurrentUserName); string username = ""; foreach (var p in name) { username = p.Username; } var list3 = db.Roles.ToList(); //Create List of SelectListItem List <SelectListItem> selectlist = new List <SelectListItem>(); selectlist.Add(new SelectListItem() { Text = "", Value = "" }); foreach (var row in list3) { //Adding every record to list selectlist.Add(new SelectListItem { Text = row.RoleName, Value = row.RoleName.ToString() }); } ViewBag.Role = selectlist; int check = db.Users.ToList().Where(a => a.Email == user.Email).Count(); if (check >= 1) { var mod = ModelState.First(c => c.Key == "Email"); // this mod.Value.Errors.Add("Duplicate emails are not allowed"); } string h = ""; if (user.BrokerCode == "") { user.BrokerCode = "MORCO"; user.BrokerName = "Dry Associates"; } if (ModelState.IsValid && check < 1) { string name4 = WebSecurity.CurrentUserName; var userw = db.Users.ToList().Where(a => a.Email == name4); int? myid = 0; string names = ""; foreach (var row in userw) { myid = row.UserId; names = row.Username; } if (Request["role"] != "") { //Role role = new Role {RoleName = Request["Roles"] }; string fullname = Request["role"]; var role = db.Roles.ToList().Where(a => a.RoleName == fullname); //sql query user.Password = Request["Password"].ToString(); user.ConfirmPassword = Request["ConfirmPassword"].ToString(); user.Password = ComputeHash(user.Password, new SHA256CryptoServiceProvider()); user.ConfirmPassword = ComputeHash(user.ConfirmPassword, new SHA256CryptoServiceProvider()); user.CreateDate = DateTime.Now; user.LockCount = 0; user.role = Request["role"].ToString(); if (user.BrokerCode == null) { user.BrokerCode = "MORCO"; user.BrokerName = "Dry Associates"; } db.Users.Add(user); await db.SaveChangesAsync(names); System.Web.HttpContext.Current.Session["NOT"] = "You have successfully added the user"; int roleid = 0; int userid = 0; foreach (var row in role) { roleid = row.RoleId; } int user2 = db.Users.Max(a => a.UserId); userid = user2; string cs = ConfigurationManager.ConnectionStrings["SBoardConnection"].ConnectionString; using (SqlConnection cn = new SqlConnection(cs)) { string sql = "INSERT INTO UserRoles (UserId,RoleId) VALUES (@UserId,@RoleId)"; SqlCommand cmd = new SqlCommand(sql); cmd.CommandType = CommandType.Text; cmd.Connection = cn; cmd.Parameters.AddWithValue("@UserId", userid); cmd.Parameters.AddWithValue("@RoleId", roleid); cn.Open(); try { cmd.ExecuteNonQuery(); cn.Close(); } catch (Exception) { throw; } } // user.Roles.Add(role); } return(RedirectToAction("Index")); } else { } string name2 = WebSecurity.CurrentUserName; var user3 = db.Users.ToList().Where(a => a.Email == name2); ViewBag.Users = ""; foreach (var row in user3) { ViewBag.Users = row.FirstName + " " + row.LastName; } ////Create List of SelectListItem List <SelectListItem> selectlist2 = new List <SelectListItem>(); selectlist2.Add(new SelectListItem() { Text = user.BrokerName, Value = user.BrokerName }); return(View(user)); }