public CustomerDto Create(CustomerCreateDto model)
        {
            Customer_Category CustomerCategory = _context.Customer_Categories
                                                 .Single(x => x.Customer_CategoryId == model.Customer_CategoryId);

            ApplicationUser user = _context.Users.Single(x => x.Email == model.Email);

            var entry = new Customer
            {
                CustomerName        = model.CustomerName,
                CustomerLastName    = model.CustomerLastName,
                CustomerAge         = model.CustomerAge,
                Customer_CategoryId = model.Customer_CategoryId,
                Customer_Category   = CustomerCategory,
                Email      = user.Email,
                UserEmail  = user.Email,
                User       = user,
                CustomerId = id++
            };

            _context.Customers.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <CustomerDto>(entry));
        }
Example #2
0
        public Customer_CategoryDto Create(Customer_CategoryCreateDto model)
        {
            var entry = new Customer_Category
            {
                Customer_CategoryName        = model.Customer_CategoryName,
                Customer_CategoryDescription = model.Customer_CategoryDescription,
                Customer_CategoryId          = id++
            };

            _context.Customer_Categories.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <Customer_CategoryDto>(entry));
        }
        public CustomerDto Create(CustomerCreateDto model)
        {
            Customer_Category CustomerCategory = _context.Customer_Categories
                                                 .Single(x => x.Customer_CategoryId == model.Customer_CategoryId);

            var entry = new Customer
            {
                CustomerName        = model.CustomerName,
                CustomerAge         = model.CustomerAge,
                Customer_CategoryId = model.Customer_CategoryId,
                Customer_Category   = CustomerCategory,
                CustomerId          = id++
            };

            _context.Customers.Add(entry);
            _context.SaveChanges();

            return(_mapper.Map <CustomerDto>(entry));
        }