public ActionResult Create(Customers customers) { if (ModelState.IsValid) { db.Customers.Add(customers); db.SaveChanges(); return RedirectToAction("Index"); } return View(customers); }
private int CreateCustomerRecords(string username) { int nCustomerId = 0; Customers customers = new Customers(); customers.CustomerNo = username; customers.BussinesSice = DateTime.Now; db.Customers.Add(customers); db.SaveChanges(); nCustomerId = customers.Id; CustomersContactAddress contactAddress = new CustomersContactAddress(); contactAddress.CustomerId = nCustomerId; contactAddress.Email = username; db.CustomersContactAddresses.Add(contactAddress); db.SaveChanges(); return nCustomerId; }
public ActionResult UpdateCustomer(Customers customer, string CompanyName, string FirtsName, string LastName, string customeremailHlpId) { bool bError = false; string szMsg = ""; IQueryable<Customers> qryCustomer = null; IQueryable<CustomersContactAddress> qryConAdd = null; IQueryable<SalesOrder> qrySalesOrder = null; CustomersContactAddress contactaddress = null; Customers customerHlp = null; SalesOrder salesorder = null; if (ModelState.IsValid) { //validate the Customer No qryCustomer = db.Customers.Where(cst => cst.CustomerNo == customer.CustomerNo); if (qryCustomer.Count() > 0) { customerHlp = qryCustomer.FirstOrDefault<Customers>(); szMsg = string.Format("The Custmer No: {0} is already assigend", customerHlp.CustomerNo); qryConAdd = db.CustomersContactAddresses.Where(cut => cut.CustomerId == customerHlp.Id); if (qryConAdd.Count() > 0) { contactaddress = qryConAdd.FirstOrDefault<CustomersContactAddress>(); if (contactaddress != null) { szMsg = string.Format("The Custmer No: {0} is assigned to {1}", customerHlp.CustomerNo, contactaddress.CompanyName); } } //ModelState.AddModelError("", szMsg); TempData["ErrorCustomer"] = szMsg; bError = true; //Verify the email if (customer.CustomerNo == contactaddress.Email) { bError = false; } //If there is no email, use assign that record if (string.IsNullOrEmpty(contactaddress.Email)) { customerHlp.ASINo = customer.ASINo; customerHlp.BussinesSice = customer.BussinesSice; customerHlp.BussinesType = customer.BussinesType; customerHlp.CreditLimit = customer.CreditLimit; customerHlp.DeptoNo = customer.DeptoNo; customerHlp.Origin = customer.Origin; customerHlp.PaymentTerms = customer.PaymentTerms; customerHlp.PPAINo = customer.PPAINo; customerHlp.SageNo = customer.SageNo; customerHlp.SalesPerson = customer.SalesPerson; customerHlp.SellerPermintNo = customer.SellerPermintNo; customerHlp.Status = customer.Status; //Keep the same Customer No customerHlp.CustomerNo = customerHlp.CustomerNo; db.Entry(customerHlp).State = EntityState.Modified; //Update the Customer address data contactaddress.Email = customeremailHlpId; contactaddress.CompanyName = CompanyName; contactaddress.FirstName = FirtsName; contactaddress.LastName = LastName; db.Entry(contactaddress).State = EntityState.Modified; db.SaveChanges(); //Update the sales order data qrySalesOrder = db.SalesOrders.Where(slor => slor.CustomerId == customer.Id); if (qrySalesOrder.Count() > 0) { foreach (var item in qrySalesOrder) { salesorder = db.SalesOrders.Find(item.SalesOrderId); if (salesorder != null) { salesorder.CustomerId = customerHlp.Id; db.Entry(salesorder).State = EntityState.Modified; } } db.SaveChanges(); } //Delete support data DeleteSupport(customer.Id); bError = false; } if (bError) { return RedirectToAction("Index", new { CreateCustomer = true, CustomerId = customer.Id }); } return RedirectToAction("Index", new { CreateCustomer = false, CustomerId = customer.Id }); } db.Entry(customer).State = EntityState.Modified; qryConAdd = db.CustomersContactAddresses.Where(cut => cut.CustomerId == customer.Id); if (qryConAdd.Count() > 0) { contactaddress = qryConAdd.FirstOrDefault<CustomersContactAddress>(); if (contactaddress != null) { contactaddress.CompanyName = CompanyName; contactaddress.FirstName = FirtsName; contactaddress.LastName = LastName; db.Entry(contactaddress).State = EntityState.Modified; } } db.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Edit(Customers customers) { if (ModelState.IsValid) { db.Entry(customers).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(customers); }
// // GET: /Customers/Create01 public ActionResult Create01() { int nCustomerId = 0; DateTime dDate = DateTime.Now; Customers customers = new Customers(); customers.BussinesSice = dDate; customers.CustomerNo = GetNextCustomerNo(); db.Customers.Add(customers); db.SaveChanges(); nCustomerId = customers.Id; TempData["AddCustomer"] = "AddCustomer"; return RedirectToAction("Edit", new { id = nCustomerId }); }
// // GET: /CustomersAdmin/Create public PartialViewResult Create() { DateTime dDate = DateTime.Now; Customers customers = new Customers(); customers.BussinesSice = dDate; customers.CustomerNo = "0"; return PartialView(customers); }
public ActionResult PaymentListTab(string customerid) { int nId = Convert.ToInt32(customerid); List<KeyValuePair<string, string>> listSelector = new List<KeyValuePair<string, string>>(); //Get theActive/Inactive list listSelector = new List<KeyValuePair<string, string>>(); listSelector.Add(new KeyValuePair<string, string>("Y", "Active")); listSelector.Add(new KeyValuePair<string, string>("N", "Inactive")); SelectList activeinactivelist = new SelectList(listSelector, "Key", "Value"); ViewBag.ActiveInactivelist = activeinactivelist; Customers customer = db.Customers.Find(nId); if (customer == null) { customer = new Customers(); } return View(customer); }
public ActionResult Create(Customers customers) { string szError = string.Empty; IQueryable<Customers> qryCust = null; if (ModelState.IsValid) { //Check CustmerNo does not existe qryCust = db.Customers.Where(cut => cut.CustomerNo == customers.CustomerNo); if (qryCust.Count() > 0) { szError = string.Format("Customer No. {0} already exist.", customers.CustomerNo); ModelState.AddModelError("CustomerNo", szError); return View(customers); } db.Customers.Add(customers); db.SaveChanges(); return RedirectToAction("Index"); } return View(customers); }