Esempio n. 1
0
        public static Order ConvertToDTO(this BB.Core.Model.Order entity)
        {
            var result = new Order();

            result.OrderId = entity.OrderId;
            result.UserID  = entity.UserID;
            result.Date    = entity.StatusUpdates.Max(it => it.Date);
            result.Status  = entity.StatusUpdates.FirstOrDefault(it => it.Date == result.Date).Status;

            foreach (var it in entity.OrderItems)
            {
                result.OrderItems.Add(it.ConvertToDTO());
            }

            return(result);
        }
Esempio n. 2
0
        public IHttpActionResult CreateOrder(long userId)
        {
            var user = db.Users.FirstOrDefault(it => it.UserID == userId);

            if (user == null)
            {
                return(Ok("No user found"));
            }

            var status = new BB.Core.Model.StatusUpdate();

            status.Date   = DateTime.Now;
            status.Status = Status.Cart;

            var newOrder = new BB.Core.Model.Order();

            newOrder.User = user;
            newOrder.StatusUpdates.Add(status);
            db.Orders.Add(newOrder);
            db.SaveChanges();
            return(Ok(new { order = newOrder.ConvertToDTO() }));
        }