public int ValidateCustomer(Common.Customer customer) { int customerId = 0; Customer cust = mapper.Map <Customer>(customer); using (var ctx = new CustomerContext()) { Customer cus = ctx.Customers.Where(x => x.Username == cust.Username && x.Password == cust.Password).FirstOrDefault(); if (cus != null) { customerId = cus.CustomerId; } } return(customerId); }
public int SaveCustomer(Common.Customer customer) { int customerId = 0; Customer cust = mapper.Map <Customer>(customer); using (var ctx = new CustomerContext()) { if (!ctx.Customers.Any(x => x.Username == cust.Username)) { ctx.Customers.Add(cust); int result = ctx.SaveChanges(); customerId = ctx.Customers.Where(x => x.Username == cust.Username).FirstOrDefault().CustomerId; } } return(customerId); }