コード例 #1
0
 public bool AddUserAndAssingRole(UserRoleDTO userDTO)
 {
     using (var dbContextTransaction = LogicXDBContext.Database.BeginTransaction())
     {
         var flag = false;
         try
         {
             Users user = new Users();
             user.user_name            = userDTO.user_name;
             user.user_phone           = userDTO.user_phone;
             user.user_email           = userDTO.user_email;
             user.user_date_of_joining = userDTO.user_date_of_joining;
             user.password             = userDTO.password;
             user.comany_id            = userDTO.company_id;
             LogicXDBContext.Users.Add(user);
             LogicXDBContext.SaveChanges();
             User_Roles userRole = new User_Roles();
             userRole.role_id          = userDTO.role_id;
             userRole.user_id          = user.user_id;
             userRole.role_assign_date = DateTime.Now;
             LogicXDBContext.User_Roles.Add(userRole);
             LogicXDBContext.SaveChanges();
             dbContextTransaction.Commit();
             flag = true;
         }
         catch (Exception)
         {
             dbContextTransaction.Rollback();
             flag = false;
         }
         return(flag);
     }
 }
コード例 #2
0
        //Method to Insert User with Roles and Country Associations.
        public static Int32?InsertNewUser(UserModel User)
        {
            var ifuserexists = dbUserAdministration.CheckifUserExists(User.User511);

            List <LDAPUserModel> _ldapUserModel = new List <LDAPUserModel>();

            if (User.FirstName == null || User.LastName == null || User.Email == null || User.UPI == null)
            {
                _ldapUserModel = bsUserAdministration.GetUserInfo(User.User511.ToUpper(), User.UPI);
            }
            if (!ifuserexists)
            {
                User _userEntity = new User();
                _userEntity.User_511       = User.User511;
                _userEntity.First_Name     = User.FirstName != null ? User.FirstName : _ldapUserModel[0].FirstName;
                _userEntity.Last_Name      = User.LastName != null ? User.LastName : _ldapUserModel[0].LastName;
                _userEntity.Middle_Initial = User.MiddleInitial;
                _userEntity.Email_Id       = User.Email != null ? User.Email : _ldapUserModel[0].Email;
                _userEntity.UPI            = Convert.ToDecimal(User.UPI) != null?Convert.ToDecimal(User.UPI) : Convert.ToDecimal(_ldapUserModel[0].UPI);

                _userEntity.Is_Active    = User.IsActive;
                _userEntity.Created_Date = DateTime.Now;
                _userEntity.Created_By   = User.User511 == null ? AppConstants.CreatedBy : User.User511;
                var insertedUserID = dbUserAdministration.InsertNewUser(_userEntity);

                if (User.RoleIds != null)
                {
                    List <String> lstRolesId = User.RoleIds.Trim().Split(',').ToList();
                    for (int i = 0; i < lstRolesId.Count; i++)
                    {
                        User_Roles _userRoleEntity = new User_Roles();
                        _userRoleEntity.User_Id        = Convert.ToInt32(insertedUserID);
                        _userRoleEntity.Role_Master_Id = Convert.ToInt32(lstRolesId[i]);
                        _userRoleEntity.Is_Active      = true;
                        _userRoleEntity.Created_Date   = DateTime.Now;
                        _userRoleEntity.Created_By     = User.User511 == null ? AppConstants.CreatedBy : User.User511;
                        var status = dbUserAdministration.InsertUserRolesforUserID(_userRoleEntity);
                    }
                }

                if (User.CountryIds != null)
                {
                    List <String> lstCountryId = User.CountryIds.Trim().Split(',').ToList();
                    for (int i = 0; i < lstCountryId.Count; i++)
                    {
                        User_Country_Association _userCountryEntity = new User_Country_Association();
                        _userCountryEntity.User_Id           = Convert.ToInt32(insertedUserID);
                        _userCountryEntity.Country_Master_Id = Convert.ToInt32(lstCountryId[i]);
                        _userCountryEntity.Created_Date      = DateTime.Now;
                        _userCountryEntity.Created_By        = User.User511 == null ? AppConstants.CreatedBy : User.User511;
                        var status = dbUserAdministration.InsertUserCountryAssociation(_userCountryEntity);
                    }
                }
                return(1);
            }
            else
            {
                return(-1);
            }
        }
