public decimal WaterDiscTotal(WaterBill waterBill, Tariff tariff)
 {
     decimal totalValue = 0;
     List<decimal> tariffStr = tariff.ParseDiscString(tariff.WaterDiscString);
     if (tariffStr.Count == 5)
     {
         if (waterBill.WaterUsage >= tariffStr[0])
         {
             totalValue += tariffStr[0] * tariffStr[2];
             if (waterBill.WaterUsage < tariffStr[1])
             {
                 totalValue += (waterBill.WaterUsage - tariffStr[0]) * tariffStr[3];
             }
             else
             {
                 totalValue += ((tariffStr[1] - tariffStr[0]) * tariffStr[3]) + ((waterBill.WaterUsage - tariffStr[1]) * tariffStr[4]);
             }
         }
         else
         {
             return waterBill.WaterUsage * tariffStr[2];
         }
         return totalValue;
     }
     return totalValue;
 }
 public decimal GasDiscTotal(GasBill gasBill, Tariff tariff)
 {
     decimal totalValue = 0;
     List<decimal> tariffStr = tariff.ParseDiscString(tariff.GasDiscString);
     if (tariffStr.Count == 5)
     {
         if (gasBill.GasUsage >= tariffStr[0])
         {
             totalValue += tariffStr[0] * tariffStr[2];
             if (gasBill.GasUsage < tariffStr[1])
             {
                 totalValue += (gasBill.GasUsage - tariffStr[0]) * tariffStr[3];
             }
             else
             {
                 totalValue += ((tariffStr[1] - tariffStr[0]) * tariffStr[3]) + ((gasBill.GasUsage - tariffStr[1]) * tariffStr[4]);
             }
         }
         else
         {
             return gasBill.GasUsage * tariffStr[2];
         }
         return totalValue;
     }
     return totalValue;
 }
 public decimal ElectroDiscTotal(ElectroBill electroBill, Tariff tariff)
 {
     decimal totalValue = 0;
     List<decimal> tariffStr = tariff.ParseDiscString(tariff.ElectroDiscString);
     if (tariffStr.Count == 5)
     {
         if (electroBill.ElectroUsage >= tariffStr[0])
         {
             totalValue += tariffStr[0] * tariffStr[2];
             if (electroBill.ElectroUsage < tariffStr[1])
             {
                 totalValue += (electroBill.ElectroUsage - tariffStr[0]) * tariffStr[3];
             }
             else
             {
                 totalValue += ((tariffStr[1] - tariffStr[0]) * tariffStr[3]) + ((electroBill.ElectroUsage - tariffStr[1]) * tariffStr[4]);
             }
         }
         else
         {
             return electroBill.ElectroUsage * tariffStr[2];
         }
         return totalValue;
     }
     return totalValue;
 }
 public ActionResult Edit(Tariff tariff)
 {
     if (ModelState.IsValid)
      {
          repo.SaveTariff(tariff);
          TempData["message"] = string.Format("{0} успешно сохранен", tariff.TariffName);
          return RedirectToAction("List");
      }
      else
      {
          // there is something wrong with the data values
          return View(tariff);
      }
 }
 public void SaveTariff(Tariff tariff)
 {
     if (tariff.Id == 0)
     {
         context.Tariffs.Add(tariff);
     }
     else
     {
         Tariff dbEntry = context.Tariffs.Find(tariff.Id);
         if (dbEntry != null)
         {
             dbEntry.TariffName = tariff.TariffName;
             dbEntry.ElectroTariff = tariff.ElectroTariff;
             dbEntry.GasTariff = tariff.GasTariff;
             dbEntry.WaterTariff = tariff.WaterTariff;
         }
     }
     context.SaveChanges();
 }
 public decimal GasTotal(GasBill gasBill, Tariff tariff)
 {
     return gasBill.GasUsage * tariff.GasTariff;
 }
 public decimal ElectroTotal(ElectroBill electroBill, Tariff tariff)
 {
     return electroBill.ElectroUsage * tariff.ElectroTariff;
 }
 public decimal WaterTotal(WaterBill waterBill, Tariff tariff)
 {
     return waterBill.WaterUsage * tariff.WaterTariff;
 }