public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ChargeAmount,Features,BillingPer,IsActive")] PricePlan pricing) { if (id != pricing.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pricing); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PricingExists(pricing.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(pricing)); }
private decimal calculateCost(List <ElectricityReading> electricityReadings, PricePlan pricePlan) { var average = calculateAverageReading(electricityReadings); var timeElapsed = calculateTimeElapsed(electricityReadings); var averagedCost = average / timeElapsed; return(averagedCost * pricePlan.UnitRate); }
// GET: PricePlan/Delete/5 public async Task <ActionResult> Delete(int id) { PricePlan pricePlan = await _pricePlanRepository.GetByIdAsync(id); if (pricePlan == null) { return(HttpNotFound()); } return(View(pricePlan)); }
public PricePlanViewModel Create(PricePlan pricePlan) { return(new PricePlanViewModel() { Description = pricePlan.Description, Id = pricePlan.Id, Name = pricePlan.Name, ProductTypeId = pricePlan.ProductTypeId, ProductTypeName = GetProductTypeNameById(pricePlan.ProductTypeId) }); }
public async Task <IActionResult> Create([Bind("Name,ChargeAmount,Features,BillingPer,IsActive")] PricePlan pricing) { if (ModelState.IsValid) { _context.Add(pricing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pricing)); }
public async Task <ActionResult> Create(CreatePricePlanViewModel pricePlanViewModel) { if (ModelState.IsValid) { var currentUserId = await _customerIdService.GetCustomerId(); var pricePlan = new PricePlan(); Mapper.Map(pricePlanViewModel, pricePlan); pricePlan.CustomerId = currentUserId; await _pricePlanRepository.Add(pricePlan); return(RedirectToAction("Index")); } return(View(pricePlanViewModel)); }
public PricePlanTest() { _pricePlan = new PricePlan { EnergySupplier = Supplier.TheGreenEco, UnitRate = 20m, PeakTimeMultiplier = new List <PeakTimeMultiplier> { new PeakTimeMultiplier { DayOfWeek = DayOfWeek.Saturday, Multiplier = 2m }, new PeakTimeMultiplier { DayOfWeek = DayOfWeek.Sunday, Multiplier = 10m } } }; }
public void ShouldReturnCorrectPriceWhenThereAreTwoPriceUnits() { var plan = new PricePlan(); plan.PriceUnits = new Collection <PriceUnit>(); plan.PriceUnits.Add(new PriceUnit { Height = 200, Width = 350, Price = 5000 }); plan.PriceUnits.Add(new PriceUnit { Height = 210, Width = 360, Price = 7000 }); plan.PriceUnits.Add(new PriceUnit { Height = 220, Width = 370, Price = 7000 }); var price = new PricePlanPriceService().GetPrice(plan, 213, 365); Assert.Equal(7000, price); }
public bool Add(decimal setUpFee, decimal hourlyRate, decimal hourlyDdownTime, out PricePlan newObj) { try { var obj = new PricePlan(); obj.SetUpFee = setUpFee; obj.HourlyRate = hourlyRate; obj.HourlyDdownTime = hourlyDdownTime; this.dbContext.PricePlans.Add(obj); this.dbContext.SaveChanges(); newObj = obj; } catch (Exception) { newObj = null; return(false); } return(true); }
public decimal GetConsumptionCost(List <ElectricityReading> electricityReadings, Supplier supplier) { PricePlan pricePlan = _pricePlans.Find(x => x.EnergySupplier == supplier); return(calculateCost(electricityReadings, pricePlan)); }