public ActionResult CustomerReg(Customer customer, CustomerCompleInfo customerCompleInfo) { var isCustomerExist = _context.Customers.Count(c => c.FirstName == customer.FirstName && c.LastName == customer.LastName); if (customer.Id == 0) { if (isCustomerExist != 0) { TempData["notice"] = "Successfully registered"; return(RedirectToAction("New")); } else { customer.RegisteredDateCreated = DateTime.Now; _context.Customers.Add(customer); if (customerCompleInfo.Id == 0) { customerCompleInfo.CustomerId = customer.Id; _context.CustomerCompleInfos.Add(customerCompleInfo); } } } _context.SaveChanges(); return(View()); }
public ActionResult Save(Customer customer, CustomerCompleInfo customerCompleInfo) { var isCustomerExist = _context.Customers.Count(c => c.FirstName == customer.FirstName && c.LastName == customer.LastName); if (customer.Id == 0) { if (isCustomerExist != 0) { TempData["notice"] = "Successfully registered"; return(RedirectToAction("New")); } else { customer.RegisteredDateCreated = DateTime.Now; _context.Customers.Add(customer); if (customerCompleInfo.CivilStatusId != 0 && customerCompleInfo.Id == 0) { customerCompleInfo.CustomerId = customer.Id; _context.CustomerCompleInfos.Add(customerCompleInfo); } } } else { var customerInDb = _context.Customers.Single(c => c.Id == customer.Id); customerInDb.FirstName = customer.FirstName; customerInDb.MiddleName = customer.MiddleName; customerInDb.LastName = customer.LastName; customerInDb.Mobile = customer.Mobile; customerInDb.Sexid = customer.Sexid; customerInDb.NameExtension = customer.NameExtension; var customerCompleteInfo = _context.CustomerCompleInfos.Single(i => i.CustomerId == customer.Id); customerCompleteInfo.Telephone = customerCompleInfo.Telephone; customerCompleteInfo.Email = customerCompleInfo.Email; customerCompleteInfo.Birthdate = customerCompleInfo.Birthdate; customerCompleteInfo.CivilStatusId = customerCompleInfo.CivilStatusId; customerCompleteInfo.PlaceOfBirth = customerCompleInfo.PlaceOfBirth; customerCompleteInfo.Nationality = customerCompleInfo.Nationality; customerCompleteInfo.TaxIdentificationNumber = customerCompleInfo.TaxIdentificationNumber; customerCompleteInfo.CivilStatusId = customerCompleInfo.CustomerTypeId; customerCompleteInfo.LotHouseNumberAndStreet = customerCompleInfo.LotHouseNumberAndStreet; customerCompleteInfo.Barangay = customerCompleInfo.Barangay; customerCompleteInfo.CityMunicipality = customerCompleInfo.CityMunicipality; customerCompleteInfo.Province = customerCompleInfo.Province; customerCompleteInfo.Country = customerCompleInfo.Country; customerCompleteInfo.ZipCode = customerCompleInfo.ZipCode; } try { _context.SaveChanges(); } catch (DbEntityValidationException e) { Console.WriteLine(e); throw; } return(RedirectToAction("Index")); }