public bool AddProfile(ProfileModel profileModel) { Profile profile = new Profile(); AutoMapper.Mapper.Map(profileModel, profile); bool isExists = profileRepository.Exists(r => r.ProfileName == profileModel.ProfileName && (r.CompanyId == profileModel.CompanyId || profileModel.CompanyId == null) && r.RecordDeleted == false); if (!isExists) { List <ProfilePermission> defaultPermissions = profilePermissionRepository.GetAll(x => x.Profile.IsDefaultForRegisterdUser == true).ToList(); foreach (ProfilePermission profilePermission in defaultPermissions) { profile.ProfilePermissions.Add(new ProfilePermission() { HasAccess = profilePermission.HasAccess, CreatedDate = DateTime.UtcNow, ModulePermissionId = profilePermission.ModulePermissionId, CreatedBy = profileModel.CreatedBy }); } profileRepository.Insert(profile); return(true); } else { return(false); } }
public void UpdateProfilePermission(List <ProfilePermissionModel> profilePermissionModels, int modifiedBy) { int?profileId = profilePermissionModels[0].ProfileId; //ProfilePermission profilePermission = profilePermissionRepository.SingleOrDefault(r => r.ProfilePermissionId == profilePermissionModel.ProfilePermissionId); List <ProfilePermission> profilePermissionList = profilePermissionRepository.GetAll(r => r.ProfileId == profileId).ToList(); if (profilePermissionList != null) { foreach (var profilePermissionModel in profilePermissionModels) { ProfilePermission profilePermission = profilePermissionList.Where(x => x.ProfilePermissionId == profilePermissionModel.ProfilePermissionId).SingleOrDefault(); profilePermission.HasAccess = profilePermissionModel.HasAccess; profilePermission.ModifiedDate = DateTime.UtcNow; profilePermission.ModifiedBy = modifiedBy; } profilePermissionRepository.UpdateAll(profilePermissionList); } }