public async Task Run([TimerTrigger("0 5 0 * * SUN")] TimerInfo myTimer, ILogger log) { var allTowns = await TownService.GetAllTowns(); foreach (var town in allTowns) { await HistoricalTurnipService.SaveTurnipData(town); var newTown = new TownEntity() { PartitionKey = town.PartitionKey, RowKey = town.RowKey, MayorName = town.MayorName, OwnerUsername = town.OwnerUsername, Created = town.Created, ETag = town.ETag, Name = town.Name, NativeFruit = town.NativeFruit, Timestamp = town.Timestamp, TurnipPrices = "0.0.0.0.0.0.0.0.0.0.0.0.0.0", TurnipsOwned = 0 }; await TownService.UpsertTown(newTown); } }
public void InitializeEntity(TownEntity town) { _entities.Add(town); town.OnTurnPassed .Where(_ => town.Id == _selectedTownId.Value) .Subscribe(_ => _outlineChangeSubject.OnNext(town.Id)) .AddTo(this); }
private void UpdateData(TownEntity entity) { if (view == null) { throw new NullReferenceException(); } view.ShowOverPanel(); view.UpdateOutline(GetTownOutlineData(entity)); }
private void UpdateBuildingContainer(TownEntity entity) { if (townDetailView == null) { throw new NullReferenceException(); } var divisions = entity.Divisions; townDetailView.UpdateBuildingContainer(ConvertBuildingData(divisions)); }
public void Connect(TownEntity start, TownEntity end, int capacity, int length) { if (Routes.Any(route => route.From.Id == start.Id && route.To.Id == end.Id || route.From.Id == end.Id && route.To.Id == start.Id)) { return; } var addRoute = new Route(capacity, length, start, end); Routes.Add(addRoute); }
private void UpdateDivisionContainer(TownEntity entity) { if (townDetailView == null) { throw new NullReferenceException(); } var popData = entity.Pops; var workplaceData = entity.GetWorkplaces(); townDetailView.UpdateDivisionContainer(CreateRowData(popData, workplaceData)); }
public void AddTown(Town town) { using (StoreDBcontext context = new StoreDBcontext()) { TownEntity townEntity = new TownEntity { RegionId = town.RegionId, TownName = town.TownName }; context.SaveChanges(); } }
public void TownInitialize() { races = new List <RaceEntity>(); races.Add(RaceFactory.Create("Race_01", RaceType.HUMAN)); goods = new List <GoodsEntity>(); goods.Add(GoodsFactory.Create(GoodsType.FLOUR, "小麦")); var building = new SimpleProducer("農場", new ProduceAbility(goods.First(), 10), 5); townEntity = TownFactory.Create(0, "town_01", TownType.INLAND, races.First()); townEntity.Build(0, building); }
public async Task <TownEntity> UpsertTown(string userName, string townName, string mayorName, DateTime createdDate, int nativeFruit) { var newTown = new TownEntity() { Name = townName, MayorName = mayorName, OwnerUsername = userName, Created = createdDate, NativeFruit = nativeFruit, TurnipPrices = "0.0.0.0.0.0.0.0.0.0.0.0.0.0", TurnipsOwned = 0, PartitionKey = userName.ToLowerInvariant(), RowKey = townName.ToLowerInvariant() }; return(await UpsertTown(newTown)); }
public async Task <TurnipEntity> SaveTurnipData(TownEntity town) { if (town.TurnipPrices == null || town.TurnipPrices.Length <= 0 || town.TurnipPrices.All(s => s < 20)) { return(null); } var turnipRecord = new TurnipEntity() { MaxProfit = this.CalculateMaxProfit(town.TurnipPrices, town.TurnipsOwned), StartDate = DateTime.Now.AddDays(-7), TurnipPrices = town.TurnipPrices, TurnipsOwned = town.TurnipsOwned, PartitionKey = town.OwnerUsername, RowKey = $"{DateTime.Now.AddDays(-7).Month}.{DateTime.Now.AddDays(-7).Day}.{DateTime.Now.AddDays(-7).Year}.{town.Name.ToLowerInvariant()}" }; await this.StorageService.AddOrUpdate("Turnips", turnipRecord); return(turnipRecord); }
public void AddProduct(Product product) { ProductEntity productEntity = (ProductEntity) new ProductEntity().ConvertFromApplicationModel(product); using (StoreDBcontext context = new StoreDBcontext()) { var town = context.Towns.Where(e => e.TownName == product.Town.TownName && e.RegionId == product.Town.RegionId).FirstOrDefault(); if (town != null) { productEntity.TownId = town.ID; } else { TownEntity townEntity = new TownEntity { TownName = product.Town.TownName, RegionId = product.Town.RegionId }; productEntity.Town = townEntity; } context.Products.Add(productEntity); context.SaveChanges(); } }
public List <IRoute> GetConnectedRoutes(TownEntity town) { return(Routes .Where(route => route.From == town || route.To == town) .ToList()); }
public async Task <TownEntity> UpsertTown(TownEntity updatedTown) { await StorageService.AddOrUpdate("Towns", updatedTown); return(updatedTown); }
private void UpdateDetail(TownEntity entity) { UpdateDivisionContainer(entity); UpdateBuildingContainer(entity); }
private static TownOutlineData GetTownOutlineData(TownEntity entity) => new TownOutlineData(entity.TownName, entity.TownType.GetDescription(), entity.Storages);
public void AttachTowns(TownEntity attachedTown) { Towns.Add(attachedTown); }
public bool IsOwn(TownEntity town) { return(Towns.Contains(town)); }
public void UpdateProduct(Product product) { using (StoreDBcontext context = new StoreDBcontext()) { bool HasChanged = false; var dbProduct = context.Products .Where(e => e.ProductId == product.ProductId).FirstOrDefault(); if (product.Name != dbProduct.Name) { dbProduct.Name = product.Name; HasChanged = true; } if (product.Price != dbProduct.Price) { dbProduct.Price = product.Price; HasChanged = true; } if (product.Description != dbProduct.Description) { dbProduct.Description = product.Description; HasChanged = true; } if (product.Contacts != dbProduct.Contacts) { dbProduct.Contacts = product.Contacts; } if (product.Town.RegionId != dbProduct.Town.RegionId) { dbProduct.Town.RegionId = product.Town.RegionId; HasChanged = true; } if (product.Town.TownName != dbProduct.Town.TownName) { var town = context.Towns.Where(e => e.TownName == product.Town.TownName && e.RegionId == product.Town.RegionId).FirstOrDefault(); if (town != null) { dbProduct.TownId = town.ID; } else { TownEntity townEntity = new TownEntity { TownName = product.Town.TownName, RegionId = product.Town.RegionId }; dbProduct.Town = townEntity; } HasChanged = true; } //Images comparison int currentImagesCount = product.Images.Value.Count; List <ImageEntity> dbImages = dbProduct.Images.OrderBy(e => e.ID).ToList(); if (currentImagesCount > 0) { HasChanged = true; for (int i = 0; i < currentImagesCount; i++) { if (product.Images.Value[i] != null) { if (dbImages.ElementAtOrDefault(i) != null && dbImages.ElementAtOrDefault(i).ImageUrl != product.Images.Value[i].ImageUrl) { int id = dbImages[i].ID; var img = context.Images.Where(e => e.ID == id).FirstOrDefault(); img.ImageUrl = product.Images.Value[i].ImageUrl; } else if (dbImages.ElementAtOrDefault(i) == null) { dbProduct.Images.Add(new ImageEntity().ConvertFromApplicationModel(product.Images.Value[i]) as ImageEntity); } } } } if (HasChanged) { context.SaveChanges(); } } }