Exemplo n.º 1
0
        public object Post(Order request)
        {
            if (request.Id != default(uint))
            {
                return new HttpResult(HttpStatusCode.Conflict);
            }

            orderPersister.Create(request);

            return request;
        }
Exemplo n.º 2
0
        public object Get(Order request)
        {
            if (request.Id != default(uint))
            {
                var order = Db.GetById<Order>(request.Id);

                return order;
            }

            return new HttpResult(HttpStatusCode.BadRequest);
        }
Exemplo n.º 3
0
        public object Delete(Order request)
        {
            if (request.Id == default(uint))
            {
                return new HttpResult(HttpStatusCode.BadRequest);
            }

            Db.DeleteById<Order>(request.Id);

            return new HttpResult(HttpStatusCode.OK);
        }
Exemplo n.º 4
0
        public void Create(Order order)
        {
            using (var dbConnection = dbConnectionFactory.Open())
            {
                dbConnection.InsertOnly(order, ev => ev.Insert(o => new {o.Date, o.OrderStatus, o.CancellationReason, o.Total}));

                var orderId = dbConnection.GetLastInsertId();
                order.Id = Convert.ToUInt32(orderId);

                foreach (var orderItem in order.OrderItems)
                {
                    InsertOrderItem(dbConnection, orderItem);
                }
            }
        }
Exemplo n.º 5
0
        public void Update(Order order)
        {
            using (var dbConnection = dbConnectionFactory.Open())
            {
                dbConnection.Save(order);

                foreach (var orderItem in order.OrderItems)
                {
                    if (orderItem.Id == default(uint))
                    {
                        dbConnection.Save(orderItem);
                    }
                    else
                    {
                        InsertOrderItem(dbConnection, orderItem);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public object Put(Order request)
        {
            if (request.Id == default(uint))
            {
                return new HttpResult(HttpStatusCode.BadRequest);
            }

            orderPersister.Update(request);

            return request;
        }