Пример #1
0
        public NewOrderReponse Create(NewOrder order)
        {
            NewOrderReponse response = new NewOrderReponse();

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    var customer = conn.Get <Customers>(order.CustomerId);
                    order.orders.ForEach(item =>
                    {
                        var product         = conn.Get <Products>(item.ProductId);
                        OrderHistory orders = new OrderHistory()
                        {
                            CustomerId   = order.CustomerId,
                            CustomerName = customer.FullName,
                            ProductId    = item.ProductId,
                            ProductName  = product.ProductName,
                            ImageUrl     = product.ImageUrl,
                            UnitPrice    = product.UnitPrice,
                            Quantity     = item.Quantity
                        };
                        conn.Insert(orders);
                    });
                    string sql      = @"select * from products where productid in (
                                SELECT a.productid from orders a 
                                where a.customerid = ?CustomerId and productid not in (select productid from subscriptions where customerid = a.customerid)
                                group by a.productid
                                having count(a.productid) > 1)";
                    var    products = conn.Query <Products>(sql, new { order.CustomerId }).ToList();
                    if (products.Count > 0)
                    {
                        response.SuggestSubscription = true;
                        response.SuggestedProducts   = products;
                    }
                    response.Status      = true;
                    response.Description = "Record saved";
                }
            }
            catch (Exception ex)
            {
                response.Description = ex.Message;
                response.Status      = false;
            }
            return(response);
        }
Пример #2
0
        public NewOrderReponse Create(NewCarts cart)
        {
            NewOrderReponse response = new NewOrderReponse();

            try
            {
                using (IDbConnection conn = GetConnection())
                {
                    var customer = conn.Get <Customers>(cart.CustomerId);

                    response.Status      = true;
                    response.Description = "Record saved";
                }
            }
            catch (Exception ex)
            {
                response.Description = ex.Message;
                response.Status      = false;
            }
            return(response);
        }