예제 #1
0
        /// <summary>
        /// 啟用/停用 APP
        /// </summary>
        /// <returns></returns>
        public TResult <bool> EnableOrDisableApp(AppListItem appListItem)
        {
            //UI 畫面  是啟用 就是 反向
            string status = appListItem.Status ? AppStatus.Disable : AppStatus.Enable;

            if (status == AppStatus.Enable && !string.IsNullOrEmpty(appListItem.OSType))
            {
                //先檢查 有無其他版本啟用 不包含自己
                WisAppOs wisAppOs = _appListService.CheckAppOsStatus(appListItem.AppID, appListItem.OSType == "IOS" ? 1 : 2);

                if (wisAppOs != null && wisAppOs.AppOSID != Convert.ToInt32(appListItem.AppOSID))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "已有其本版已啟用!"));
                }
            }

            bool updated = _appListService.EnableOrDisableApp(appListItem.AppOSID, status);

            if (updated)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "updated fail!"));
            }
        }
예제 #2
0
        public TResult <List <AvailableGroupDefine> > GetSearchGroupDefine(List <string> groupID, string searchGroup)
        {
            List <WisDefineGroup> wisDefineGroup = _appListService.GetSearchDefineGroup(groupID, searchGroup);

            List <AvailableGroupDefine> searchGroupDefine = _mapper.Map <List <WisDefineGroup>, List <AvailableGroupDefine> >(wisDefineGroup);

            return(TResult <List <AvailableGroupDefine> > .OK(searchGroupDefine, "OK"));
        }
예제 #3
0
        public TResult <List <AvailableGroupDefine> > GetAvailableGroupDefine(List <string> groupID)
        {
            List <WisDefineGroup> availableWisDefineGroup = _appListService.GetAvailableDefineGroup(groupID);

            List <AvailableGroupDefine> availableGroupDefine = _mapper.Map <List <WisDefineGroup>, List <AvailableGroupDefine> >(availableWisDefineGroup);

            return(TResult <List <AvailableGroupDefine> > .OK(availableGroupDefine, "OK"));
        }
예제 #4
0
        /// <summary>
        /// 第一次web 載入預設收尋
        /// </summary>
        /// <returns></returns>
        public TResult <AppListViewModel> Initialize()
        {
            List <AppListItem> appListItem = _appListService.InitGetAppList();
            AppListViewModel   viewModel   = new AppListViewModel
            {
                Search  = new AppListSearchRequest(),
                AppList = appListItem
            };

            return(TResult <AppListViewModel> .OK(viewModel, "OK"));
        }
예제 #5
0
        public TResult <AppOsDetailsViewModel> GetAvailbleAppDescription(string appID, int appOsID, byte osType)
        {
            List <WisAppOsOther> wisAppOsOther = new List <WisAppOsOther>();
            WisAppList           wisAppList    = _appListService.GetAppName(appID);
            List <WisAppOs>      wisAppOs      = _appListService.GetAppOs(appID);
            List <WisAppPhoto>   wisAppPhoto   = _uploadFileService.GetPhotos(appID);

            AppDescription appDescription = _mapper.Map <WisAppList, AppDescription>(wisAppList);

            //取當前版
            AppOsInfo appNowVersion = _mapper.Map <WisAppOs, AppOsInfo>(
                wisAppOs.Where(
                    p => p.OSType == osType &&
                    p.Status == AppStatus.EnableBool &&
                    p.DelFlag == false &&
                    p.WebDownFlag == true &&
                    p.AppOSID == appOsID)?.OrderByDescending(p => p.CreateDT).FirstOrDefault());

            //是否要取得多載點 的path路徑
            if (appNowVersion.MultipleDownload)
            {
                wisAppOsOther = _uploadFileService.GetWisAppOsOther(appID, appOsID.ToString());
            }

            //至少會有 WisAppOS table 原始台灣載點路徑
            wisAppOsOther.Add(new WisAppOsOther {
                Site = "WHQ", FilePath = appNowVersion.FilePath
            });

            //組成完整載點路徑: endpoint+path url
            List <DownloadUrlList> downloadUrlList = UploadFileHepler.GetDownloadUrlList(_configContext.OtherSideEndPoint, wisAppOsOther);

            //歷史紀錄 前5筆
            List <AppOsInfo> appHistory = _mapper.Map <List <WisAppOs>, List <AppOsInfo> >(
                wisAppOs.Where(
                    p => p.OSType == osType &&
                    p.DelFlag == false
                    )?.OrderByDescending(p => p.CreateDT).Take(5).ToList());

            //圖片資訊 FileNumber = 5 為 icon 圖片
            List <AppPhotoContent> photo = _mapper.Map <List <WisAppPhoto>, List <AppPhotoContent> >(wisAppPhoto.Where(p => p.AppOS == osType)?.OrderBy(p => p.FileNumber).ToList());

            AppOsDetailsViewModel viewModel = new AppOsDetailsViewModel
            {
                Description   = appDescription,
                AppNowVersion = appNowVersion,
                AppOsHistory  = appHistory,
                Photo         = photo,
                DownloadList  = downloadUrlList
            };

            return(TResult <AppOsDetailsViewModel> .OK(viewModel, "OK"));
        }
예제 #6
0
        /// <summary>
        /// 如果資料 只新增 AppList 需刪除 AppID 就可
        /// 如果資料 新增到 AppOS 需刪除 AppOSID
        /// </summary>
        /// <param name="appListItem"></param>
        /// <returns></returns>
        public TResult <bool> DeleteApp(AppListItem appListItem)
        {
            bool deleted = false;

            if (!string.IsNullOrEmpty(appListItem.AppOSID))
            {
                //有值 代表需刪除  AppOS 就可以
                deleted = _appListService.DeleteAppOs(appListItem.AppOSID);
            }
            else
            {
                //無值 代表 只新增 AppList 階段 需刪除 AppID 就可
                deleted = _appListService.DeleteApp(appListItem.AppID);
            }
            if (deleted)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "delete fail!"));
            }
        }
