public CustomerOptions CreateCustomer(CustomerOptions customerOptions)
        {
            Customer customer = new Customer  {
                FirstName   = customerOptions.FirstName,
                LastName    = customerOptions.LastName,
                Phone       = customerOptions.Phone,
                Email       = customerOptions.Email,
                VatNumber   = customerOptions.VatNumber,
                Address     = customerOptions.Address,
                Dob         = customerOptions.Dob,
                CreatedDate = DateTime.Now,
                IsActive    = true,
                TotalGross  = 0m
            };

            dbContext.Customers.Add(customer);
            dbContext.SaveChanges();
            return(new CustomerOptions
            {
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                Phone = customer.Phone,
                Email = customer.Email,
                VatNumber = customer.VatNumber,
                Address = customer.Address,
                Dob = customer.Dob,
            });
        }
        public OrderOption CreateOrder(CustomerOptions customerOpt)
        {
            if (customerOpt == null)
            {
                return(null);
            }
            Customer customer = dbContext.Customers.Find(customerOpt.Id);

            if (customer == null)
            {
                return(null);
            }
            Order order = new Order {
                Customer = customer
            };

            dbContext.Orders.Add(order);
            dbContext.SaveChanges();
            OrderOption orderOption = new OrderOption
            {
                CustomerName = customer.FirstName + " " + customer.LastName,
                Id           = order.Id
            };

            return(orderOption);
        }
Exemple #3
0
        ProductOptions IProductService.CreateProduct(ProductOptions productOptions)
        {
            Product product = GetProductFromProductOptions(productOptions);

            dbContext.Products.Add(product);
            dbContext.SaveChanges();
            productOptions.Id = product.Id;
            return(productOptions);
        }
        /// <summary>
        /// Creating a basket. BasketOption contains the CustomerId
        ///                  that we want to relate the basket with
        /// </summary>
        /// <param name="baskOption"></param>
        /// <returns></returns>
        public Basket CreateBasket(BasketOption baskOption)
        {
            CustomerManagement cstMng = new CustomerManagement(db);
            Basket             basket = new Basket
            {
                Customer = cstMng.FindCustomerById(baskOption.CustomerId)
            };

            db.Baskets.Add(basket);
            db.SaveChanges();
            return(basket);
        }
Exemple #5
0
        //CRUD

        /// <summary>
        /// Adding a new product to the db
        /// </summary>
        /// <param name="prodOption"></param>
        /// <returns></returns>
        public Product CreateProduct(ProductOption prodOption)
        {
            Product product = new Product
            {
                Name     = prodOption.Name,
                Price    = prodOption.Price,
                Quantity = prodOption.Quantity
            };

            db.Add(product);
            db.SaveChanges();

            return(product);
        }
        public Product CreateProduct(ProductOptions productOptions)
        {
            Product product = new Product {
                Code        = productOptions.Code,
                Description = productOptions.Description,
                Name        = productOptions.Name,
                Price       = productOptions.Price,
                Quantity    = productOptions.Quantity
            };

            dbContext.Products.Add(product);
            dbContext.SaveChanges();

            return(product);
        }
        //CRUD
        // create read update delete


        /// <summary>
        /// Method for creating a customer
        /// </summary>
        /// <param name="custOption"></param>
        /// <returns></returns>
        public Customer CreateCustomer(CustomerOption custOption)
        {
            Customer customer = new Customer
            {
                FirstName = custOption.FirstName,
                LastName  = custOption.LastName,
                Address   = custOption.Address,
                Dob       = custOption.Dob,
                Email     = custOption.Email,
                Active    = true,
                Balance   = 0,
            };


            db.Customers.Add(customer);
            db.SaveChanges();

            return(customer);
        }
Exemple #8
0
        public Customer CreateCustomer(CustomerOptions customerOptions)
        {
            Customer customer = new Customer {
                Address    = customerOptions.Address,
                CreateDate = DateTime.Now,
                Dob        = customerOptions.Dob,
                Email      = customerOptions.Email,
                FirstName  = customerOptions.FirstName,
                IsActive   = true,
                LastName   = customerOptions.LastName,
                Phone      = customerOptions.Phone,
                TotalGross = 0M,
                VatNumber  = customerOptions.VatNumber,
            };

            using CrmAppDbContext dbContext = new CrmAppDbContext();
            dbContext.Customers.Add(customer);
            dbContext.SaveChanges();


            return(customer);
        }