public ActionResult EditMeterType(MeterType meterType) { using (var context = new TownUtilityBillSystemEntities()) { if (ModelState.IsValid) { var meterTypeDB = context.METER_TYPE.Find(meterType.Id); meterTypeDB.NAME = meterType.Name; meterTypeDB.UTILITY_ID = meterType.Utility.Id; meterTypeDB.VARIFICATION_PERIOD_YEARS = meterType.VarificationPeriod; context.SaveChanges(); return(RedirectToAction("ShowAllMeterTypes", "Meter")); } var utilitiesDB = context.UTILITY.ToList(); meterType.Utilities = new List <Utility>(); foreach (var u in utilitiesDB) { meterType.Utilities.Add(new Utility() { Id = u.ID, Name = u.NAME }); } return(View()); } }
public ActionResult EditMeter(Meter meter) { using (var context = new TownUtilityBillSystemEntities()) { if (ModelState.IsValid) { var meterDB = context.METER.Find(meter.Id); meterDB.SERIAL_NUMBER = meter.SerialNumber; meterDB.RELEASE_DATE = meter.ReleaseDate; meterDB.VARIFICATION_DATE = meter.VarificationDate; meterDB.METER_TYPE_ID = meter.MeterType.Id; context.SaveChanges(); return(RedirectToAction("ShowFoundMeters", "Meter", new { searchString = meter.SerialNumber })); } var meterTypesDB = context.METER_TYPE.ToList(); meter.MeterTypes = new List <MeterType>(); foreach (var ct in meterTypesDB) { meter.MeterTypes.Add(new MeterType() { Id = ct.ID, Name = ct.NAME }); } return(View(meter)); } }
public ActionResult EditUtility(Utility utility) { using (var context = new TownUtilityBillSystemEntities()) { if (ModelState.IsValid) { var utilityDB = context.UTILITY.Find(utility.Id); utilityDB.NAME = utility.Name; utilityDB.PRICE = utility.Price; if (utilityDB.USAGEFORSTANDARTPRICE != null) { utilityDB.USAGEFORSTANDARTPRICE = utility.UsageForStandartPrice; } if (utilityDB.BIGUSAGEPRICE != null) { utilityDB.BIGUSAGEPRICE = utility.BigUsagePrice; } context.SaveChanges(); return(RedirectToAction("ShowUtility", "Utility", new { utilityName = utilityDB.NAME })); } return(View()); } }
public ActionResult EditMeterData(MeterItem meterItem) { if (ModelState.IsValid) { using (var context = new TownUtilityBillSystemEntities()) { var meterItemDB = context.METER_ITEM.Find(meterItem.Id); meterItemDB.VALUE = meterItem.Value; context.SaveChanges(); return(RedirectToAction("ShowMeterData", "Meter", new { meterId = meterItemDB.METER_ID })); } } return(View()); }
public ActionResult EditCustomer(Customer customer) { using (var context = new TownUtilityBillSystemEntities()) { if (ModelState.IsValid) { var customerDB = context.CUSTOMER.Find(customer.Id); customerDB.ACCOUNT = customer.Account; if (customerDB.SURNAME != null) { customerDB.SURNAME = customer.Surname; } customerDB.NAME = customer.Name; customerDB.EMAIL = customer.Email; customerDB.PHONE = customer.Phone; customerDB.CUSTOMER_TYPE_ID = customer.CustomerType.Id; context.SaveChanges(); List <int> privateTypeIds = GetPrivateCustomerTypeIds(context); if (privateTypeIds.Contains(customer.CustomerType.Id)) { return(RedirectToAction("ShowPrivateCustomers", "Customer")); } else { return(RedirectToAction("ShowLegalCustomers", "Customer")); } } var customerTypesDB = context.CUSTOMER_TYPE.ToList(); customer.CustomerTypes = new List <CustomerType>(); foreach (var ct in customerTypesDB) { customer.CustomerTypes.Add(new CustomerType() { Id = ct.ID, Name = ct.NAME }); } return(View()); } }
public ActionResult PaymentCardForm(PaymentCardModel payment) { Regex regexCardNumber = new Regex("^[0-9]{1,16}$"); Regex regexCardCVV = new Regex("^[0-9]{1,3}$"); DateTime presentDate = DateTime.Today; if (payment.PaymentCard.Number != null) { payment.PaymentCard.Number = payment.PaymentCard.Number.Replace(" ", ""); if (!regexCardNumber.IsMatch(payment.PaymentCard.Number)) { ViewBag.WrongCardNumberError = "The Credit card number must have 16 digits."; } } if (payment.PaymentCard.CVV != null) { if (!regexCardCVV.IsMatch(payment.PaymentCard.CVV)) { ViewBag.WrongCVVError = "The CVV number must have 3 digits."; } } if (payment.PaymentCard.ExpireDate.ToString() != "1/1/0001 12:00:00 AM" && payment.PaymentCard.ExpireDate < presentDate) { ViewBag.WrongExpireDateError = "The card is expired"; } if (ModelState.IsValid) { using (var context = new TownUtilityBillSystemEntities()) { var billDB = context.BILL.Find(payment.Bill.Id); billDB.PAID = true; context.SaveChanges(); return(RedirectToAction("ShowBillPaidInfo", "Bill", new { bill_Id = billDB.ID })); } } return(View(payment)); }