예제 #7
0
        public TResult <List <AvailableAppListViewModel> > GetAvailableAppList(string companyApp, byte osType)
        {
            string            sqlAppendStr = "";
            DynamicParameters parameters   = new DynamicParameters();

            //授權權限使用者
            parameters.Add(@"@Uid", _authService.GetCurrentUserID(), DbType.String);

            //從razor change event 拿不到 value 只能
            if (!companyApp.Equals("All"))
            {
                bool isCompanyApp = false;
                if (companyApp == CompanyApp.Yes)
                {
                    isCompanyApp = true;
                }
                else
                {
                    isCompanyApp = false;
                }

                sqlAppendStr += @" AND app.CompanyApp = @CompanyApp ";
                parameters.Add(@"@CompanyApp", isCompanyApp, DbType.Boolean);
            }

            if (osType != 3)
            {
                sqlAppendStr += @" AND appOs.OSType = @OSType ";
                parameters.Add(@"@OSType", osType, DbType.Byte);
            }

            sqlAppendStr += @" Order BY app.IsTop DESC, appOs.LastUpdateDT DESC ";
            List <AvailableAppList>          availableAppLists          = _appListService.GetAvailableApp(sqlAppendStr, parameters);
            List <AvailableAppListViewModel> availableAppListViewModels = _mapper.Map <List <AvailableAppList>, List <AvailableAppListViewModel> >(availableAppLists);

            return(TResult <List <AvailableAppListViewModel> > .OK(availableAppListViewModels, "OK"));
        }
예제 #8
0
        /// <summary>
        /// 更新 Wis App name
        /// </summary>
        /// <param name="appNameCreate"></param>
        /// <returns></returns>
        public TResult <bool> ModifyAppName(AppNameCreate appNameCreate)
        {
            List <WisAppUserList> wisAppUserList = new List <WisAppUserList>();

            //撈出置頂總合資料
            List <InSideOrOutSideApp> inSideOrOutSideApps = _appListService.GetIsTopAppList();

            #region Check 置頂

            //如果要頂置 需檢查頂置規則 企業APP 2筆 外部 App 2筆
            var result = IsTopCalculateHelper.IsOverTopQuantity(appNameCreate, inSideOrOutSideApps, false);

            if (!result.isCheckTop)
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, result.errorMessage));
            }

            #endregion

            //DTO
            WisAppList wisApp = _mapper.Map <AppNameCreate, WisAppList>(appNameCreate);
            DateTime   date   = DateTime.Now;
            wisApp.LastUpdateUser = "******";
            wisApp.LastUpdateDT   = date;

            #region 授權群組 設定 AppOen  1:開放,0:有授權名單

            if (!string.IsNullOrEmpty(wisApp.AppUserGroup) && wisApp.AppOpen == false)
            {
                List <string> groupID = wisApp.AppUserGroup?.Split(',').ToList();

                List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

                foreach (var item in wisDefineGroups)
                {
                    //新增群組
                    if (!string.IsNullOrEmpty(item.GroupInclude))
                    {
                        List <MdsHrEmpData> mdsHrEmpData = new List <MdsHrEmpData>();
                        List <string>       findGroup    = item.GroupInclude.Split(',').ToList();
                        if (item.SelectGroup == "1") // 找Site
                        {
                            mdsHrEmpData.AddRange(_appListService.GetHrEmpByLocation(findGroup));
                        }
                        else // 找 DeptID
                        {
                            mdsHrEmpData.AddRange(_appListService.GetHrEmpByDept(findGroup));
                        }

                        List <WisAppUserList> findAppUser = mdsHrEmpData.Select(p => new WisAppUserList {
                            AppID = appNameCreate.AppID, UserID = p.Uid
                        }).ToList();

                        wisAppUserList.AddRange(findAppUser);
                    }

                    //新增 自定義的user
                    if (!string.IsNullOrEmpty(item.AccountInclude))
                    {
                        List <MdsAdUserData> mdsAdUserDatas = new List <MdsAdUserData>();
                        List <MdsHrEmpData>  mdsHrEmpData   = new List <MdsHrEmpData>();
                        List <string>        findUId        = item.AccountInclude.Split(',').ToList();
                        if (item.SelectAccount == "1") // 找 AD Data
                        {
                            mdsAdUserDatas = _appListService.GetMdsAdUser(findUId);
                        }
                        else // 找 HR Data
                        {
                            mdsHrEmpData = _appListService.GetHrEmpByUId(findUId);
                        }

                        List <WisAppUserList> findAppUser = mdsAdUserDatas.Select(p => new WisAppUserList {
                            AppID = appNameCreate.AppID, UserID = p.Uid
                        }).ToList();
                        List <WisAppUserList> findAppUserByHr = mdsHrEmpData.Select(p => new WisAppUserList {
                            AppID = appNameCreate.AppID, UserID = p.Uid
                        }).ToList();

                        wisAppUserList.AddRange(findAppUser);
                        wisAppUserList.AddRange(findAppUserByHr);
                    }
                }
            }

            #endregion

            bool isModified = _appListService.ModifyAppName(wisApp, wisAppUserList);

            if (isModified)
            {
                return(TResult <bool> .OK(true, appNameCreate.AppName));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Modify App name fail!"));
            }
        }
