public static void SeedData(ItemsGroupPlanningPnDbContext dbContext) { var seedData = new ItemsPlanningConfigurationSeedData(); var configurationList = seedData.Data; foreach (var configurationItem in configurationList) { if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name)) { var newConfigValue = new PluginConfigurationValue() { Name = configurationItem.Name, Value = configurationItem.Value, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 }; dbContext.PluginConfigurationValues.Add(newConfigValue); dbContext.SaveChanges(); } } // Seed plugin permissions var newPermissions = ItemsGroupPlanningPermissionsSeedData.Data .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName)) .Select(p => new PluginPermission { PermissionName = p.PermissionName, ClaimName = p.ClaimName, CreatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 } ); dbContext.PluginPermissions.AddRange(newPermissions); dbContext.SaveChanges(); }
public static void SeedData(WorkOrderPnDbContext dbContext) { WorkOrdersConfigurationSeedData seedData = new WorkOrdersConfigurationSeedData(); PluginConfigurationValue[] configurationList = seedData.Data; foreach (PluginConfigurationValue configurationItem in configurationList) { if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name)) { PluginConfigurationValue newConfigValue = new PluginConfigurationValue() { Name = configurationItem.Name, Value = configurationItem.Value, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 }; dbContext.PluginConfigurationValues.Add(newConfigValue); dbContext.SaveChanges(); } } // Seed plugin permissions IEnumerable <PluginPermission> newPermissions = WorkOrdersPermissionsSeedData.Data .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName)) .Select(p => new PluginPermission { PermissionName = p.PermissionName, ClaimName = p.ClaimName, CreatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 }); dbContext.PluginPermissions.AddRange(newPermissions); dbContext.SaveChanges(); }
public static void SeedData(IPluginDbContext dbContext, IPluginConfigurationSeedData data) { foreach (var configurationItem in data.Data) { if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name)) { var newConfigValue = new PluginConfigurationValue() { Name = configurationItem.Name, Value = configurationItem.Value, CreatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 }; dbContext.PluginConfigurationValues.Add(newConfigValue); dbContext.SaveChanges(); } } //// Seed plugin permissions //var newPermissions = CustomersPermissionsSeedData.Data // .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName)) // .Select(p => new PluginPermission // { // PermissionName = p.PermissionName, // ClaimName = p.ClaimName, // CreatedAt = DateTime.UtcNow, // Version = 1, // WorkflowState = Constants.WorkflowStates.Created, // CreatedByUserId = 1 // } // ); //dbContext.PluginPermissions.AddRange(newPermissions); dbContext.SaveChanges(); }
public static void SeedData(CaseTemplatePnDbContext dbContext) { var seedData = new BaneDanmarkLaConfigurationSeedData(); var configurationList = seedData.Data; foreach (var configurationItem in configurationList) { if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name)) { var newConfigValue = new PluginConfigurationValue() { Name = configurationItem.Name, Value = configurationItem.Value, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 }; dbContext.PluginConfigurationValues.Add(newConfigValue); dbContext.SaveChanges(); } } }
public static void SeedData(ItemsPlanningPnDbContext dbContext) { var seedData = new ItemsPlanningConfigurationSeedData(); var configurationList = seedData.Data; foreach (var configurationItem in configurationList) { if (!dbContext.PluginConfigurationValues.Any(x => x.Name == configurationItem.Name)) { var newConfigValue = new PluginConfigurationValue() { Name = configurationItem.Name, Value = configurationItem.Value, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 }; dbContext.PluginConfigurationValues.Add(newConfigValue); dbContext.SaveChanges(); } } // Seed plugin permissions var newPermissions = ItemsPlanningPermissionsSeedData.Data .Where(p => dbContext.PluginPermissions.All(x => x.ClaimName != p.ClaimName)) .Select(p => new PluginPermission { PermissionName = p.PermissionName, ClaimName = p.ClaimName, CreatedAt = DateTime.UtcNow, Version = 1, WorkflowState = Constants.WorkflowStates.Created, CreatedByUserId = 1 } ); if (!dbContext.Languages.Any()) { var languages = new List <Language>() { new Language() { CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, Version = 1, WorkflowState = Constants.WorkflowStates.Created, Name = "Danish", LanguageCode = "da" }, new Language() { CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, Version = 1, WorkflowState = Constants.WorkflowStates.Created, Name = "English", LanguageCode = "en-US" }, new Language() { CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, Version = 1, WorkflowState = Constants.WorkflowStates.Created, Name = "German", LanguageCode = "de-DE" } }; dbContext.Languages.AddRange(languages); } dbContext.PluginPermissions.AddRange(newPermissions); dbContext.SaveChanges(); }
public async Task <OperationResult> Update(CalendarUserModel requestModel) { try { // CalendarUser calendarUser = _dbContext.CalendarUsers.FirstOrDefault(x => x.Id == requestModel.Id); // if (calendarUser == null) // { // return new OperationResult(false, // _caseManagementLocalizationService.GetString("CalendarUserNotFound")); // } // // calendarUser.SiteId = requestModel.SiteId; // calendarUser.Color = requestModel.Color; // calendarUser.IsVisibleInCalendar = requestModel.IsVisibleInCalendar; // calendarUser.NameInCalendar = requestModel.NameInCalendar; await requestModel.Update(_dbContext); //TODO // await _dbContext.SaveChangesAsync(); PluginConfigurationValue caseManagementSetting = _dbContext.PluginConfigurationValues.SingleOrDefault(x => x.Name == "CaseManagementBaseSettings:RelatedEntityGroupId"); if (caseManagementSetting != null) { Core core = await _coreHelper.GetCore(); EntityGroup entityGroup = await core.EntityGroupRead(caseManagementSetting.Value); if (entityGroup == null) { return(new OperationResult(false, "Entity group not found")); } int nextItemUid = entityGroup.EntityGroupItemLst.Count; string label = requestModel.NameInCalendar; if (string.IsNullOrEmpty(label)) { label = $"Empty company {nextItemUid}"; } await core.EntityItemUpdate(entityGroup.Id, $"{label}", "", nextItemUid.ToString(), 0); //if (item != null) //{ // entityGroup = core.EntityGroupRead(caseManagementSetting.RelatedEntityGroupId.ToString()); // if (entityGroup != null) // { // foreach (var entityItem in entityGroup.EntityGroupItemLst) // { // if (entityItem.MicrotingUUID == item.MicrotingUUID) // { // calendarUser.RelatedEntityId = entityItem.Id; // } // } // } //} //_dbContext.SaveChanges(); } return(new OperationResult(true, _caseManagementLocalizationService.GetString("CalendarUserUpdatedSuccessfully"))); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationResult(false, _caseManagementLocalizationService.GetString("ErrorWhileUpdatingCalendarUser"))); } }
public async Task <OperationResult> Create(CalendarUserModel calendarUserModel) { try { // CalendarUser calendarUser = new CalendarUser(); // { // SiteId = calendarUserModel.SiteId, // NameInCalendar = calendarUserModel.NameInCalendar, // Color = calendarUserModel.Color, // IsVisibleInCalendar = calendarUserModel.IsVisibleInCalendar, // }; // _dbContext.CalendarUsers.Add(calendarUser); // await _dbContext.SaveChangesAsync(); CalendarUser existingCalendarUser = _dbContext.CalendarUsers.SingleOrDefault(x => x.SiteId == calendarUserModel.SiteId); if (existingCalendarUser == null) { await calendarUserModel.Create(_dbContext); } else { calendarUserModel.Id = existingCalendarUser.Id; calendarUserModel.WorkflowState = Constants.WorkflowStates.Created; await calendarUserModel.Update(_dbContext); } PluginConfigurationValue caseManagementSetting = _dbContext.PluginConfigurationValues.SingleOrDefault(x => x.Name == "CaseManagementBaseSettings:RelatedEntityGroupId"); if (caseManagementSetting != null) { Core core = await _coreHelper.GetCore(); EntityGroup entityGroup = await core.EntityGroupRead(caseManagementSetting.Value); if (entityGroup == null) { return(new OperationResult(false, "Entity group not found")); } int nextItemUid = entityGroup.EntityGroupItemLst.Count; string label = calendarUserModel.NameInCalendar; if (string.IsNullOrEmpty(label)) { label = $"Empty company {nextItemUid}"; } EntityItem item = await core.EntitySelectItemCreate(entityGroup.Id, $"{label}", 0, nextItemUid.ToString()); if (item != null) { entityGroup = await core.EntityGroupRead(caseManagementSetting.Value); if (entityGroup != null) { foreach (EntityItem entityItem in entityGroup.EntityGroupItemLst) { if (entityItem.MicrotingUUID == item.MicrotingUUID) { calendarUserModel.RelatedEntityId = entityItem.Id; } } } } await _dbContext.SaveChangesAsync(); } return(new OperationResult(true, _caseManagementLocalizationService.GetString("CalendarUserHasBeenCreated"))); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationResult(false, _caseManagementLocalizationService.GetString("ErrorWhileCreatingCalendarUser"))); } }
public async Task <string> DownloadEFormPdf(int caseId, string token, string fileType) { PluginConfigurationValue pluginConfigurationValue = await _dbContext.PluginConfigurationValues.SingleOrDefaultAsync(x => x.Name == "ItemsPlanningBaseSettings:Token"); if (token == pluginConfigurationValue.Value) { try { var core = await _core.GetCore(); int eFormId = 0; ItemCase itemCase = await _dbContext.ItemCases.FirstOrDefaultAsync(x => x.Id == caseId); Item item = await _dbContext.Items.SingleOrDefaultAsync(x => x.Id == itemCase.ItemId); ItemList itemList = await _dbContext.ItemLists.SingleOrDefaultAsync(x => x.Id == item.ItemListId); await using MicrotingDbContext microtingDbContext = core.DbContextHelper.GetDbContext(); var locale = await _userService.GetCurrentUserLocale(); Language language = microtingDbContext.Languages.Single(x => x.LanguageCode.ToLower() == locale.ToLower()); if (itemList != null) { eFormId = itemList.RelatedEFormId; } string xmlContent = new XElement("ItemCase", new XElement("ItemId", item.Id), new XElement("ItemNumber", item.ItemNumber), new XElement("ItemName", item.Name), new XElement("ItemDescription", item.Description), new XElement("ItemLocationCode", item.LocationCode), new XElement("ItemBuildYear", item.BuildYear), new XElement("ItemType", item.Type) ).ToString(); if (caseId != 0 && eFormId != 0) { var filePath = await core.CaseToPdf(itemCase.MicrotingSdkCaseId, eFormId.ToString(), DateTime.Now.ToString("yyyyMMddHHmmssffff"), $"{core.GetSdkSetting(Settings.httpServerAddress)}/" + "api/template-files/get-image/", fileType, xmlContent, language); if (!System.IO.File.Exists(filePath)) { throw new FileNotFoundException(); } return(filePath); } else { throw new Exception("could not find case of eform!"); } } catch (Exception exception) { Log.LogException($"ItemListCaseService.DownloadEFormPdf: Got exception {exception.Message}"); throw new Exception("Something went wrong!", exception); } } throw new UnauthorizedAccessException(); }
private async Task <ItemListPnCaseResultListModel> GetTableData(ItemListCasesPnRequestModel requestModel) { PluginConfigurationValue pluginConfigurationValue = await _dbContext.PluginConfigurationValues.SingleOrDefaultAsync(x => x.Name == "ItemsPlanningBaseSettings:Token"); var itemList = await _dbContext.ItemLists.SingleOrDefaultAsync(x => x.Id == requestModel.ListId); var core = await _core.GetCore(); await using MicrotingDbContext microtingDbContext = core.DbContextHelper.GetDbContext(); var locale = await _userService.GetCurrentUserLocale(); Language language = microtingDbContext.Languages.Single(x => x.LanguageCode.ToLower() == locale.ToLower()); List <FieldDto> allFields = await _core.GetCore().Result.Advanced_TemplateFieldReadAll(itemList.RelatedEFormId, language); int i = 0; List <int> toBeRemoved = new List <int>(); foreach (FieldDto field in allFields) { if (field.FieldType == Constants.FieldTypes.SaveButton) { toBeRemoved.Add(i); } i += 1; } foreach (int i1 in toBeRemoved) { allFields.RemoveAt(i1); } ItemListPnCaseResultListModel itemListPnCaseResultListModel = new ItemListPnCaseResultListModel(); itemListPnCaseResultListModel.Total = 0; itemListPnCaseResultListModel.LabelEnabled = itemList.LabelEnabled; itemListPnCaseResultListModel.DescriptionEnabled = itemList.DescriptionEnabled; itemListPnCaseResultListModel.DeployedAtEnabled = itemList.DeployedAtEnabled; itemListPnCaseResultListModel.DoneAtEnabled = itemList.DoneAtEnabled; itemListPnCaseResultListModel.DoneByUserNameEnabled = itemList.DoneByUserNameEnabled; itemListPnCaseResultListModel.UploadedDataEnabled = itemList.UploadedDataEnabled; itemListPnCaseResultListModel.ItemNumberEnabled = itemList.ItemNumberEnabled; itemListPnCaseResultListModel.LocationCodeEnabled = itemList.LocationCodeEnabled; itemListPnCaseResultListModel.BuildYearEnabled = itemList.BuildYearEnabled; itemListPnCaseResultListModel.TypeEnabled = itemList.TypeEnabled; itemListPnCaseResultListModel.NumberOfImagesEnabled = itemList.NumberOfImagesEnabled; itemListPnCaseResultListModel.SdkeFormId = itemList.RelatedEFormId; itemListPnCaseResultListModel.FieldEnabled1 = itemList.SdkFieldEnabled1; if (itemListPnCaseResultListModel.FieldEnabled1) { itemListPnCaseResultListModel.FieldName1 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId1)?.Label; } itemListPnCaseResultListModel.FieldEnabled2 = itemList.SdkFieldEnabled2; if (itemListPnCaseResultListModel.FieldEnabled2) { itemListPnCaseResultListModel.FieldName2 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId2)?.Label; } itemListPnCaseResultListModel.FieldEnabled3 = itemList.SdkFieldEnabled3; if (itemListPnCaseResultListModel.FieldEnabled3) { itemListPnCaseResultListModel.FieldName3 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId3)?.Label; } itemListPnCaseResultListModel.FieldEnabled4 = itemList.SdkFieldEnabled4; if (itemListPnCaseResultListModel.FieldEnabled4) { itemListPnCaseResultListModel.FieldName4 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId4)?.Label; } itemListPnCaseResultListModel.FieldEnabled5 = itemList.SdkFieldEnabled5; if (itemListPnCaseResultListModel.FieldEnabled5) { itemListPnCaseResultListModel.FieldName5 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId5)?.Label; } itemListPnCaseResultListModel.FieldEnabled6 = itemList.SdkFieldEnabled6; if (itemListPnCaseResultListModel.FieldEnabled6) { itemListPnCaseResultListModel.FieldName6 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId6)?.Label; } itemListPnCaseResultListModel.FieldEnabled7 = itemList.SdkFieldEnabled7; if (itemListPnCaseResultListModel.FieldEnabled7) { itemListPnCaseResultListModel.FieldName7 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId7)?.Label; } itemListPnCaseResultListModel.FieldEnabled8 = itemList.SdkFieldEnabled8; if (itemListPnCaseResultListModel.FieldEnabled8) { itemListPnCaseResultListModel.FieldName8 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId8)?.Label; } itemListPnCaseResultListModel.FieldEnabled9 = itemList.SdkFieldEnabled9; if (itemListPnCaseResultListModel.FieldEnabled9) { itemListPnCaseResultListModel.FieldName9 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId9)?.Label; } itemListPnCaseResultListModel.FieldEnabled10 = itemList.SdkFieldEnabled10; if (itemListPnCaseResultListModel.FieldEnabled10) { itemListPnCaseResultListModel.FieldName10 = allFields.SingleOrDefault(x => x.Id == itemList.SdkFieldId10)?.Label; } var newItems = (_dbContext.Items.Where(item => item.ItemListId == requestModel.ListId) .Join(_dbContext.ItemCases, item => item.Id, itemCase => itemCase.ItemId, (item, itemCase) => new { itemCase.Id, item.Name, item.Description, item.BuildYear, item.LocationCode, item.ItemNumber, item.Type, itemCase.MicrotingSdkCaseDoneAt, itemCase.MicrotingSdkCaseId, itemCase.Status, itemCase.CreatedAt, itemCase.DoneByUserName, itemCase.SdkFieldValue1, itemCase.SdkFieldValue2, itemCase.SdkFieldValue3, itemCase.SdkFieldValue4, itemCase.SdkFieldValue5, itemCase.SdkFieldValue6, itemCase.SdkFieldValue7, itemCase.SdkFieldValue8, itemCase.SdkFieldValue9, itemCase.SdkFieldValue10, itemCase.WorkflowState, itemCase.NumberOfImages })); if (requestModel.DateFrom != null) { newItems = newItems.Where(x => x.CreatedAt >= new DateTime(requestModel.DateFrom.Value.Year, requestModel.DateFrom.Value.Month, requestModel.DateFrom.Value.Day, 0, 0, 0)); } if (requestModel.DateTo != null) { newItems = newItems.Where(x => x.CreatedAt <= new DateTime(requestModel.DateTo.Value.Year, requestModel.DateTo.Value.Month, requestModel.DateTo.Value.Day, 23, 59, 59)); } if (!string.IsNullOrEmpty(requestModel.Sort)) { if (requestModel.IsSortDsc) { newItems = newItems .CustomOrderByDescending(requestModel.Sort); } else { newItems = newItems .CustomOrderBy(requestModel.Sort); } } else { newItems = newItems .OrderBy(x => x.Id); } itemListPnCaseResultListModel.Total = newItems.Count(x => x.WorkflowState != Constants.WorkflowStates.Removed); newItems = newItems .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) .Skip(requestModel.Offset) .Take(requestModel.PageSize); itemListPnCaseResultListModel.Items = new List <ItemsListPnCaseResultModel>(); foreach (var item in newItems.ToList()) { Console.WriteLine($"[DBG] ItemListCaseService.GetSingleListResults: Looking at case with id {item.Id} with status {item.Status}"); try { ItemsListPnCaseResultModel newItem = new ItemsListPnCaseResultModel() { Id = item.Id, DoneAt = item.MicrotingSdkCaseDoneAt, DeployedAt = item.CreatedAt, DoneByUserName = item.DoneByUserName, Label = item.Name, Description = item.Description, ItemNumber = item.ItemNumber, LocationCode = item.LocationCode, BuildYear = item.BuildYear, Type = item.Type, NumberOfImages = item.NumberOfImages, Field1 = item.SdkFieldValue1, Field2 = item.SdkFieldValue2, Field3 = item.SdkFieldValue3, Field4 = item.SdkFieldValue4, Field5 = item.SdkFieldValue5, Field6 = item.SdkFieldValue6, Field7 = item.SdkFieldValue7, Field8 = item.SdkFieldValue8, Field9 = item.SdkFieldValue9, Field10 = item.SdkFieldValue10, SdkCaseId = item.MicrotingSdkCaseId, SdkeFormId = itemList.RelatedEFormId, Status = item.Status, Token = pluginConfigurationValue.Value }; itemListPnCaseResultListModel.Items.Add(newItem); } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(itemListPnCaseResultListModel); }