Пример #1
0
 public static Entities.Customers MapAllCustomers(Library.Models.Customers customers)
 {
     return(new Entities.Customers
     {
         CustomerId = customers.CustomerId,
         FirstName = customers.FirstName,
         LastName = customers.LastName
     });
 }
        /// <summary>
        /// Used to add customers to the database.
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <returns>Model of the new customer.</returns>
        public Library.Models.Customers AddCustomer(string firstName, string lastName)
        {
            Library.Models.Customers newCustomer = new Library.Models.Customers(firstName, lastName);

            _dbContext.Customers.Add(Mapper.MapAllCustomers(newCustomer));
            try
            {
                _dbContext.SaveChanges();
                logger.Debug($"Database Addition Successful | Customer Id : { newCustomer.CustomerId } First Name : { newCustomer.FirstName } Last Name : { newCustomer.LastName }");
            }
            catch (DbUpdateException ex)
            {
                logger.Error($"Database Update Exception | Adding New Customer Error ({firstName} {lastName}) : {ex}.");
            }

            return(newCustomer);
        }
Пример #3
0
 public static Customer Map(Library.Models.Customers customer) => new Customer
 {
     CustomerId = customer.Id,
     CustName   = customer.Name,
     CustPhone  = customer.Phone
 };