/// <summary> /// Synchronizes the MSP worklog tariff types to match the SIS worklog tariff types /// </summary> public async Task SyncWorklogTariffTypes() { var sisWorklogTariffTypes = await _sisWorklogTariffTypeRepo.GetAllAsync(); List <ITypeEntity> mspWorklogTariffTypes; using (var uow = _dapperUowFactory.Create()) { mspWorklogTariffTypes = uow.MspWorklogTariffTypeRepository.GetAllActive().ToList <ITypeEntity>(); uow.Commit(); } var newTypes = sisWorklogTariffTypes.Except(mspWorklogTariffTypes); var removedTypes = mspWorklogTariffTypes.Except(sisWorklogTariffTypes); using (var uow = _dapperUowFactory.Create()) { foreach (var worklogTariffType in newTypes) { uow.MspWorklogTariffTypeRepository.Add(new MspWorklogTariffType(0, worklogTariffType.Description)); } // Removed foreach (var worklogTariffType in removedTypes) { var mspWorklogTariffType = worklogTariffType as MspWorklogTariffType; uow.MspWorklogTariffTypeRepository.Remove(mspWorklogTariffType); } uow.Commit(); } }
/// <inheritdoc /> public IEnumerable <MspProject> GetAll() { using (var uow = _dapperUowFactory.Create()) { return(uow.MspProjectRepository.GetAll()); } }
// Retrieves the emailaddress of an employee private string GetTechnicianEmail(long employeeId) { string emailAddress; using (var uow = _dapperUnitOfWorkFactory.Create()) { emailAddress = uow.MspTechnicianRepository.GetById(employeeId).EmailAddress; } return(emailAddress); }
/// <summary> /// Synchronizes the MSP accounts /// </summary> public async Task SyncAccountsAsync() { HashSet <IAccount> mspAccounts; using (var uow = _dapperUowFactory.Create()) { mspAccounts = uow.MspAccountRepository.GetAll().ToHashSet <IAccount>(); uow.Commit(); } var sisAccounts = await _sisAccountRepository.GetAllAsync(); var sisAccountsHashSet = sisAccounts.ToHashSet <IAccount>(); // Get updated/new accounts in SIS by comparing to MSP accounts var changedAccounts2 = sisAccountsHashSet.Except(mspAccounts, new AccountValueComparer()).ToList(); // Get new accounts by finding all accounts that do not exists var newAccounts = changedAccounts2.Except(mspAccounts, new AccountEqualityComparer()); // Get updated accounts by finding all accounts with a code that does exist in MSP var updatedAccounts = changedAccounts2.Intersect(mspAccounts, new AccountEqualityComparer()); using (var uow = _dapperUowFactory.Create()) { foreach (var account in newAccounts) { var mspAccount = new MspAccount(account); uow.MspAccountRepository.Create(mspAccount); } foreach (var account in updatedAccounts) { var mspAccount = new MspAccount(account); uow.MspAccountRepository.Update(mspAccount); } uow.Commit(); } }
/// <summary> /// Synchronizes the MSP worklog types to match the SIS worklog types /// </summary> public async Task SyncWorklogTypesAsync() { // Get current worklog types in both systems var sisWorklogTypes = await _sisWorklogTypeRepo.GetAllAsync(); List <ITypeEntity> mspWorklogTariffTypes; using (var uow = _dapperUowFactory.Create()) { mspWorklogTariffTypes = uow.MspWorklogTypeRepository.GetAllActive().ToList <ITypeEntity>(); uow.Commit(); } // Compare worklog types in both systems var newTypes = sisWorklogTypes.Except(mspWorklogTariffTypes); var removedTypes = mspWorklogTariffTypes.Except(sisWorklogTypes); using (var uow = _dapperUowFactory.Create()) { // Add new worklog types foreach (var worklogType in newTypes) { uow.MspWorklogTypeRepository.Add(new MspWorklogType { Description = worklogType.Description, IsRemoved = false }); } // Remove deleted worklog type foreach (var worklogType in removedTypes) { var mspWorklogType = worklogType as MspWorklogType; uow.MspWorklogTypeRepository.Remove(mspWorklogType); } uow.Commit(); } }
/// <summary> /// 新增或更新使用者 /// </summary> /// <param name="InputModel"></param> /// <param name="UserId"></param> /// <returns></returns> public async Task <VerityResult> CreateOrUpdateUser(SystemUserModel InputModel, string UserId) { VerityResult result = new VerityResult(); try { SystemUser actionItem = new SystemUser(); if (InputModel.ID == 0) { actionItem.Code = InputModel.Code; actionItem.Name = InputModel.Name; actionItem.Password = "******"; actionItem.Token = " "; actionItem.CreateUser = UserId; actionItem.CreateTime = DateTime.Now; actionItem.Modifier = UserId; actionItem.ModifyTime = DateTime.Now; using (var uow = _dapperUnitOfWorkFactory.Create()) { _systemUserRepository.Add(actionItem); uow.SaveChanges(); } if (result.StatusCode != HttpStatusCode.InternalServerError) { result.StatusCode = HttpStatusCode.OK; result.Message = "CreateSuccess"; // string.Format(ResourceMessage.CreateSuccess, "SystemUser"); } } else { var existUser = _systemUserRepository.Get(InputModel.ID); if (existUser == null) { result.StatusCode = HttpStatusCode.NotFound; result.Message = "NotExistedData"; // string.Format(ResourceMessage.NotExistedData, InputModel.ID); } else { existUser.Modifier = UserId; existUser.ModifyTime = DateTime.Now; using (var uow = _dapperUnitOfWorkFactory.Create()) { _systemUserRepository.Add(actionItem); uow.SaveChanges(); } //_systemUserRepository.Update(dict, "ID"); result.StatusCode = HttpStatusCode.OK; result.Message = "UpdateSuccess"; // string.Format(ResourceMessage.UpdateSuccess, "SystemUser"); } } } catch (Exception ex) { result.StatusCode = HttpStatusCode.InternalServerError; result.Message = ex.Message; ExceptionLog log = new ExceptionLog() { FunctionName = " CreateOrUpdateUser(SystemUserModel InputModel, string UserId)", Parameter = InputModel, StatusCode = HttpStatusCode.InternalServerError, ExceptionMessage = ex }; } return(await Task.Run(() => result)); }