Пример #1
0
        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);
        }
Пример #2
0
        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);
        }