예제 #9
0
        /// <summary>
        /// 更新 Wis APP os
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <returns></returns>
        public TResult <bool> InsertOrModifyAppOs(AppOsInfo appOsInfo)
        {
            //短解 應該前端要給預設值 DownloadUrlList.Count = 0 這樣的設定 要不然會throw exception
            if (appOsInfo.DownloadUrlList == null)
            {
                appOsInfo.DownloadUrlList = new List <DownloadUrlList>();
            }

            //CompanyApp  = false 欄位版本資訊為空值 補上預設值 原因是外部App 不需要輸入版本號 但是db 欄位為必填
            if (string.IsNullOrEmpty(appOsInfo.Version))
            {
                appOsInfo.Version = "";
            }

            DateTime date = DateTime.Now;

            WisAppOs           wisAppOs    = _mapper.Map <AppOsInfo, WisAppOs>(appOsInfo);
            List <WisAppPhoto> wisAppPhoto = _mapper.Map <List <AppPhotoContent>, List <WisAppPhoto> >(appOsInfo.Photo);

            //視為存在條件  AppID & OsType & Version
            WisAppOs wisAppOsFromDb = _appListService.AppOsIsExisted(appOsInfo.AppID, appOsInfo.OSType, appOsInfo.Version);

            //沒有代表是新增
            if (wisAppOsFromDb == null)
            {
                List <WisAppOsOther> insertWisAppOsOthers = new List <WisAppOsOther>();
                wisAppOs.DelFlag        = false;
                wisAppOs.LastUpdateUser = "******";
                wisAppOs.CreateDT       = date;
                wisAppOs.LastUpdateDT   = date;

                //多載點功能啟用 才新增
                if (appOsInfo.MultipleDownload)
                {
                    //多載點處理
                    foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                    {
                        insertWisAppOsOthers.Add(new WisAppOsOther
                        {
                            AppID          = wisAppOs.AppID,
                            AppOsID        = 0,//等transaction當中insert
                            Site           = downloadUrl.Site,
                            OSType         = wisAppOs.OSType,
                            Version        = wisAppOs.Version,
                            FileName       = appOsInfo.FileName, //IOS 為 ipa路徑 Android 為原始 apk檔案名稱
                            FilePath       = downloadUrl.Url,    //IOS 為plist路徑  Android 為apk路徑
                            LastUpdateUser = "******",
                            LastUpdateDT   = date,
                            CreateDT       = date
                        });
                    }
                }

                bool isInserted = _appListService.DisableAppOsStatusAndInsertAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, insertWisAppOsOthers);

                if (isInserted)
                {
                    //取新增後的 appOsID
                    WisAppOs insertObject = _appListService.GetAppOs(appOsInfo.AppID).FirstOrDefault(p => p.OSType == appOsInfo.OSType && p.Status == AppStatus.EnableBool);
                    return(TResult <bool> .OK(true, insertObject.AppOSID.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Insert App Os fail!"));
                }
            }
            else
            { //有在DB 找到 代表更新
                List <WisAppOsOther> insertWisAppOsOthers = new List <WisAppOsOther>();
                wisAppOs.DelFlag        = wisAppOsFromDb.DelFlag;
                wisAppOs.LastUpdateUser = wisAppOsFromDb.LastUpdateUser;
                wisAppOs.CreateDT       = wisAppOsFromDb.CreateDT;
                wisAppOs.LastUpdateDT   = date;

                //多載點功能啟用 才更新
                if (appOsInfo.MultipleDownload)
                {
                    //多載點 處理
                    foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                    {
                        insertWisAppOsOthers.Add(new WisAppOsOther
                        {
                            AppID          = wisAppOs.AppID,
                            AppOsID        = wisAppOs.AppOSID,//必定會有 AppOsID
                            Site           = downloadUrl.Site,
                            OSType         = wisAppOs.OSType,
                            Version        = wisAppOs.Version,
                            FileName       = appOsInfo.FileName, //IOS 為 ipa路徑 Android 為原始 apk檔案名稱
                            FilePath       = downloadUrl.Url,    //IOS 為plist路徑  Android 為apk路徑
                            LastUpdateUser = "******",
                            LastUpdateDT   = date,
                            CreateDT       = date
                        });
                    }
                }

                bool isUpdated = _appListService.DisableAppOsStatusAndModifyAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, insertWisAppOsOthers);

                if (isUpdated)//返回 更新
                {
                    return(TResult <bool> .OK(true, appOsInfo.AppOSID.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Update App Os fail!"));
                }
            }
        }
        /// <summary>
        /// 頁簽畫面 ViewModel
        /// </summary>
        /// <param name="appID"></param>
        /// <param name="appOsID"></param>
        /// <param name="appOsType"></param>
        /// <returns></returns>
        public TResult <AppEditViewModel> GetCreateAndEditApp(string appID, string appOsID = "", string appOsType = "")
        {
            WisAppList           wisAppList     = _appListService.GetAppName(appID);
            List <WisAppOs>      wisAppOs       = _appListService.GetAppOs(appID);
            List <WisAppPhoto>   wisAppPhoto    = _uploadFileService.GetPhotos(appID);
            List <WisAppOsOther> wisAppOsOthers = _uploadFileService.GetWisAppOsOther(appID, appOsID);

            AppOsInfo         editAppIos        = null;
            AppOsInfo         editAppAndroid    = null;
            List <AppOsOther> iosAppOsOther     = new List <AppOsOther>();
            List <AppOsOther> androidAppOsOther = new List <AppOsOther>();

            //DTO
            AppNameCreate appNameCreate = _mapper.Map <WisAppList, AppNameCreate>(wisAppList);

            #region 處理  User Group Name

            if (!string.IsNullOrEmpty(wisAppList.AppUserGroup))
            {
                List <string> groupID = wisAppList.AppUserGroup.Split(',').ToList();

                List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

                //組成 DigitalHR,ML1400,WZS All users 顯示在前端
                string userGroupName = string.Join(",", wisDefineGroups.Select(p => p.GroupName).ToArray().Select((s, i) => s.ToString()));

                appNameCreate.AppUserGroupName = userGroupName;
            }

            #endregion

            //透過 AppOSID  取編輯 資料
            if (appOsType == "IOS")
            {//選取的 AppOSID 為IOS  那 Android 拿取目前已啟動的資料
                editAppIos     = _mapper.Map <WisAppOs, AppOsInfo>(wisAppOs.Where(p => p.OSType == OsType.Ios && p.AppOSID.ToString() == appOsID).FirstOrDefault());
                editAppAndroid = _mapper.Map <WisAppOs, AppOsInfo>(wisAppOs.Where(p => p.OSType == OsType.Android && p.Status == true).FirstOrDefault());

                //多載點
                iosAppOsOther = _mapper.Map <List <WisAppOsOther>, List <AppOsOther> >(wisAppOsOthers.Where(p => p.OSType == OsType.Ios).ToList());
            }
            else if (appOsType == "Android")
            {//選取的 AppOSID 為Android  那 IOS 拿取目前已啟動的資料
                editAppIos     = _mapper.Map <WisAppOs, AppOsInfo>(wisAppOs.Where(p => p.OSType == OsType.Ios && p.Status == true).FirstOrDefault());
                editAppAndroid = _mapper.Map <WisAppOs, AppOsInfo>(wisAppOs.Where(p => p.OSType == OsType.Android && p.AppOSID.ToString() == appOsID).FirstOrDefault());

                //多載點
                androidAppOsOther = _mapper.Map <List <WisAppOsOther>, List <AppOsOther> >(wisAppOsOthers.Where(p => p.OSType == OsType.Android).ToList());
            }

            //歷史紀錄
            List <AppOsInfo> appIosHistory     = _mapper.Map <List <WisAppOs>, List <AppOsInfo> >(wisAppOs.Where(p => p.OSType == OsType.Ios && p.DelFlag == false)?.OrderByDescending(p => p.CreateDT).ToList());
            List <AppOsInfo> appAndroidHistory = _mapper.Map <List <WisAppOs>, List <AppOsInfo> >(wisAppOs.Where(p => p.OSType == OsType.Android && p.DelFlag == false)?.OrderByDescending(p => p.CreateDT).ToList());

            //圖片資訊
            List <AppPhotoContent> iosPhoto     = _mapper.Map <List <WisAppPhoto>, List <AppPhotoContent> >(wisAppPhoto.Where(p => p.AppOS == OsType.Ios).ToList());
            List <AppPhotoContent> androidPhoto = _mapper.Map <List <WisAppPhoto>, List <AppPhotoContent> >(wisAppPhoto.Where(p => p.AppOS == OsType.Android).ToList());

            //IOS
            if (editAppIos != null)
            {
                editAppIos.AppName         = wisAppList.AppName;
                editAppIos.AppNameEn       = wisAppList.AppNameEn;
                editAppIos.Photo           = iosPhoto;
                editAppIos.AppOsHistory    = appIosHistory ?? new List <AppOsInfo>();
                editAppIos.AppOsOther      = iosAppOsOther;
                editAppIos.DownloadUrlList = iosAppOsOther.Select(p => new DownloadUrlList {
                    Site = p.Site, Url = p.FilePath
                }).ToList();
            }
            else
            {
                //為 null 代表是只建立 app Name 而已 但是一定有 App ID 因為一定有建立 Create App name
                editAppIos = new AppOsInfo
                {
                    AppID        = appID,
                    AppName      = wisAppList.AppName,
                    AppNameEn    = wisAppList.AppNameEn,
                    OSType       = OsType.Ios,
                    Status       = true,
                    Photo        = iosPhoto,
                    AppOsHistory = appIosHistory ?? new List <AppOsInfo>(),
                    AppOsOther   = iosAppOsOther
                };
            }

            //Android
            if (editAppAndroid != null)
            {
                editAppAndroid.AppName         = wisAppList.AppName;
                editAppAndroid.AppNameEn       = wisAppList.AppNameEn;
                editAppAndroid.Photo           = androidPhoto;
                editAppAndroid.AppOsHistory    = appAndroidHistory ?? new List <AppOsInfo>();
                editAppAndroid.AppOsOther      = androidAppOsOther;
                editAppAndroid.DownloadUrlList = androidAppOsOther.Select(p => new DownloadUrlList {
                    Site = p.Site, Url = p.FilePath
                }).ToList();
            }
            else
            {
                //為 null 代表是只建立 app Name 而已 但是一定有 App ID 因為一定有建立 Create App name
                editAppAndroid = new AppOsInfo
                {
                    AppID        = appID,
                    AppName      = wisAppList.AppName,
                    AppNameEn    = wisAppList.AppNameEn,
                    OSType       = OsType.Android,
                    Status       = true,
                    Photo        = androidPhoto,
                    AppOsHistory = appAndroidHistory ?? new List <AppOsInfo>(),
                    AppOsOther   = androidAppOsOther
                };
            }

            AppEditViewModel appEditViewModel = new AppEditViewModel
            {
                AppName    = appNameCreate,
                AppIos     = editAppIos,
                AppAndroid = editAppAndroid
            };

            return(TResult <AppEditViewModel> .OK(appEditViewModel, "OK"));
        }
예제 #11
0
        /// <summary>
        /// 因實體檔案 目前已 dev server C:/AppOs 路徑下為主 所以再本機 測試 會有無法刪除檔案情形
        /// </summary>
        /// <param name="appListItem"></param>
        /// <returns></returns>
        public TResult <bool> DeleteFile(AppListItem appListItem)
        {
            bool deleted = false;

            if (string.IsNullOrEmpty(appListItem.AppOSID))
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "無法刪除實體檔案 因為 AppOsId 為空值"));
            }

            if (string.IsNullOrEmpty(appListItem.FilePath))
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "無實體安裝檔案"));
            }

            //IOS 刪除檔案
            if (appListItem.OSType == "IOS")
            {
                //Plist 檔案
                string filePath = $"{_configContext.UploadPath}/{appListItem.FilePath}";
                //ipa 檔案
                string fileName = $"{_configContext.UploadPath}/{appListItem.FileName}";

                if (!File.Exists(filePath))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝Plist路徑檔案"));
                }

                if (!File.Exists(fileName))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝ipa路徑檔案"));
                }

                //刪除實體檔案
                File.Delete(filePath);
                File.Delete(fileName);
            }

            //Android 刪除檔案
            if (appListItem.OSType == "Android")
            {
                //apk 檔案 Android filePath  為 .apk 檔案路徑 fileName 為原.apk 黨案名稱
                string filePath = $"{_configContext.UploadPath}/{appListItem.FilePath}";

                if (!File.Exists(filePath))
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, " 無實體安裝apk路徑檔案"));
                }

                //刪除實體檔案
                File.Delete(filePath);
            }

            //DB 更新
            deleted = _appListService.DeleteAppFilePath(appListItem.AppOSID);

            if (deleted)
            {
                return(TResult <bool> .OK(true, "OK"));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "再刪除資料庫 欄位 FilePath出現錯誤"));
            }
        }
