public async Task <WasteCollection> AddWasteCollectionAsync(WasteCollection wasteCollection)
        {
            await _appDbContext.WasteCollections.AddAsync(wasteCollection);

            await _appDbContext.SaveChangesAsync();

            return(wasteCollection);
        }
Beispiel #2
0
        /// <summary>
        /// Registers a waste collection to the database context
        /// Calculates points and updates household point balance before storing
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public async Task <WasteCollection> RegisterWasteCollectionAsync(WasteCollection collection)
        {
            RegisterPointsForCollection(collection);
            await Context.WasteCollections.AddAsync(collection);

            await Context.SaveChangesAsync();

            return(collection);
        }
Beispiel #3
0
        private WasteCollection GenerateWasteCollection(Disposer disposer, WasteContainer wasteContainer)
        {
            var wasteCollection = new WasteCollection();

            wasteCollection.Disposer       = disposer;
            wasteCollection.Container      = wasteContainer;
            wasteCollection.GenerationDate = DateTime.Now;

            return(wasteCollection);
        }
Beispiel #4
0
        // User gets points for having less trash collected than the average in the users district
        private void RegisterPointsForCollection(WasteCollection collection)
        {
            var household = Context.Households.Where(x => x.HouseholdId == collection.HouseholdId).FirstOrDefault();

            var districtAverage          = MockedAverageDistributionByDistrict.GetMockedDistribution(household.District);
            var districtAverageTotalBags = districtAverage.PlasticWaste + districtAverage.ResidualWaste + districtAverage.FoodWaste;

            var totalBagsCollected = collection.PlasticWaste + collection.ResidualWaste + collection.FoodWaste;

            var pointsMultiplier = districtAverageTotalBags / totalBagsCollected - 1;
            var pointsGiven      = 100 * pointsMultiplier;

            household.Points += (int)pointsGiven;
        }
Beispiel #5
0
        public async Task <IActionResult> AddAsync(AddWasteCollectionViewModel model)
        {
            if (ModelState.IsValid)
            {
                WasteCollection wasteCollection = new WasteCollection
                {
                    ServiceArea  = model.ServiceArea,
                    Mon          = model.Mon,
                    Tue          = model.Tue,
                    Wed          = model.Wed,
                    Thur         = model.Thur,
                    Fri          = model.Fri,
                    Sat          = model.Sat,
                    Sun          = model.Sun,
                    DateModified = DateTime.Now
                };

                await _wasteCollectionsRepository.AddWasteCollectionAsync(wasteCollection);

                return(RedirectToAction("Complete", new { message = "Waste collection information has been added successfully" }));
            }
            return(View(model));
        }
 public async Task <ActionResult <WasteCollection> > RegisterCollection([FromBody] WasteCollection collection)
 {
     return(Ok(await CollectionService.RegisterWasteCollectionAsync(collection)));
 }
 public async Task <ActionResult <WasteCollection> > RegisterCollectionForSelf([FromBody] WasteCollection collection)
 {
     collection.HouseholdId = HttpContext.User.GetHouseHoldId(Context);
     return(Ok(await CollectionService.RegisterWasteCollectionAsync(collection)));
 }
Beispiel #8
0
 public WasteCollectionModifyViewModel(WasteCollection model)
 {
     m_Model = model;
 }
 public WasteCollectionModifyViewModel CreateWasteCollectionViewModel(WasteCollection wasteCollection)
 {
     return(new WasteCollectionModifyViewModel(wasteCollection));
 }
 public async Task UpdateWasteCollection(WasteCollection updatedWasteCollection)
 {
     _appDbContext.WasteCollections.Update(updatedWasteCollection);
     await _appDbContext.SaveChangesAsync();
 }
 public SelectableWasteCollectionViewModel(WasteCollection wasteCollection)
     : base(false)
 {
     m_Model = wasteCollection;
 }
Beispiel #12
0
 public WasteCollectionEditViewModel(WasteCollection model)
 {
     m_Model = model;
 }
Beispiel #13
0
 public SelectableWasteCollectionViewModel CreateSelectableWasteCollectionViewModel(WasteCollection wasteCollection)
 {
     return(new SelectableWasteCollectionViewModel(wasteCollection));
 }