Update() public method

public Update ( ) : void
return void
Example #1
0
 public override void Update(GameTime gameTime)
 {
     textArea.Update(gameTime);
     itemList.Update(gameTime);
     commandManager.Update(gameTime);
     if (MissionManager.GetInstance().HasChanged)
     {
         UpdateMissions();
     }
 }
Example #2
0
 public override void Update(GameTime gameTime)
 {
     commandManager.Update(gameTime);
     dialogueOptions.Update(gameTime);
     responseArea.Update(gameTime);
     if (DialogueManager.GetInstance().HasChanged)
     {
         PopulateOptions();
     }
 }
Example #3
0
        public async Task ItemList_Update_DoesUpdate()
        {
            // Arrange
            ItemList itemList = new ItemList
            {
                Name             = Guid.NewGuid().ToString(),
                Description      = Guid.NewGuid().ToString(),
                Enabled          = true,
                RelatedEFormId   = 35,
                RelatedEFormName = Guid.NewGuid().ToString(),
                RepeatType       = RepeatType.Day,
                UpdatedByUserId  = 1,
                CreatedByUserId  = 1,
                RepeatUntil      = new DateTime(2050, 1, 1, 1, 1, 1),
                DayOfWeek        = DayOfWeek.Friday,
                RepeatEvery      = 1,
                DayOfMonth       = 1,
                Version          = 1,
                WorkflowState    = Constants.WorkflowStates.Created,
            };
            await itemList.Create(DbContext);

            // Act
            itemList = await DbContext.ItemLists.FirstOrDefaultAsync();

            string oldName = itemList.Name;

            itemList.Name = "hello";
            await itemList.Update(DbContext);

            List <ItemList>        itemLists        = DbContext.ItemLists.AsNoTracking().ToList();
            List <ItemListVersion> itemListVersions = DbContext.ItemListVersions.AsNoTracking().ToList();

            // Assert
            Assert.AreEqual(1, itemLists.Count);
            Assert.AreEqual(2, itemListVersions.Count);
            Assert.AreEqual(itemList.Name, itemLists[0].Name);
            Assert.AreEqual(itemList.Description, itemLists[0].Description);
            Assert.AreEqual(itemList.Enabled, itemLists[0].Enabled);
            Assert.AreEqual(itemList.UpdatedByUserId, itemLists[0].UpdatedByUserId);
            Assert.AreEqual(itemList.CreatedByUserId, itemLists[0].CreatedByUserId);
            Assert.AreEqual(itemList.RepeatUntil, itemLists[0].RepeatUntil);
            Assert.AreEqual(itemList.DayOfWeek, itemLists[0].DayOfWeek);
            Assert.AreEqual(itemList.RepeatEvery, itemLists[0].RepeatEvery);
            Assert.AreEqual(itemList.RepeatType, itemLists[0].RepeatType);
            Assert.AreEqual(itemList.DayOfMonth, itemLists[0].DayOfMonth);
            Assert.AreEqual(itemList.RelatedEFormId, itemLists[0].RelatedEFormId);
            Assert.AreEqual(itemList.RelatedEFormName, itemLists[0].RelatedEFormName);
            Assert.AreEqual(Constants.WorkflowStates.Created, itemLists[0].WorkflowState);
            Assert.AreEqual(itemList.Id, itemLists[0].Id);
            Assert.AreEqual(2, itemLists[0].Version);

            Assert.AreEqual(oldName, itemListVersions[0].Name);
            Assert.AreEqual(itemList.Description, itemListVersions[0].Description);
            Assert.AreEqual(itemList.Enabled, itemListVersions[0].Enabled);
            Assert.AreEqual(itemList.RepeatType, itemListVersions[0].RepeatType);
            Assert.AreEqual(itemList.RelatedEFormId, itemListVersions[0].RelatedEFormId);
            Assert.AreEqual(itemList.RelatedEFormName, itemListVersions[0].RelatedEFormName);

            Assert.AreEqual(itemList.UpdatedByUserId, itemListVersions[0].UpdatedByUserId);
            Assert.AreEqual(itemList.CreatedByUserId, itemListVersions[0].CreatedByUserId);
            Assert.AreEqual(itemList.RepeatUntil, itemListVersions[0].RepeatUntil);
            Assert.AreEqual(itemList.DayOfWeek, itemListVersions[0].DayOfWeek);
            Assert.AreEqual(itemList.RepeatEvery, itemListVersions[0].RepeatEvery);
            Assert.AreEqual(itemList.Id, itemListVersions[0].ItemListId);
            Assert.AreEqual(Constants.WorkflowStates.Created, itemListVersions[0].WorkflowState);
            Assert.AreEqual(1, itemListVersions[0].Version);
            Assert.AreEqual("hello", itemListVersions[1].Name);
            Assert.AreEqual(itemList.Description, itemListVersions[1].Description);
            Assert.AreEqual(itemList.Enabled, itemListVersions[1].Enabled);
            Assert.AreEqual(itemList.RepeatType, itemListVersions[1].RepeatType);
            Assert.AreEqual(itemList.RelatedEFormId, itemListVersions[1].RelatedEFormId);
            Assert.AreEqual(itemList.RelatedEFormName, itemListVersions[1].RelatedEFormName);

            Assert.AreEqual(itemList.UpdatedByUserId, itemListVersions[1].UpdatedByUserId);
            Assert.AreEqual(itemList.CreatedByUserId, itemListVersions[1].CreatedByUserId);
            Assert.AreEqual(itemList.RepeatUntil, itemListVersions[1].RepeatUntil);
            Assert.AreEqual(itemList.DayOfWeek, itemListVersions[1].DayOfWeek);
            Assert.AreEqual(itemList.RepeatEvery, itemListVersions[1].RepeatEvery);

            Assert.AreEqual(itemList.Id, itemListVersions[1].ItemListId);
            Assert.AreEqual(Constants.WorkflowStates.Created, itemListVersions[1].WorkflowState);
            Assert.AreEqual(2, itemListVersions[1].Version);
        }
        public async Task <OperationResult> Update(ItemsListPnModel updateModel)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                await using var dbContext = core.DbContextHelper.GetDbContext();

                var locale = await _userService.GetCurrentUserLocale();

                Language language = dbContext.Languages.Single(x => x.LanguageCode.ToLower() == locale.ToLower());
                var      template = await _coreHelper.GetCore().Result.TemplateItemRead(updateModel.RelatedEFormId, language);

                var itemsList = new ItemList
                {
                    Id                    = updateModel.Id,
                    RepeatUntil           = updateModel.RepeatUntil,
                    RepeatEvery           = updateModel.RepeatEvery,
                    RepeatType            = updateModel.RepeatType,
                    DayOfWeek             = updateModel.DayOfWeek,
                    DayOfMonth            = updateModel.DayOfMonth,
                    Description           = updateModel.Description,
                    Name                  = updateModel.Name,
                    UpdatedAt             = DateTime.UtcNow,
                    UpdatedByUserId       = UserId,
                    RelatedEFormId        = updateModel.RelatedEFormId,
                    RelatedEFormName      = template?.Label,
                    LabelEnabled          = updateModel.LabelEnabled,
                    DescriptionEnabled    = updateModel.DescriptionEnabled,
                    DeployedAtEnabled     = updateModel.DeployedAtEnabled,
                    DoneAtEnabled         = updateModel.DoneAtEnabled,
                    DoneByUserNameEnabled = updateModel.DoneByUserNameEnabled,
                    UploadedDataEnabled   = updateModel.UploadedDataEnabled,
                    ItemNumberEnabled     = updateModel.ItemNumberEnabled,
                    LocationCodeEnabled   = updateModel.LocationCodeEnabled,
                    BuildYearEnabled      = updateModel.BuildYearEnabled,
                    TypeEnabled           = updateModel.TypeEnabled,
                    NumberOfImagesEnabled = updateModel.NumberOfImagesEnabled,
                    SdkFieldId1           = updateModel.SdkFieldId1,
                    SdkFieldId2           = updateModel.SdkFieldId2,
                    SdkFieldId3           = updateModel.SdkFieldId3,
                    SdkFieldId4           = updateModel.SdkFieldId4,
                    SdkFieldId5           = updateModel.SdkFieldId5,
                    SdkFieldId6           = updateModel.SdkFieldId6,
                    SdkFieldId7           = updateModel.SdkFieldId7,
                    SdkFieldId8           = updateModel.SdkFieldId8,
                    SdkFieldId9           = updateModel.SdkFieldId9,
                    SdkFieldId10          = updateModel.SdkFieldId10,
                    SdkFieldEnabled1      = updateModel.SdkFieldId1 != null,
                    SdkFieldEnabled2      = updateModel.SdkFieldId2 != null,
                    SdkFieldEnabled3      = updateModel.SdkFieldId3 != null,
                    SdkFieldEnabled4      = updateModel.SdkFieldId4 != null,
                    SdkFieldEnabled5      = updateModel.SdkFieldId5 != null,
                    SdkFieldEnabled6      = updateModel.SdkFieldId6 != null,
                    SdkFieldEnabled7      = updateModel.SdkFieldId7 != null,
                    SdkFieldEnabled8      = updateModel.SdkFieldId8 != null,
                    SdkFieldEnabled9      = updateModel.SdkFieldId9 != null,
                    SdkFieldEnabled10     = updateModel.SdkFieldId10 != null,
                    LastExecutedTime      = updateModel.LastExecutedTime
                };
                await itemsList.Update(_dbContext);

                // update current items
                var items = await _dbContext.Items
                            .Where(x => x.ItemListId == itemsList.Id)
                            .ToListAsync();

                foreach (var item in items)
                {
                    var itemModel = updateModel.Items.FirstOrDefault(x => x.Id == item.Id);
                    if (itemModel != null)
                    {
                        item.Description     = itemModel.Description;
                        item.ItemNumber      = itemModel.ItemNumber;
                        item.LocationCode    = itemModel.LocationCode;
                        item.Name            = itemModel.Name;
                        item.UpdatedAt       = DateTime.UtcNow;
                        item.UpdatedByUserId = UserId;
                        item.BuildYear       = itemModel.BuildYear;
                        item.Type            = itemModel.Type;
                        await item.Update(_dbContext);
                    }
                }

                // Remove old
                var itemModelIds   = updateModel.Items.Select(x => x.Id).ToArray();
                var itemsForRemove = await _dbContext.Items
                                     .Where(x => !itemModelIds.Contains(x.Id) && x.ItemListId == itemsList.Id)
                                     .ToListAsync();

                foreach (var itemForRemove in itemsForRemove)
                {
                    await itemForRemove.Delete(_dbContext);
                }

                // Create new
                foreach (var itemModel in updateModel.Items)
                {
                    var item = items.FirstOrDefault(x => x.Id == itemModel.Id);
                    if (item == null)
                    {
                        var newItem = new Item()
                        {
                            LocationCode    = itemModel.LocationCode,
                            ItemNumber      = itemModel.ItemNumber,
                            Description     = itemModel.Description,
                            Name            = itemModel.Name,
                            Version         = 1,
                            WorkflowState   = Constants.WorkflowStates.Created,
                            CreatedAt       = DateTime.UtcNow,
                            CreatedByUserId = UserId,
                            UpdatedAt       = DateTime.UtcNow,
                            Enabled         = true,
                            BuildYear       = itemModel.BuildYear,
                            Type            = itemModel.Type,
                            ItemListId      = itemsList.Id,
                        };
                        await newItem.Save(_dbContext);
                    }
                }

                return(new OperationResult(
                           true,
                           _itemsPlanningLocalizationService.GetString("ListUpdatedSuccessfully")));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                return(new OperationResult(
                           false,
                           _itemsPlanningLocalizationService.GetString("ErrorWhileUpdatingList")));
            }
        }