예제 #12
0
 public TResult <List <McpCategory> > GetCategory()
 {
     return(TResult <List <McpCategory> > .OK(_appListService.GetCategory(), "OK"));
 }
예제 #13
0
        /// <summary>
        /// 上傳 Ios Android 安裝檔案
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <param name="uploadFile"></param>
        /// <returns></returns>
        public async Task <TResult <AppOsInfo> > UploadInstallFile(AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            //存放多載點 plist 檔案名稱
            List <DownloadUrlList> downloadUrlList = new List <DownloadUrlList>();

            #region 驗證檔案格式

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (string.IsNullOrEmpty(appOsInfo.Version))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_VERSIONREQUIRED, "必須輸入 版本號碼"));
            }

            if (appOsInfo.Photo.Where(p => p.FileNumber == 5).FirstOrDefault() == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "必須上傳 Icon 圖片"));
            }

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();

            //驗證 Ios 是否符合格式 目前只看.ipa 檔案
            if (appOsInfo.OSType == OsType.Ios && !extension.Equals(".ipa"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  IOS 安裝檔應為 .ipa 格式"));
            }

            //驗證 Android 是否符合格式 目前只看.apk 檔案
            if (appOsInfo.OSType == OsType.Android && !extension.Equals(".apk"))
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式限制:  Android 安裝檔應為 .apk 格式"));
            }

            #endregion

            string fileName = $"{appOsInfo.Version}-{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath   = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Install");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            #region 如果是 IOS 必須做出 Plist 檔案 和多載點 plist

            //如果是IOS 除了上傳.ipa 檔案 還要上傳 Plist xml file
            if (appOsInfo.OSType == OsType.Ios)
            {
                //圖片 url 路徑
                AppPhotoContent iosIconPhoto = appOsInfo.Photo.Where(P => P.FileNumber == 5).FirstOrDefault();

                //多載點 plist
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    // 組plist 黨案名稱
                    string pListFileName = $"{Guid.NewGuid().ToString("N")}{".plist"}";

                    // 組 ipa url 路徑
                    string ipaPath = $"{endPoint.Url}/{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                    // 組圖片 url 路徑
                    string iconPath = iosIconPhoto != null ? $"{endPoint.Url}/{iosIconPhoto.FilePath.Replace(" ", "")}" : "";

                    //做出 plist xml 內容物
                    string plistXml = UploadFileHepler.GetPlistXml(ipaPath, iconPath, appOsInfo.PackageName, appOsInfo.Version, appOsInfo.AppNameEn);

                    //存入 Plist 實體路徑
                    File.WriteAllText(Path.Combine(filePath, pListFileName), plistXml);

                    //原始路徑 存在Wis_AppOS table
                    if (endPoint.Site == "WHQ")
                    { //原始載點不加入 DownloadUrlList
                      //為 plist 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}";

                        //為 .ipa 檔案路徑
                        appOsInfo.FileName = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";
                    }
                    else
                    {//多載點資訊 存在 Wis_AppOs_Other
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{pListFileName}"//plist 路徑
                        });
                    }
                }

                //前端必須按下儲存按鈕  url資訊才會寫入 DB
                //Ios 上傳檔案路徑 是 plist檔案路徑
                appOsInfo.DownloadUrlList = downloadUrlList;
            }

            #endregion

            #region Android 處理檔案 路徑

            //Android 直接存放 apk 檔案路徑
            if (appOsInfo.OSType == OsType.Android)
            {
                foreach (OtherSideEndPoint endPoint in _configContext.OtherSideEndPoint)
                {
                    //Wis_AppOS url 路徑處理
                    if (endPoint.Site == "WHQ")
                    {
                        //為 .apk 檔案路徑
                        appOsInfo.FilePath = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}";

                        //為 .apk 原檔案名稱
                        appOsInfo.FileName = uploadFile.Name;
                    }
                    else
                    {//Wis_AppOs_Other 資訊
                        downloadUrlList.Add(new DownloadUrlList
                        {
                            Site = endPoint.Site,
                            Url  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Install"}/{fileName}"//.apk 檔案路徑
                        });
                    }
                }
                //Android 上傳檔案路徑 是apk檔案路徑 與原本路徑一模一樣
                appOsInfo.DownloadUrlList = downloadUrlList;
            }
            #endregion

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }
예제 #14
0
        /// <summary>
        /// 上傳圖片檔案 對象物件 AppOsInfo 裡的 AppPhotoContent
        /// </summary>
        /// <param name="fileNumber">記錄圖檔上傳位置 5 為安裝檔案Icon圖片</param>
        /// <param name="osType">IOS = 1 Android=2</param>
        /// <param name="appIos"></param>
        /// <param name="uploadFile"></param>
        /// <returns>實體路徑圖片</returns>
        public async Task <TResult <AppOsInfo> > UploadImageFile(int fileNumber, AppOsInfo appOsInfo, IMatFileUploadEntry uploadFile)
        {
            #region 驗證圖片檔案格式

            //驗證圖片是否符合格式  目前只接受 PNG JPEG
            ImageFormat imageType = await _uploadFileService.CheckImageType(uploadFile);

            if (imageType == null)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_IMAGEFORMATTYPE, "檔案格式限制: jpg、jpeg、png"));
            }

            int findExtension = uploadFile.Name.LastIndexOf(".");

            if (findExtension == -1)
            {
                return(TResult <AppOsInfo> .Fail(null, FaultInfoRcConstants.ERR_CODE_OSFORMATTYPE, "檔案格式錯誤: 無附檔名"));
            }

            #endregion

            string extension = uploadFile.Name.Substring(uploadFile.Name.LastIndexOf(".")).ToLower();
            string fileName  = $"{Guid.NewGuid().ToString("N")}{extension}"; //Create a new Name
            string osPath    = OsType.Ios == appOsInfo.OSType ? "IOS" : "Android";
            string filePath  = Path.Combine(_configContext.UploadPath, appOsInfo.AppNameEn.Replace(" ", ""), osPath, "Images");

            //檔案資料夾路徑不存在就新增
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            using (var fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Create, FileAccess.Write))
            {
                await uploadFile.WriteToStreamAsync(fs);
            }

            AppPhotoContent appPhotoContent = new AppPhotoContent
            {
                AppID      = appOsInfo.AppID,
                AppOS      = appOsInfo.OSType,
                FileNumber = fileNumber,
                FileName   = fileName,
                //exapmle Wistron%20Ark\IOS\Images\5-623cefb49e3946a28198464dd72b5bb4.png 子目錄位址
                FilePath  = $"{appOsInfo.AppNameEn.Replace(" ", "")}/{osPath}/{"Images"}/{fileName}",
                PhotoType = fileNumber == 5 ? PhotoType.IconType : PhotoType.NormalType
            };

            //把有存在編號的 去除 在Add更新過後的 但還未更新資料庫 等待 按下儲存按鈕
            AppPhotoContent existed = appOsInfo.Photo.Where(p => p.FileNumber == fileNumber).FirstOrDefault();
            if (existed != null)
            {
                appOsInfo.Photo.Remove(existed);
                appOsInfo.Photo.Add(appPhotoContent);
            }
            else
            {
                appOsInfo.Photo.Add(appPhotoContent);
            }

            return(TResult <AppOsInfo> .OK(appOsInfo, "OK"));
        }
