public ActionResult <string> IsCustomerAvailabe([FromForm] CustomerTE customer) { var isExistingCustomer = _context.customers.SingleOrDefault(x => x.customermobile == customer.customermobile); if (isExistingCustomer != null) { return(Ok(isExistingCustomer)); } else { return(Ok("Mobile No.Not Registered")); } }
public ActionResult <string> CustomerRegistration([FromForm] CustomerTE customer, bool update) { string Result = ""; //If Want to Update Customer Mobile and Address if (update) { var CustomerDataForUpdate = _context.customers.Single(x => x.CustomerId == customer.CustomerId); if (CustomerDataForUpdate != null) { CustomerDataForUpdate.customermobile = customer.customermobile; CustomerDataForUpdate.Customeraddress = customer.Customeraddress; _context.Entry(CustomerDataForUpdate).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); Result = "Update Successfully"; } } else { bool isAnyData = _context.customers.Any(); if (isAnyData) { int MaxIdValue = _context.customers.Max(x => x.Id); CustomerTE CustwithMaxId = _context.customers.Single(x => x.Id == MaxIdValue); CustomerTE IsExistingCust = _context.customers.SingleOrDefault(x => x.customermobile == customer.customermobile); if (IsExistingCust == null) { //If will get Last row CustId and Increase it By 1 and update CustId with New Customer customer.CustomerId = (Convert.ToInt32(CustwithMaxId.CustomerId) + 1).ToString(); _context.Add(customer); _context.SaveChanges(); Result = "Customer Registered Successfully"; } else { Result = "Mobile No Registered with Mr. " + IsExistingCust.CustomerName; } } else { //First time for creation Customer Table int custId = 10100001; customer.CustomerId = custId.ToString(); _context.Add(customer); _context.SaveChanges(); Result = "Congratulation 1 Customer Registered Successfully"; } } return(Ok(Result)); }
public ActionResult <CustomerTE> GetCustomerById([FromForm] CustomerTE data) { string result = ""; var Customer = _context.customers.SingleOrDefault(x => x.CustomerId == data.CustomerId); if (Customer != null) { return(Ok(Customer)); } else { result = "Customer Not Found!"; return(Ok(result)); } }
public ActionResult <List <PendingBills> > GetPendingBillByCustomerValue([FromForm] PendingBills data) { string TextBoxValue = data.TextBoxValue.Trim(); string SearchCriteria = data.SearchCriteria; string Result = ""; List <PendingBills> PendingBillsWithName = new List <PendingBills>(); CustomerTE Customer = new CustomerTE(); List <BillsPendingTE> PendingBills = new List <BillsPendingTE>(); var isAnyData = _context.billspending.Any(); if (isAnyData) { if (SearchCriteria != "CUSTOMERID") { if (SearchCriteria == "CUSTOMERMOBILE") { Customer = _context.customers.SingleOrDefault(x => x.customermobile == TextBoxValue); if (Customer != null) { PendingBills = _context.billspending. Where(x => x.Customerid.ToString() == Customer.CustomerId && x.Iscompleted == false).ToList(); if (PendingBills == null) { Result = "No Pending Bill Available for" + Customer.CustomerName; } } else { Result = "Match Not Found with Mobile"; } } else if (SearchCriteria == "CUSTOMERNAME") { Customer = _context.customers.SingleOrDefault(x => x.CustomerName.ToUpper() == TextBoxValue.ToUpper()); if (Customer != null) { PendingBills = _context.billspending. Where(x => x.Customerid.ToString() == Customer.CustomerId && x.Iscompleted == false).ToList(); if (PendingBills == null) { Result = "No Pending Bill Available for" + Customer.CustomerName; } } else { Result = "Not Found with Name"; } } } else if (SearchCriteria == "CUSTOMERID") { Customer = _context.customers.SingleOrDefault(x => x.CustomerId == TextBoxValue); if (Customer != null) { PendingBills = _context.billspending.Where(x => x.Customerid.ToString() == TextBoxValue && x.Iscompleted == false).ToList(); if (PendingBills == null) { Result = "No Pending Bill Available for" + Customer.CustomerName; } } else { Result = "Not Found with ID"; } } } // Iterating throug all Pending Bills and adding Customer Name and Mobile if (PendingBills.Count > 0) { foreach (var billData in PendingBills) { PendingBills bill = new PendingBills() { Billnumber = billData.Billnumber.ToString(), Pendingamount = billData.Pendingamount, Customerid = billData.Customerid.ToString(), Customermobile = Customer.customermobile.ToString(), Customername = Customer.CustomerName }; PendingBillsWithName.Add(bill); } return(Ok(PendingBillsWithName)); } else { PendingBillsWithName = null; return(Ok(Result)); } }