コード例 #3
0
        public ActionResult Users()
        {
            User_Roles model = new User_Roles
            {
                Users = db.Users.OrderBy(x => x.LastName).ToList(),

                Roles = new List <ListClass>
                {
                    new ListClass()
                    {
                        Id   = null,
                        Name = "Select ..."
                    }
                }
                .Concat(db.Roles.ToArray()
                        .Select(c => new ListClass
                {
                    Id   = c.Id,
                    Name = c.Name
                }).OrderBy(x => x.Name))
                .ToList(),
            };

            return(View(model));
        }
コード例 #4
0
        public ActionResult Index([Bind(Include = "authorized_person_email, authorized_person_password")] Authorized_Persons form_datas)
        {
            Authorized_Persons check_authorized_person = db.Authorized_Persons.Where(a => a.authorized_person_email == form_datas.authorized_person_email).FirstOrDefault();

            if (check_authorized_person == null)
            {
                ViewBag.LoginError = "Email düzgün daxil edilməyib!";
                return(View());
            }

            //Input'dan daxil edilən şifrəni VerifyPassword methodu ilə check edir. (Ətraflı: BaseController-Abstract.cs)
            if (!PasswordStorage.VerifyPassword(form_datas.authorized_person_password, check_authorized_person.authorized_person_password))
            {
                ViewBag.LoginError = "Şifrə düzgün daxil edilməyib!";
                return(View());
            }

            User_Roles role = db.User_Roles.Where(r => r.user_role_id == check_authorized_person.authorized_person_role_id).FirstOrDefault();

            //Normalda bu üsulla user authorization etmək düzgün deyil.
            //Lakin layihə üçün verilən vaxt müddəti az olduğundan dərinliyinə getmirəm.
            if (role.user_role_name == "Rektor" || role.user_role_name == "Prorektor" || role.user_role_name == "Rektor Müşaviri" || role.user_role_name == "Dekan" || role.user_role_name == "Kafedra Müdiri" || role.user_role_name == "Mərkəz Rəhbəri" || role.user_role_name == "Muzey Rəhbəri")
            {
                Session["Authorized_Person_Id"]       = check_authorized_person.authorized_person_id;
                Session["Authorized_Person_Email"]    = check_authorized_person.authorized_person_email;
                Session["Authorized_Person_Password"] = check_authorized_person.authorized_person_password;
                AreaName = "Admin";
            }

            return(RedirectToAction("Index", "Dashboard", new { Area = AreaName }));
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            User_Roles user_Roles = db.User_Roles.Find(id);

            db.User_Roles.Remove(user_Roles);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
 public User_RolesViewModel Get(int id)
 {
     using (UnitOfWork unitOfWork = new UnitOfWork())
     {
         User_Roles role = unitOfWork.RoleRepository.Get(id);
         return(Mapper.Map <User_Roles, User_RolesViewModel>(role));
     }
 }
コード例 #7
0
 public void DeleteRole(int id)
 {
     using (unitOfWork = new UnitOfWork())
     {
         User_Roles model = unitOfWork.RoleRepository.Get(id);
         unitOfWork.RoleRepository.Delete(model);
         unitOfWork.RoleRepository.Save();
     }
 }
コード例 #8
0
 public void EditRole(User_RolesViewModel model)
 {
     using (unitOfWork = new UnitOfWork())
     {
         User_Roles modelMapping = Mapper.Map <User_RolesViewModel, User_Roles>(model);
         unitOfWork.RoleRepository.Update(modelMapping);
         unitOfWork.RoleRepository.Save();
     }
 }
 public ActionResult Edit([Bind(Include = "user_role_id,user_role_name")] User_Roles user_Roles)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user_Roles).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user_Roles));
 }
        public ActionResult Create([Bind(Include = "user_role_id,user_role_name")] User_Roles user_Roles)
        {
            if (ModelState.IsValid)
            {
                db.User_Roles.Add(user_Roles);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user_Roles));
        }