예제 #15
0
        /// <summary>
        /// 新增時需檢查置頂資料
        /// </summary>
        /// <param name="appNameCreate"></param>
        /// <returns></returns>
        public TResult <ResponseAppNameCreate> InsertAppName(AppNameCreate appNameCreate)
        {
            List <WisAppUserList> wisAppUserList = new List <WisAppUserList>();

            bool isExisted = _appListService.AppNameIsExisted(appNameCreate.AppName);

            if (appNameCreate.Category == "None")
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, "請選擇類別"));
            }

            if (isExisted)
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, "App 名稱已存在"));
            }

            //撈出置頂資料
            List <InSideOrOutSideApp> inSideOrOutSideApps = _appListService.GetIsTopAppList();

            #region  Check 置頂

            //如果要頂置 檢查頂置規則 企業APP 2筆 外部 App 2筆
            var result = IsTopCalculateHelper.IsOverTopQuantity(appNameCreate, inSideOrOutSideApps, true);

            if (!result.isCheckTop)
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, result.errorMessage));
            }

            #endregion

            //DTO
            WisAppList wisApp = _mapper.Map <AppNameCreate, WisAppList>(appNameCreate);

            string   appID = Guid.NewGuid().ToString();
            DateTime date  = DateTime.Now;

            appNameCreate.AppID   = appID;
            wisApp.AppID          = appID;
            wisApp.LastUpdateUser = "******";
            wisApp.LastUpdateDT   = date;
            wisApp.CreateDT       = date;
            wisApp.Delflag        = false;
            //開放使用,無須授權	1:開放,0:有授權名單

            #region 授權群組 設定 AppOen  1:開放,0:有授權名單
            List <string> groupID = wisApp.AppUserGroup?.Split(',').ToList();

            List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

            foreach (var item in wisDefineGroups)
            {
                //新增群組
                if (!string.IsNullOrEmpty(item.GroupInclude))
                {
                    List <MdsHrEmpData> mdsHrEmpData = new List <MdsHrEmpData>();
                    List <string>       findGroup    = item.GroupInclude.Split(',').ToList();
                    if (item.SelectGroup == "1") // 找Site
                    {
                        mdsHrEmpData.AddRange(_appListService.GetHrEmpByLocation(findGroup));
                    }
                    else // 找 DeptID
                    {
                        mdsHrEmpData.AddRange(_appListService.GetHrEmpByDept(findGroup));
                    }

                    List <WisAppUserList> findAppUser = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                }

                //新增 自定義的user
                if (!string.IsNullOrEmpty(item.AccountInclude))
                {
                    List <MdsAdUserData> mdsAdUserDatas = new List <MdsAdUserData>();
                    List <MdsHrEmpData>  mdsHrEmpData   = new List <MdsHrEmpData>();
                    List <string>        findUId        = item.AccountInclude.Split(',').ToList();
                    if (item.SelectAccount == "1") // 找 AD Data
                    {
                        mdsAdUserDatas = _appListService.GetMdsAdUser(findUId);
                    }
                    else // 找 HR Data
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByUId(findUId);
                    }

                    List <WisAppUserList> findAppUser = mdsAdUserDatas.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();
                    List <WisAppUserList> findAppUserByHr = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                    wisAppUserList.AddRange(findAppUserByHr);
                }
            }

            #endregion

            bool inserted = _appListService.InsertAppName(wisApp, wisAppUserList);

            if (inserted)
            {
                return(TResult <ResponseAppNameCreate> .OK(new ResponseAppNameCreate { IsSuccessful = true, AppID = appID }, appNameCreate.AppName));
            }
            else
            {
                return(TResult <ResponseAppNameCreate> .Fail(new ResponseAppNameCreate { IsSuccessful = false, AppID = "" }, FaultInfoRcConstants.ERR_CODE_FAIL, "Insert App name fail!"));
            }
        }
