public ActionResult Create([Bind(Include = "ID,UserName,Password,CourtID,FullName,RoleID,CreationDate,LastLoginDateTime,OfficeNumber,OfficeFloorNumber,OfficeName,IsActive,IsInworkToday,MaxQueueCount,Email,Phone,Mobile,LastUpdateDate,SocialID,ExtensionNumber,ActiveDirectoryUserName,olduserid,SubRoleID")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "ID,UserID,CorutOfficeID,RoleID,SupRoleID,UpdateAdminID,CreateDate,UpdateDate,isActive")] Users_Courts users_Courts) { if (ModelState.IsValid) { if (db.Users_Courts.Where(x => x.UserID == users_Courts.UserID && x.CorutOfficeID == users_Courts.CorutOfficeID && x.RoleID == users_Courts.RoleID).FirstOrDefault() == null) { users_Courts.CreateDate = DateTime.Now; users_Courts.UpdateDate = DateTime.Now; users_Courts.CreateAdminID = Convert.ToInt32(Session["UserID"]); users_Courts.UpdateAdminID = Convert.ToInt32(Session["UserID"]); if (users_Courts.RoleID.Equals(3)) { users_Courts.SupRoleID = 1; } db.Users_Courts.Add(users_Courts); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Message = "الربط موجود سابقاً"; } } ViewBag.CorutID = new SelectList(db.Courts, "CourtID", "CourtName"); ViewBag.CorutOfficeID = new SelectList(""); ViewBag.RoleID = new SelectList(db.Roles, "ID", "Name"); ViewBag.SupRoleID = new SelectList(db.SubRoles, "ID", "Name"); MOJEntities dbC = new MOJEntities(); List <object> newList = new List <object>(); foreach (var item in dbC.Users) { newList.Add(new { Id = item.ID, Name = item.FullName + " | " + item.SocialID }); } ViewBag.UserID = new SelectList(newList, "Id", "Name"); //ViewBag.UserID = new SelectList(db.Users, "ID", "UserName"); ViewBag.CreateAdminID = new SelectList(db.Users, "ID", "FullName"); ViewBag.UpdateAdminID = new SelectList(db.Users, "ID", "UserName"); return(View()); }