Exemplo n.º 1
0
 /// <summary>
 /// Gets the corporate physician roles.
 /// </summary>
 /// <param name="corporateId">The corporate identifier.</param>
 /// <returns></returns>
 public List <UserRole> GetCorporatePhysicianRoles(int corporateId)
 {
     using (var rolebal = new RoleBal())
     {
         using (var userRoleBal = new UserRoleBal())
         {
             var roleIdlist          = rolebal.GetPhysicianRolesByCorporateId(corporateId);
             var physicianTypeUserId =
                 userRoleBal.GetUserIdByCorporateAndRoleTypeId(corporateId, roleIdlist).ToList();
             return(physicianTypeUserId);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Method to add the User in the database.
        /// </summary>
        /// <param name="m"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public int AddUpdateUser(Users m, int roleId)
        {
            int result;
            var userRolebal     = new UserRoleBal();
            var facilityRoleBal = new FacilityRoleBal();

            using (var transScope = new TransactionScope())
            {
                using (var usersRep = UnitOfWork.UsersRepository)
                {
                    var encryptPassword = EncryptDecrypt.GetEncryptedData(m.Password, "");
                    m.Password        = encryptPassword;
                    usersRep.AutoSave = true;
                    if (m.UserID > 0)
                    {
                        var currentUser = usersRep.Where(u => u.UserID == m.UserID).FirstOrDefault();
                        if (currentUser != null)
                        {
                            m.CreatedBy   = currentUser.CreatedBy;
                            m.CreatedDate = currentUser.CreatedDate;
                        }

                        usersRep.UpdateEntity(m, m.UserID);

                        var name = $"{m.FirstName} - {m.LastName}";

                        //Add missing updates in roles
                        if (roleId > 0)
                        {
                            using (var uRoleRep = UnitOfWork.UserRoleRepository)
                            {
                                var currentRole = uRoleRep.Where(r => r.UserID == m.UserID).FirstOrDefault();
                                if (currentRole != null && currentRole.RoleID != roleId)
                                {
                                    currentRole.RoleID       = roleId;
                                    currentRole.ModifiedBy   = m.ModifiedBy;
                                    currentRole.ModifiedDate = m.ModifiedDate;
                                    uRoleRep.UpdateEntity(currentRole, currentRole.UserRoleID);

                                    //Update the roles in Physician Table too if schedulingApplied is set true to that current role in FacilityRole Table.
                                    var isSchedulingApplied = facilityRoleBal.IsSchedulingApplied(roleId);
                                }
                            }
                        }


                        if (Convert.ToBoolean(m.IsDeleted))
                        {
                            userRolebal.DeleteRoleWithUser(m.UserID);
                        }
                        transScope.Complete();
                    }
                    else
                    {
                        usersRep.Create(m);

                        //Check if User Role is added
                        if (m.UserID > 0 && roleId > 0)
                        {
                            var userRoleModel = new UserRole
                            {
                                UserID      = m.UserID,
                                RoleID      = roleId,
                                IsActive    = true,
                                IsDeleted   = false,
                                CreatedBy   = m.CreatedBy,
                                CreatedDate = m.CreatedDate,
                                UserRoleID  = 0
                            };
                            var newUserRoleId = userRolebal.SaveUserRole(userRoleModel);
                            if (newUserRoleId > 0)
                            {
                                var facilityRoleModel = new FacilityRole
                                {
                                    RoleId         = roleId,
                                    FacilityRoleId = 0,
                                    FacilityId     = Convert.ToInt32(m.FacilityId),
                                    IsActive       = true,
                                    IsDeleted      = false,
                                    CorporateId    = Convert.ToInt32(m.CorporateId),
                                    CreatedBy      = m.CreatedBy,
                                    CreatedDate    = m.CreatedDate
                                };
                                var isAdded = facilityRoleBal.SaveFacilityRoleIfNotExists(facilityRoleModel);
                                if (isAdded)
                                {
                                    transScope.Complete();
                                }
                            }
                        }
                    }


                    result = m.UserID;
                }
            }
            return(result);
        }