예제 #16
0
        /// <summary>
        /// search 條件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public TResult <AppListViewModel> SearchAppList(AppListSearchRequest request)
        {
            string            sqlAppendStr = "";
            DynamicParameters parameters   = new DynamicParameters();

            //AppName
            if (!string.IsNullOrEmpty(request.AppName))
            {
                sqlAppendStr += @"AND LOWER(apList.AppName) LIKE LOWER(@AppName) ";
                parameters.Add(@"@AppName", "%" + request.AppName.ToLower().Trim() + "%", DbType.String);
            }

            //Category
            if (!string.IsNullOrEmpty(request.Category))
            {
                if (request.Category != "All" && request.Category != "None")
                {
                    sqlAppendStr += @"AND apList.Category = @Category ";
                    parameters.Add(@"@Category", request.Category.Trim(), DbType.String);
                }
            }

            //Version
            if (!string.IsNullOrEmpty(request.Version))
            {
                sqlAppendStr += @"AND apOs.Version LIKE @Version ";
                parameters.Add(@"@Version", "%" + request.Version.Trim() + "%", DbType.String);
            }

            //Status
            if (!string.IsNullOrEmpty(request.Enable))
            {
                if (request.Enable != "All" && request.Enable != "None")
                {
                    sqlAppendStr += @"AND apOs.Status =@Status ";
                    parameters.Add(@"@Status", request.Enable.Trim(), DbType.String);
                }
            }


            //同時傳入這兩個參數 StartDate &  EndDate 才要組這串 between 條件
            if (!string.IsNullOrEmpty(request.StartDate?.ToString()) && !string.IsNullOrEmpty(request.EndDate?.ToString()))
            {
                sqlAppendStr += @"AND(apOs.CreateDT >= @StartDate AND apOs.CreateDT <= @EndDate) ";
                parameters.Add(@"@StartDate", request.StartDate, DbType.DateTime);
                parameters.Add(@"@EndDate", request.EndDate.Value.AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999), DbType.DateTime);
            }
            else
            {
                if (!string.IsNullOrEmpty(request.StartDate?.ToString()))
                {
                    sqlAppendStr += @"AND apOs.CreateDT >= @StartDate ";
                    parameters.Add(@"@StartDate", request.StartDate, DbType.DateTime);
                }

                if (!string.IsNullOrEmpty(request.EndDate?.ToString()))
                {
                    sqlAppendStr += @"AND apOs.CreateDT <= @EndDate ";
                    parameters.Add(@"@EndDate", request.EndDate.Value.AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999), DbType.DateTime);
                }
            }

            sqlAppendStr += @" ORDER BY apList.IsTop DESC, apOs.CreateDT DESC, apList.AppID DESC ";


            List <AppListItem> appListItem = _appListService.GetAppList(sqlAppendStr, parameters);
            AppListViewModel   viewModel   = new AppListViewModel
            {
                Search  = request,
                AppList = appListItem
            };

            return(TResult <AppListViewModel> .OK(viewModel, "OK"));
        }
        /// <summary>
        /// 更新 Wis APP os
        /// </summary>
        /// <param name="appOsInfo"></param>
        /// <returns></returns>
        public TResult <bool> InsertOrModifyAppOs(AppOsInfo appOsInfo)
        {
            DateTime date = DateTime.Now;

            WisAppOs wisAppOs = _mapper.Map <AppOsInfo, WisAppOs>(appOsInfo);

            List <WisAppPhoto> wisAppPhoto = _mapper.Map <List <AppPhotoContent>, List <WisAppPhoto> >(appOsInfo.Photo);

            //視為存在條件  AppID & OsType & Version
            WisAppOs wisAppOsFromDb = _appListService.AppOsIsExisted(appOsInfo.AppID, appOsInfo.OSType, appOsInfo.Version);

            //沒有代表是新增
            if (wisAppOsFromDb == null)
            {
                List <WisAppOsOther> insertWisAppOsOthers = new List <WisAppOsOther>();
                wisAppOs.DelFlag        = false;
                wisAppOs.LastUpdateUser = "******";
                wisAppOs.CreateDT       = date;
                wisAppOs.LastUpdateDT   = date;

                //多載點處理
                foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                {
                    insertWisAppOsOthers.Add(new WisAppOsOther
                    {
                        AppID          = wisAppOs.AppID,
                        AppOsID        = 0,//等transaction當中insert
                        Site           = downloadUrl.Site,
                        OSType         = wisAppOs.OSType,
                        Version        = wisAppOs.Version,
                        FileName       = appOsInfo.FileName, //IOS 為 ipa路徑 Android 為原始 apk檔案名稱
                        FilePath       = downloadUrl.Url,    //IOS 為plist路徑  Android 為apk路徑
                        LastUpdateUser = "******",
                        LastUpdateDT   = date,
                        CreateDT       = date
                    });
                }

                bool isInserted = _appListService.DisableAppOsStatusAndInsertAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, insertWisAppOsOthers);

                if (isInserted)
                {
                    //取新增後的 appOsID
                    int insertPrimaryKey = _appListService.GetAppOs(appOsInfo.AppID).Where(p => p.OSType == appOsInfo.OSType).Max(p => p.AppOSID);
                    return(TResult <bool> .OK(true, insertPrimaryKey.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Insert App Os fail!"));
                }
            }

            //有在DB 找到 代表更新
            if (wisAppOsFromDb != null)
            {
                List <AppOsOther> updateAppOsOthers = new List <AppOsOther>();
                wisAppOs.DelFlag        = wisAppOsFromDb.DelFlag;
                wisAppOs.LastUpdateUser = wisAppOsFromDb.LastUpdateUser;
                wisAppOs.CreateDT       = wisAppOsFromDb.CreateDT;
                wisAppOs.LastUpdateDT   = date;

                //多載點 處理
                foreach (DownloadUrlList downloadUrl in appOsInfo.DownloadUrlList)
                {
                    AppOsOther appOsOther = appOsInfo.AppOsOther.Where(p => p.Site == downloadUrl.Site).Select(p => { return(p); }).FirstOrDefault();
                    // 更新 ipa or apk 檔案
                    appOsOther.FileName = wisAppOs.FileName;
                    //更新 plist
                    appOsOther.FilePath = downloadUrl.Url;
                    updateAppOsOthers.Add(appOsOther);
                }

                List <WisAppOsOther> updateWisAppOsOther = _mapper.Map <List <AppOsOther>, List <WisAppOsOther> >(updateAppOsOthers);

                bool isUpdated = _appListService.DisableAppOsStatusAndModifyAppOsAndPhotoAndOsOther(wisAppOs, wisAppPhoto, updateWisAppOsOther);

                if (isUpdated)//返回 更新
                {
                    return(TResult <bool> .OK(true, appOsInfo.AppOSID.ToString()));
                }
                else
                {
                    return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Update App Os fail!"));
                }
            }

            return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "The proccess is fail!"));
        }