コード例 #11
0
 public ActionResult Edit([Bind(Include = "id,user_id,role_id")] User_Roles user_Roles)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user_Roles).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.role_id = new SelectList(db.Role, "role_id", "role1", user_Roles.role_id);
     ViewBag.user_id = new SelectList(db.User, "user_id", "userName", user_Roles.user_id);
     return(View(user_Roles));
 }
コード例 #12
0
        // GET: User_Roles/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_Roles user_Roles = db.User_Roles.Find(id);

            if (user_Roles == null)
            {
                return(HttpNotFound());
            }
            return(View(user_Roles));
        }
コード例 #13
0
        // GET: User_Roles/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_Roles user_Roles = db.User_Roles.Find(id);

            if (user_Roles == null)
            {
                return(HttpNotFound());
            }
            ViewBag.role_id = new SelectList(db.Role, "role_id", "role1", user_Roles.role_id);
            ViewBag.user_id = new SelectList(db.User, "user_id", "userName", user_Roles.user_id);
            return(View(user_Roles));
        }
コード例 #14
0
 public static bool InsertUserRolesforUserID(User_Roles _userRole)
 {
     using (PJEntities _entity = new PJEntities())
     {
         try
         {
             _entity.User_Roles.Add(_userRole);
             _entity.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
コード例 #15
0
 public bool UpdateUserAndRole(int id, UserRoleDTO userDTO)
 {
     using (var dbContextTransaction = LogicXDBContext.Database.BeginTransaction())
     {
         var flag = false;
         try
         {
             var user = this.Get(id);
             if (user != null)
             {
                 user.user_name                    = userDTO.user_name;
                 user.user_phone                   = userDTO.user_phone;
                 user.user_email                   = userDTO.user_email;
                 user.user_date_of_joining         = userDTO.user_date_of_joining;
                 user.password                     = userDTO.password;
                 user.comany_id                    = userDTO.company_id;
                 LogicXDBContext.Entry(user).State = EntityState.Modified;
                 var oldUserRole = LogicXDBContext.User_Roles.Where(x => x.user_id == id).FirstOrDefault();
                 if (oldUserRole != null)
                 {
                     LogicXDBContext.Entry(oldUserRole).State = EntityState.Deleted;
                     User_Roles userRole = new User_Roles();
                     userRole.role_id          = userDTO.role_id;
                     userRole.user_id          = user.user_id;
                     userRole.role_assign_date = DateTime.Now;
                     LogicXDBContext.User_Roles.Add(userRole);
                 }
                 LogicXDBContext.SaveChanges();
                 dbContextTransaction.Commit();
                 flag = true;
             }
         }
         catch (Exception)
         {
             dbContextTransaction.Rollback();
             flag = false;
         }
         return(flag);
     }
 }
コード例 #16
0
        public async Task <bool> Register(User user, Roles role)
        {
            int rowCount = 0;

            using (var dbContext = _bookstoreDBContext)
            {
                var registerdUser = await dbContext.AddAsync(user);

                var registerdRole = await dbContext.Roles.FindAsync(role.Id);

                await dbContext.SaveChangesAsync();

                var user_roles = new User_Roles()
                {
                    UserId = user,
                    RoleId = registerdRole,
                };
                await dbContext.AddAsync(user_roles);

                rowCount = await dbContext.SaveChangesAsync();
            }
            return(rowCount > 0);
        }
コード例 #17
0
        //Method to Update User with Roles and Country Associations.
        public static Int32?UpdateExistingUser(UserModel User)
        {
            var userdetailsEntity = dbUserAdministration.GetUserforUserId(Convert.ToInt32(User.UserID));

            if (userdetailsEntity != null)
            {
                userdetailsEntity.First_Name     = User.FirstName;
                userdetailsEntity.Last_Name      = User.LastName;
                userdetailsEntity.Middle_Initial = User.MiddleInitial;
                userdetailsEntity.Email_Id       = User.Email;
                userdetailsEntity.UPI            = String.IsNullOrEmpty(User.UPI) ? 0 : Convert.ToDecimal(User.UPI);
                userdetailsEntity.Is_Active      = User.IsActive;
                userdetailsEntity.Modified_Date  = DateTime.Now;
                userdetailsEntity.Modified_By    = SessionHelper.LoggedinUser == null ? AppConstants.CreatedBy : SessionHelper.LoggedinUser.User511;
                var updatedUserID = dbUserAdministration.UpdateUserDetails(userdetailsEntity);

                var           existingRolesforUser = dbUserAdministration.GetUserRolesAssociation(Convert.ToInt32(User.UserID));
                List <String> lstRolesId           = User.RoleIds.Trim().Split(',').ToList();
                for (int i = 0; i < existingRolesforUser.Count; i++)
                {
                    if (!lstRolesId.Contains(existingRolesforUser[i].Role_Master_Id.ToString()))
                    {
                        var isRoleRemoved = dbUserAdministration.RemoveUserRolesAssocation(Convert.ToInt32(User.UserID), existingRolesforUser[i].Role_Master_Id);
                    }
                }
                for (int i = 0; i < lstRolesId.Count; i++)
                {
                    var isroleExists = existingRolesforUser.Where(x => x.Role_Master_Id == Convert.ToInt32(lstRolesId[i])).Any();
                    if (!isroleExists)
                    {
                        User_Roles _userRoleEntity = new User_Roles();
                        _userRoleEntity.User_Id        = Convert.ToInt32(updatedUserID);
                        _userRoleEntity.Role_Master_Id = Convert.ToInt32(lstRolesId[i]);
                        _userRoleEntity.Is_Active      = true;
                        _userRoleEntity.Created_Date   = DateTime.Now;
                        _userRoleEntity.Created_By     = SessionHelper.LoggedinUser == null ? AppConstants.CreatedBy : SessionHelper.LoggedinUser.User511;
                        var status = dbUserAdministration.InsertUserRolesforUserID(_userRoleEntity);
                    }
                }

                var existingCountriesforUser = dbUserAdministration.GetUserCountryAssociation(Convert.ToInt32(User.UserID));
                if (User.CountryIds != null)
                {
                    List <String> lstCountryId = User.CountryIds.Trim().Split(',').ToList();
                    for (int i = 0; i < existingCountriesforUser.Count; i++)
                    {
                        if (!lstCountryId.Contains(existingCountriesforUser[i].Country_Master_Id.ToString()))
                        {
                            var isCountryAssociationRemoved = dbUserAdministration.RemoveUserCountryAssocation(Convert.ToInt32(User.UserID), existingCountriesforUser[i].Country_Master_Id);
                        }
                    }
                    for (int i = 0; i < lstCountryId.Count; i++)
                    {
                        var isCountryExists = existingCountriesforUser.Where(x => x.Country_Master_Id == Convert.ToInt32(lstCountryId[i])).Any();
                        if (!isCountryExists)
                        {
                            User_Country_Association _userCountryEntity = new User_Country_Association();
                            _userCountryEntity.User_Id           = Convert.ToInt32(updatedUserID);
                            _userCountryEntity.Country_Master_Id = Convert.ToInt32(lstCountryId[i]);
                            _userCountryEntity.Created_Date      = DateTime.Now;
                            _userCountryEntity.Created_By        = SessionHelper.LoggedinUser == null ? AppConstants.CreatedBy : SessionHelper.LoggedinUser.User511;
                            var status = dbUserAdministration.InsertUserCountryAssociation(_userCountryEntity);
                        }
                    }
                }
                return(updatedUserID);
            }
            else
            {
                return(-1);
            }
        }