public ActionResult <CustomerReadDto> GetCustomerById(int id)
        {
            var customer = _customer.GetCustomerById(id);

            if (customer != null)
            {
                return(Ok(_mapper.Map <CustomerReadDto>(customer)));
            }
            return(NotFound());
        }
示例#2
0
        public OrderModel CalculateOrder(int customerId, List <int> productIDs)
        {
            var customerInfo = _customerRepo.GetCustomerById(customerId).CTM();
            var productInfo  = _productRepo.GetProductsByIDs(productIDs).CTMs();

            var order = CalculateOrder(productInfo, customerInfo.Discounts, customerId,
                                       orderModel => _shippingService.CalculateStuff(customerInfo.Address.ToShipping(), orderModel));

            order.Status  = Order.Enums.OrderStatus.Calculated;
            order.OrderId = _orderRepo.AddOrder(order.CTE());
            return(order);
        }
        public ActionResult <Customer> getCustomerById(int id)
        {
            var customerItem = _repository.GetCustomerById(id);

            if (customerItem != null)
            {
                return(Ok(_mapper.Map <CustomerGetDto>(customerItem)));
            }
            return(NotFound());
        }
        public ActionResult <Customer> GetCustomerById(int id)
        {
            var cust = _repoCust.GetCustomerById(id);

            if (cust != null)
            {
                return(Ok(cust));
            }
            return(NotFound());
        }
        public ActionResult <ReadCustomerDto> GetCustomerById(int id)
        {
            var cuustomer = _repository.GetCustomerById(id);

            if (cuustomer != null)
            {
                return(Ok(_mapper.Map <ReadCustomerDto>(cuustomer)));
            }

            return(NotFound());
        }
        public ActionResult <Customer> GetCustomerById(int Id)
        {
            try
            {
                if (Id <= 0)
                {
                    return(BadRequest());
                }

                var customer = _customerRepo.GetCustomerById(Id);

                if (customer == null)
                {
                    return(NotFound());
                }

                return(Ok(customer));
            }
            catch (Exception)
            {
                return(this.StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError, "Unexpected database error."));
            }
        }
        public ActionResult <Factor> createFactor(FactorPostClass factor)
        {
            // second find customer
            var _customer = _customerRepo.GetCustomerById(factor.customerId);

            if (_customer == null)
            {
                return(NotFound("The customer Not Found"));
            }
            // first find products
            List <OrderItem> _orderItems = new List <OrderItem>();

            foreach (var order in factor.orderItems)
            {
                var p = _productRepo.GetProductById(order.productId);
                if (p == null)
                {
                    return(NotFound("The Product " + order.productId.ToString() + " Not Found"));
                }
                else
                {
                    OrderItem o = new OrderItem {
                        count = order.count, product = p, productId = order.productId
                    };
                    _orderItems.Add(o);
                }
            }
            foreach (var o in _orderItems)
            {
                _orderItemRepo.CreateOrderItem(o);
                _orderItemRepo.SaveChanges();
            }
            Factor f = new Factor {
                orderItems = _orderItems, customer = _customer, customerId = factor.customerId, WriteDate = factor.WriteDate, paymentStatus = 0, total = factor.total
            };

            _repository.CreateFactor(f);
            _repository.SaveChanges();
            return(CreatedAtRoute("GetFactorById", new { Id = f.factorId }, f));
            // third create a Factor Object and save it to DB and return back to client
            // var _factor = _mapper.Map<Factor>(factor);
            // _repository.CreateFactor(_factor);
            // _repository.SaveChanges();
            // return CreatedAtRoute("GetFactorById", new {Id = _factor.factorId}, _factor);
        }
示例#8
0
        // GET: LocationsController/Details/5
        public IActionResult Details(int id)
        {
            var    orders    = _orderRepo.GetOrdersByStoreId(id);
            string storeName = _storeRepo.GetStoreById(id).StoreName;

            ViewData["Store"] = storeName;
            List <OrderViewModel> ViewOrders = new List <OrderViewModel>();

            if (orders.Any())
            {
                foreach (var order in orders)
                {
                    string   customerName          = _customerRepo.GetCustomerById(order.GetCustomerId).CustomerFullName;
                    DateTime time                  = order.GetTime;
                    decimal  total                 = order.GetTotal;
                    Dictionary <string, int> items = new Dictionary <string, int>();
                    foreach (var kvp in order.GetOrderItems)
                    {
                        string productName = _productRepo.GetProductById(kvp.Key).ProductName;
                        items[productName] = kvp.Value;
                    }

                    ViewOrders.Add(new OrderViewModel
                    {
                        Id       = order.OrderId,
                        Store    = storeName,
                        Customer = customerName,
                        Time     = time,
                        Total    = total,
                        Products = items
                    });
                }
            }

            _logger.LogInformation("Retrieving store order history from Locations/Details");
            return(View(ViewOrders));
        }
示例#9
0
 public Customer GetCustomer(int id)
 {
     return(_customerRepo.GetCustomerById(id));
 }
示例#10
0
        // GET: Customer/Details/5
        public IActionResult GetById(int id)
        {
            var customer = _repo.GetCustomerById(id);

            return(View(customer));
        }