예제 #18
0
        public TResult <LoginViewModel> Login(string userId, string password)
        {
            bool isPass = false;
            HrIdentityResponse hrResponse = null;

            try
            {
                #region  Use AD service to auth & HR API Identity

                //AD 驗證先 結果為fasle 再call HR API
                if (_authService.ValidateByAd(userId, password))
                {
                    isPass = true;
                }
                else
                {
                    hrResponse = _authService.IdentityByHr(userId, password);
                    isPass     = hrResponse.Status;
                }

                //AD 認證 和 HR API 其中一個沒過 回傳失敗
                if (!isPass)
                {
                    return(TResult <LoginViewModel> .Fail(new LoginViewModel
                    {
                        IsLogin = isPass,
                        IsAdmin = false,
                        IsMember = false,
                    }, FaultInfoRcConstants.LOGIN_FAIL, "Account/Password error."));
                }

                #endregion

                List <string> uID = new List <string> {
                    userId.ToLower().Trim()
                };

                List <MdsAdUserData> mdsAdUserData = _authService.GetMdsAdUser(uID);

                //檢查是否為 Admin 權限
                List <WisGroupUser> wisGroupUser = _authService.CheckIsAdminOrMember(userId);

                //DB 目前狀況可能會有查到同一個工號 會有雙重身份 admin 和 apadmin
                //雙重身分 只要有找到 Admin 就是管理者
                if (wisGroupUser.Any(p => p.GroupID == "admin"))
                {
                    //為Admin 管理者可使用後台 APP List
                    return(TResult <LoginViewModel> .OK(new LoginViewModel
                    {
                        UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                        //沒AD 名子資訊就取 HR 名子資訊  格式: Ting Chen/WHQ/Wistron
                        Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : hrResponse != null ? $"{hrResponse.Name_Ac.Trim()}{"/"}{hrResponse.Z_Site_ID}{"/Wistron"}" : "",
                        IsLogin = isPass,
                        IsAdmin = true,
                        IsMember = false,
                    }, "is login successful!"));
                }
                else
                {
                    //為一般 使用者只能使用 下載app 版本裝到手機上
                    return(TResult <LoginViewModel> .OK(new LoginViewModel
                    {
                        UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                        //沒AD 名子資訊就取 HR 名子資訊  格式: Ting Chen/WHQ/Wistron
                        Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : hrResponse != null ? $"{hrResponse.Name_Ac.Trim()}{"/"}{hrResponse.Z_Site_ID}{"/Wistron"}" : "",
                        IsLogin = isPass,
                        IsAdmin = false,
                        IsMember = true,
                    }, "is login successful!"));
                }
            }
            catch (Exception ex)
            {
                //考慮到PassWord和OA密碼一致,不記錄PassWord
                LogHelper.WriteException(ex, MethodBase.GetCurrentMethod(), userId);
                return(TResult <LoginViewModel> .Fail(new LoginViewModel
                {
                    IsLogin = false,
                    IsAdmin = false,
                    IsMember = false,
                }, FaultInfoRcConstants.LOGIN_FAIL, "System error."));
            }
        }
