static void Main(string[] args) { //Console.WriteLine("Hello World!"); // test WaterConsumption test = new WaterConsumption() { consumptionOfWater = 36685788, executingUnit = "宜蘭縣", populationServed = 421328, remarks = "無", theDailyDomesticConsumptionOfWaterPerPerson = 238, year = "2008-12-31T00:00:00" }; // 序列化 //string jsonData = JsonConvert.SerializeObject(test); //Console.WriteLine(jsonData); List <WaterConsumption> results = new ImportJsonService().read(@"..\..\..\7D1311DD-E1DE-4B01-A5ED-1FC589A7C082.json"); Console.WriteLine(String.Format("全部共有{0}筆資料\n", results.Count)); foreach (WaterConsumption result in results) { Console.WriteLine("ConsumptionOfWater:" + result.consumptionOfWater); Console.WriteLine("ExecutingUnit:" + result.executingUnit); Console.WriteLine("PopulationServed:" + result.populationServed); Console.WriteLine("Remarks:" + result.remarks); Console.WriteLine("TheDailyDomesticConsumptionOfWaterPerPerson:" + result.theDailyDomesticConsumptionOfWaterPerPerson); Console.WriteLine("Year:" + result.year); Console.WriteLine(""); } }
public async Task <WaterConsumption> PutAsync(WaterConsumption water) { _context.waterConsumptions.Add(water); await _context.SaveChangesAsync(); return(water); }
public IActionResult Create(WaterConsumption create) { _context.waterConsumptions.Add(create); _context.SaveChanges(); return(RedirectToAction("Index")); }
public WaterConsumption Insert(WaterConsumption consumption) { var insertedConsumption = WaterConsumptions.Add(consumption); _ctx.SaveChanges(); return(insertedConsumption); }
public IActionResult Edit(WaterConsumption edit) { _context.Entry(edit).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.waterConsumptions.Update(edit); _context.SaveChanges(); return(RedirectToAction("Index")); }
public bool PutWaterConsumption(int id, WaterConsumption wc) { RestClient <WaterConsumption> rc = new RestClient <WaterConsumption>(); rc.WebServiceUrl = "http://localhost:55428/api/waterconsumptions/"; bool response = rc.PutAsync(id, wc); return(response); }
public IHttpActionResult GetWaterConsumption(int id) { WaterConsumption waterConsumption = db.WaterConsumptions.Find(id); if (waterConsumption == null) { return(NotFound()); } return(Ok(waterConsumption)); }
public void Update(WaterConsumption consumption) { var updatedConsumption = WaterConsumptions.FirstOrDefault(x => x.UniqueId == consumption.UniqueId); updatedConsumption.KitchenUnits = consumption.KitchenUnits; updatedConsumption.BathroomUnits = consumption.BathroomUnits; updatedConsumption.UserId = consumption.UserId; updatedConsumption.CreationDate = consumption.CreationDate; _ctx.SaveChanges(); }
public IHttpActionResult PostWaterConsumption(WaterConsumption waterConsumption) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.WaterConsumptions.Add(waterConsumption); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = waterConsumption.WaterConsumptionId }, waterConsumption)); }
public IHttpActionResult DeleteWaterConsumption(int id) { WaterConsumption waterConsumption = db.WaterConsumptions.Find(id); if (waterConsumption == null) { return(NotFound()); } db.WaterConsumptions.Remove(waterConsumption); db.SaveChanges(); return(Ok(waterConsumption)); }
public static WaterConsumptionViewModel ToViewModel(this WaterConsumption item) { return(new WaterConsumptionViewModel { Id = item.UniqueId, BathroomUnits = item.BathroomUnits, KitchenUnits = item.KitchenUnits, CreationDate = item.CreationDate.Value.ToString("MM/dd/yyyy HH:mm"), UserName = item.User.Name, UserId = item.User.UniqueId, MansionId = item.User.Mansion.UniqueId, MansionName = item.User.Mansion.Address }); }
public List <WaterConsumption> read(String filePath) { //反序列化 string jsontext = File.ReadAllText(filePath); // "..\..\..\7D1311DD-E1DE-4B01-A5ED-1FC589A7C082.json" JObject domesticConsumptionOfWater = JObject.Parse(jsontext); var consumption = domesticConsumptionOfWater["TaiwanWaterExchangingData"]["StatisticofWaterResourcesClass"]["TheDomesticConsumptionOfWater"].Children(); // serialize JSON results into .NET objects List <WaterConsumption> results = new List <WaterConsumption>(); foreach (JToken token in consumption) { WaterConsumption water = token.ToObject <WaterConsumption>(); results.Add(water); } return(results); }
public async Task <IActionResult> AddWaterConsumption([Bind("IdWaterConsumption,WarmWater,ColdWater,Date,IdApartment")] WaterConsumption waterConsumption) { var apartment = _context.Apartment.FirstOrDefault(a => a.IdApartment == waterConsumption.IdApartment); // owner of the apartment can add water consumption if (Authentication.Instance.isLoggedIn() && apartment.IdOwner == Authentication.Instance.getCurrentUser().IdOwner) { if (ModelState.IsValid) { _context.Add(waterConsumption); await _context.SaveChangesAsync(); return(Redirect("~/ApartmentsOwned")); } return(View(waterConsumption)); } else { return(Redirect("~/ApartmentsOwned")); } }
public IHttpActionResult PutWaterConsumption(int id, [FromBody] WaterConsumption waterConsumption) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != waterConsumption.WaterConsumptionId) { return(BadRequest()); } //db.Entry(waterConsumption).State = EntityState.Modified; WaterConsumption wc = db.WaterConsumptions.Find(waterConsumption.WaterConsumptionId); wc.Consumption = waterConsumption.Consumption; wc.PricePerUnit = waterConsumption.PricePerUnit; wc.AmountOfMoneyOwed = waterConsumption.AmountOfMoneyOwed; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WaterConsumptionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public WaterConsumption Insert(WaterConsumption consumption) { return(_consumptionRepository.Insert(consumption)); }
public void EvaluateTraits(CreatureManager hManager, string speciesName) { List <Gene> genes = new List <Gene>(); if (!GlobalGEPSettings.RANDOMIZED_TRAITS || traitIndices.Count == 0) { traitIndices = GlobalGEPSettings.speciesTraitLayouts[speciesName]; } foreach (KeyValuePair <string, int[][]> thisTrait in traitIndices) { string key = thisTrait.Key; //For every chromosome a trait is linked to... //i = chromosome index (when a trait is on multiple chromosomes) for (int i = 0; i < thisTrait.Value.Length; i++) { //Index [i][0] will ALWAYS be the chromosome index int chromosomeIndex = thisTrait.Value[i][0]; //For every gene this trait is linked to (on this chromosome)... //j = gene index for this chromosome for (int j = 1; j < thisTrait.Value[i].Length; j++) { //Get the gene index int geneIndex = thisTrait.Value[i][j]; //Add the gene at the chromosomeIndex and geneIndex to a list to be evaluated //Accesses the genome rather than making a copy ensuring the genes accessed later on match exactly the current genome genes.Add(genome[chromosomeIndex].genes[geneIndex]); } } List <Trait> thisTraitList = AccessTraits(genes); //For each trait (keyValuePair) evaluate the genes //Could put the results into a dictionary - this way would be more polymorphic as would search for (or add) a row for each trait and search by name // instead of individual variables, or an array which requires the developer to remember which index is which switch (key.ToLower()) { case "eye left colour": eyeColours[0] = new GeneColour(thisTraitList); if (eyeColours[1] == null && eyeStyle != null) { if (eyeStyle.eyeMatching) { eyeColours[1] = eyeColours[0]; UnityEngine.Debug.Log("Eye Matching, Assigned 1 = 0"); } } break; case "eye right colour": eyeColours[1] = new GeneColour(thisTraitList); if (eyeColours[0] == null && eyeStyle != null) { if (eyeStyle.eyeMatching) { eyeColours[0] = eyeColours[1]; UnityEngine.Debug.Log("Eye Matching, Assigned 0 = 1"); } } break; case "eye style": eyeStyle = new EyeStyle(thisTraitList); if (eyeStyle.eyeMatching) { if (eyeColours[0] != null) { eyeColours[1] = eyeColours[0]; } else if (eyeColours[1] != null) { eyeColours[0] = eyeColours[1]; } else { UnityEngine.Debug.Log("Error: Both eye colours are currently NULL"); } } break; case "hair colour": hairColour = new GeneColour(thisTraitList); break; case "skin colour": skinColour = new GeneColour(thisTraitList); break; case "growth rate": growthRate = new GrowthRate(thisTraitList); break; case "life expectancy": lifeExpectancy = new LifeExpectancy(thisTraitList); break; case "reproductive age": reproductiveAge = new ReproductiveAge(thisTraitList); break; case "gestation period": gestationPeriod = new GestationPeriod(thisTraitList); break; case "energy level": energyLevel = new EnergyLevel(thisTraitList); break; case "energy consumption": energyConsumption = new EnergyConsumption(thisTraitList); break; case "food level": foodLevel = new FoodLevel(thisTraitList); break; case "food consumption": foodConsumption = new FoodConsumption(thisTraitList); break; case "water level": waterLevel = new WaterLevel(thisTraitList); break; case "water consumption": waterConsumption = new WaterConsumption(thisTraitList); break; case "strength": case "intellect": case "constitution": case "wisdom": case "charisma": case "vanity": attributesList.Add(new AttributeTrait(thisTraitList)); break; } genes.Clear(); } }
public void Update(WaterConsumption consumption) { _consumptionRepository.Update(consumption); }
public async Task <IActionResult> MainPage() { // only logged users can see the main page if (Authentication.Instance.isLoggedIn()) { var apartments = _context.Apartment.Include(a => a.IdOwnerNavigation).OrderBy(a => a.IdOwnerNavigation.FullName); var contracts = _context.Contract; var employees = _context.Employee; // total salary of all employees double salarySum = 0; foreach (var employee in employees) { salarySum += employee.Salary; } //number of all association tenants byte totalAssociationTenants = 0; foreach (var apartment in apartments) { if (apartment.NoTenants != null) { totalAssociationTenants += apartment.NoTenants.Value; } } // compute personnel salary tax per tenant double taxPerTenant = salarySum / totalAssociationTenants; foreach (Apartment apartment in apartments) { var waterConsumptions = _context.WaterConsumption.Where(w => w.IdApartment == apartment.IdApartment); var receipts = _context.Receipt.Where(r => r.IdApartment == apartment.IdApartment); DateTime date = DateTime.Now; WaterConsumption oldWaterConsumption = waterConsumptions.FirstOrDefault(w => w.Date.Month != date.Month); // if an old report of water consumption was found if (oldWaterConsumption != null) { // current debt becomes previous debt apartment.PreviousDebt += apartment.CurrentDebt; // delete the report _context.WaterConsumption.Remove(oldWaterConsumption); } apartment.CurrentDebt = 0; var currentWaterConsumption = waterConsumptions.FirstOrDefault(w => w.Date.Month == date.Month); // compute payment for warm and cold water in the current month if (currentWaterConsumption != null) { var warmWaterContract = contracts.FirstOrDefault(c => c.Type == "Warm Water"); var coldWaterContract = contracts.FirstOrDefault(c => c.Type == "Cold Water"); apartment.CurrentDebt += currentWaterConsumption.ColdWater * coldWaterContract.Price + currentWaterConsumption.WarmWater * warmWaterContract.Price; } // for other contracts add tax per tenant foreach (var contract in contracts) { if (contract.Type != "Water") { apartment.CurrentDebt += contract.Price * apartment.NoTenants; } } // add personnel salary tax per tenant apartment.CurrentDebt += apartment.NoTenants * taxPerTenant; //subtract amount from current debt based on receipts var currentReceipts = receipts.Where(r => r.Date.Month == date.Month); foreach (var receipt in currentReceipts) { if (apartment.CurrentDebt != 0) { apartment.CurrentDebt -= receipt.Amount; } else { if (apartment.PreviousDebt != 0) { apartment.PreviousDebt -= receipt.Amount; } } } apartment.CurrentDebt = Math.Round((double)apartment.CurrentDebt, 2); apartment.PreviousDebt = Math.Round((double)apartment.PreviousDebt, 2); apartment.TotalDebt = apartment.PreviousDebt + apartment.CurrentDebt; _context.Update(apartment); } await _context.SaveChangesAsync(); return(View(await apartments.ToListAsync())); } else { return(Redirect("~/Home/Index")); } }
public ActionResult Create(WaterConsumption wc) { PostWaterConsumption(wc); return(RedirectToAction("List")); }
public ActionResult Delete(int id) { WaterConsumption wc = GetWaterConsumptionById(id); return(View(wc)); }
public ActionResult Edit(WaterConsumption wc) { PutWaterConsumption(wc.WaterConsumptionId, wc); return(RedirectToAction("List")); }