//detailes customer public CustomerMV Selectcustomer(int id) { var customer = hotel.TBLcustomers.SingleOrDefault(c => c.customerId == id); CustomerMV custtemp = new CustomerMV(); custtemp.customerId = customer.customerId; custtemp.customerName = customer.customerName; custtemp.Email = customer.Email; custtemp.ssnNumber = customer.ssnNumber; custtemp.Phone = customer.Phone; return(custtemp); }
//create new customer public Response createnewcustomer(CustomerMV customer) { Response result = Validatepatient(customer); if (result.IsValid == true) { TBLcustomer customertemp = new TBLcustomer(); customertemp.customerName = customer.customerName; customertemp.Email = customer.Email; customertemp.ssnNumber = customer.ssnNumber; customertemp.Phone = customer.Phone; hotel.TBLcustomers.Add(customertemp); hotel.SaveChanges(); result.SucessMessages.Add("savedate", "save sucess"); } return(result); }
public Response ubdatecustomer(CustomerMV customer) { Response result = Validatepatient(customer); if (result.IsValid == true) { var customertemp = hotel.TBLcustomers.Find(customer.customerId); customertemp.customerName = customer.customerName; customertemp.Email = customer.Email; customertemp.ssnNumber = customer.ssnNumber; customertemp.Phone = customer.Phone; hotel.SaveChanges(); result.SucessMessages.Add("Ubdatedate", "Ubdate sucess"); } return(result); }
//validation customer public Response Validatepatient(CustomerMV viewmodel) { Response result = new Response(); if (string.IsNullOrEmpty(viewmodel.customerName)) { result.ErrorMessages.Add("customerName", "not found name"); } if (string.IsNullOrEmpty(viewmodel.ssnNumber)) { result.ErrorMessages.Add("ssnNumber", "not found name"); } if (string.IsNullOrEmpty(viewmodel.Phone)) { result.ErrorMessages.Add("Phone", "not found name"); } result.IsValid = result.ErrorMessages.Count == 0 ? true : false; return(result); }
public ActionResult EditCustomer(CustomerMV tempcustomer) { Response result = customer.ubdatecustomer(tempcustomer); if (result.IsValid == true) { TempData["customerOPer"] = result.SucessMessages.SingleOrDefault().Value; return(RedirectToAction("Index")); } else { foreach (var item in result.ErrorMessages) { ModelState.AddModelError(item.Key, item.Value); } return(View("Edit", tempcustomer.customerId)); } }