예제 #19
0
        public TResult <LoginViewModel> Login(string userId, string password)
        {
            #region  Use AD service to auth

            bool isPassByAd = _authService.ValidateByAd(userId, password);

            //AD 認證沒過 回傳失敗
            if (!isPassByAd)
            {
                return(TResult <LoginViewModel> .Fail(new LoginViewModel
                {
                    IsLogin = isPassByAd,
                    IsAdmin = false,
                    IsMember = false,
                }, FaultInfoRcConstants.LOGIN_FAIL, "Account/Password error."));
            }

            #endregion

            //bool isExisted = _authService.FindSecurityUserAccount(userId.Trim());

            #region 找査  SecurityUserAccount Table 無資料 insert

            //if (!isExisted)
            //{
            //    DateTime dateTime = DateTime.Now;
            //    _authService.InsertSecurityUserAccount(new SecurityUserAccount
            //    {
            //        GroupID = "Console",
            //        AccountID = userId,
            //        Name = userId,
            //        Description = "AD Account",
            //        Password = userId,
            //        Startup = true,
            //        PWLastUpdateTime = null,
            //        PWType = 0,
            //        CreateTime = dateTime,
            //        dModifyTime = dateTime,
            //        iFailTimes = 0,
            //        dLockTime = null,
            //        cRoleID = 0,
            //        AD_CheckFlag = false,
            //        cCallID = null,
            //        cPWD = null,
            //        DEPARTMENT = "",
            //        Email = "",
            //        DomainName = "",
            //    });
            //}

            #endregion

            List <string> uID = new List <string> {
                userId.Trim()
            };

            List <MdsAdUserData> mdsAdUserData = _authService.GetMdsAdUser(uID);

            //檢查是否為 Admin 權限
            List <WisGroupUser> wisGroupUser = _authService.CheckIsAdminOrMember(userId);

            //DB 目前狀況可能會有查到同一個工號 會有雙重身份 admin 和 apadmin
            //雙重身分 只要有找到 Admin 就是管理者
            if (wisGroupUser.Any(p => p.GroupID == "admin"))
            {
                //為Admin 管理者可使用後台 APP List
                return(TResult <LoginViewModel> .OK(new LoginViewModel
                {
                    UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                    Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : "",
                    IsLogin = isPassByAd,
                    IsAdmin = true,
                    IsMember = false,
                }, "is login successful!"));
            }
            else
            {
                //為一般 使用者只能使用 下載app 版本裝到手機上
                return(TResult <LoginViewModel> .OK(new LoginViewModel
                {
                    UID = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Uid : "",
                    Name = mdsAdUserData.Count > 0 ? mdsAdUserData.FirstOrDefault().Name : "",
                    IsLogin = isPassByAd,
                    IsAdmin = false,
                    IsMember = true,
                }, "is login successful!"));
            }
        }
예제 #20
0
        /// <summary>
        /// 更新 Wis App name
        /// </summary>
        /// <param name="appNameCreate"></param>
        /// <returns></returns>
        public TResult <bool> ModifyAppName(AppNameCreate appNameCreate)
        {
            List <WisAppUserList> wisAppUserList = new List <WisAppUserList>();

            //撈出置頂總合資料
            List <InSideOrOutSideApp> inSideOrOutSideApps = _appListService.GetIsTopAppList();

            #region Check 置頂

            //如果要頂置 需檢查頂置規則 企業APP 2筆 外部 App 2筆
            if (appNameCreate.IsTop)
            {
                //企業專用	true:企業APP , false:外部APP
                if (appNameCreate.CompanyApp)
                {
                    //內部 app得要排除 自己的部分
                    int inSideTop = inSideOrOutSideApps.Where(p => p.CompanyApp.Equals("Inside App") && p.AppID != appNameCreate.AppID).Count();

                    if (inSideTop >= 2)
                    {
                        return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "企業內部 App 置頂最多為2筆"));
                    }
                }
                else
                {
                    //外部 app 得要排除 自己的部分
                    int outSideTop = inSideOrOutSideApps.Where(p => p.CompanyApp.Equals("Outside App") && p.AppID != appNameCreate.AppID).Count();

                    if (outSideTop >= 2)
                    {
                        return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "外部 App 置頂最多為2筆"));
                    }
                }
            }

            #endregion

            //DTO
            WisAppList wisApp = _mapper.Map <AppNameCreate, WisAppList>(appNameCreate);
            DateTime   date   = DateTime.Now;
            wisApp.LastUpdateUser = "******";
            wisApp.LastUpdateDT   = date;

            #region 授權群組 設定 AppOen  1:開放,0:有授權名單

            List <string> groupID = wisApp.AppUserGroup?.Split(',').ToList();

            List <WisDefineGroup> wisDefineGroups = _appListService.GetDefineGroup(groupID);

            foreach (var item in wisDefineGroups)
            {
                //新增群組
                if (!string.IsNullOrEmpty(item.GroupInclude))
                {
                    List <MdsHrEmpData> mdsHrEmpData = new List <MdsHrEmpData>();
                    List <string>       findGroup    = item.GroupInclude.Split(',').ToList();
                    if (item.SelectGroup == "1") // 找Site
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByLocation(findGroup);
                    }
                    else // 找 DeptID
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByDept(findGroup);
                    }

                    List <WisAppUserList> findAppUser = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                }

                //新增 自定義的user
                if (!string.IsNullOrEmpty(item.AccountInclude))
                {
                    List <MdsAdUserData> mdsAdUserDatas = new List <MdsAdUserData>();
                    List <MdsHrEmpData>  mdsHrEmpData   = new List <MdsHrEmpData>();
                    List <string>        findUId        = item.AccountInclude.Split(',').ToList();
                    if (item.SelectAccount == "1") // 找 AD Data
                    {
                        mdsAdUserDatas = _appListService.GetMdsAdUser(findUId);
                    }
                    else // 找 HR Data
                    {
                        mdsHrEmpData = _appListService.GetHrEmpByUId(findUId);
                    }

                    List <WisAppUserList> findAppUser = mdsAdUserDatas.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();
                    List <WisAppUserList> findAppUserByHr = mdsHrEmpData.Select(p => new WisAppUserList {
                        AppID = appNameCreate.AppID, UserID = p.Uid
                    }).ToList();

                    wisAppUserList.AddRange(findAppUser);
                    wisAppUserList.AddRange(findAppUserByHr);
                }
            }

            #endregion

            bool isModified = _appListService.ModifyAppName(wisApp, wisAppUserList);

            if (isModified)
            {
                return(TResult <bool> .OK(true, appNameCreate.AppName));
            }
            else
            {
                return(TResult <bool> .Fail(false, FaultInfoRcConstants.ERR_CODE_FAIL, "Modify App name fail!"));
            }
        }