Beispiel #1
0
 public static Models.Orders Map(DataAccess.Orders orders) => new Models.Orders
 {
     Id         = orders.Id,
     TotalDue   = orders.TotalDue,
     OrderTime  = orders.OrderTime,
     PizzaOrder = Map(orders.PizzaOrder).ToList()
 };
        /// <summary>
        /// Delete the given Order from the database
        /// </summary>
        public virtual void Delete(Model.Order delOrder)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, delOrder);

                //Begin Checks
                if (!Exists(delOrder))
                {
                    throw new BusinessException(string.Format("There is no Order with this id. ({0})", delOrder));
                }

                DataAccess.Orders orders = new DataAccess.Orders();
                orders.Delete(delOrder);
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, delOrder);
                throw new BusinessException(string.Format("The Order is still used by {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, delOrder);
                throw;
            }
        }
 /// <summary>
 /// Equals function to compare class
 /// </summary>
 public virtual bool Exists(Int32 id)
 {
     try
     {
         DataAccess.Orders orders = new DataAccess.Orders();
         return(orders.GetById(id) != null);
     }
     catch (Exception ex)
     {
         Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id);
         throw;
     }
 }
 /// <summary>
 /// Get a Order by id from the database
 /// </summary>
 public virtual Model.Order GetById(Int32 id)
 {
     try
     {
         DataAccess.Orders orders = new DataAccess.Orders();
         Model.Order       result = orders.GetById(id);
         return(result);
     }
     catch (Exception ex)
     {
         Trace.WriteError("{0}", Trace.GetMethodName(), CLASSNAME, ex, id);
         throw;
     }
 }
Beispiel #5
0
        public OrderStatus StopOrder(Order order)
        {
            DataAccess.Orders stopOrder = new DataAccess.Orders();

            if (order.StartDate is null)
            {
                return(OrderStatus.Stop_Before_Start);
            }

            order.FinishDate = DateTime.UtcNow;
            order.StartDate  = order.StartDate.Value.ToUniversalTime();
            stopOrder.Modify(order);

            return(OrderStatus.Succes);
        }
Beispiel #6
0
        public List <Model.Order> GetByCode(string code)
        {
            try
            {
                DataAccess.Orders  orders = new DataAccess.Orders();
                List <Model.Order> result = orders.GetByCode(code);

                return(result);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, code);
                throw;
            }
        }
Beispiel #7
0
        public List <Model.Order> GetAllHistory()
        {
            try
            {
                DataAccess.Orders  orders = new DataAccess.Orders();
                List <Model.Order> result = orders.GetAllHistory();

                return(ChangeTimes(result));
            }
            catch (Exception ex)
            {
                Trace.WriteError("()", Trace.GetMethodName(), CLASSNAME, ex);
                throw;
            }
        }
        /// <summary>
        /// Get a Order by ResourceId from the database
        /// </summary>
        public virtual List <Model.Order> GetByResourceId(Int32 resourceId)
        {
            try
            {
                DataAccess.Orders  orders = new DataAccess.Orders();
                List <Model.Order> result = orders.GetByResourceId(resourceId);

                return(result);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, resourceId);
                throw;
            }
        }
Beispiel #9
0
        public OrderStatus StartOrder(Order orderToStart)
        {
            DataAccess.Orders  orders             = new DataAccess.Orders();
            List <Model.Order> actualOrdersResult = orders.GetAllActual();

            foreach (Model.Order actualOrder in actualOrdersResult)
            {
                if (actualOrder.StartDate != null && actualOrder.ResourceId == orderToStart.ResourceId)
                {
                    return(OrderStatus.Resource_in_use);
                }
            }

            orderToStart.StartDate = DateTime.UtcNow;
            orders.Modify(orderToStart);

            return(OrderStatus.Succes);
        }
        /// <summary>
        /// Modify only the specified properties of the Order
        /// specified by:
        /// </summary>
        /// <param name="id">PK</param>
        /// <param name="propValues">Properties to change</param>
        public virtual void Modify(Int32 id, params KeyValuePair <string, object>[] propValues)
        {
            try
            {
                Trace.WriteInformation("({0}, {1})", Trace.GetMethodName(), CLASSNAME, id, string.Join(",", propValues));

                DataAccess.Orders orders = new DataAccess.Orders();
                orders.Modify(
                    id,
                    propValues);
                return;
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, id);
                throw;
            }
        }
        /// <summary>
        /// Add a new Order to the database
        /// </summary>
        public virtual Int32 Add(Model.Order newOrder)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, newOrder);

                CheckConstraints(newOrder);
                DataAccess.Orders orders = new DataAccess.Orders();

                return(orders.Add(newOrder));
            }
            catch (DalForeignKeyException ex_fk)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex_fk, newOrder);
                throw new BusinessException(string.Format("No related object found in {0}", ex_fk.Table), ex_fk);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, newOrder);
                throw;
            }
        }
        /// <summary>
        /// Modify the given Order in the database
        /// </summary>
        public virtual void Modify(Model.Order modifiedOrder)
        {
            try
            {
                Trace.WriteInformation("({0})", Trace.GetMethodName(), CLASSNAME, modifiedOrder);

                //Begin Checks
                CheckConstraints(modifiedOrder);

                if (!Exists(modifiedOrder))
                {
                    throw new BusinessException(string.Format("There is no Order with this id. ({0})", modifiedOrder));
                }

                DataAccess.Orders orders = new DataAccess.Orders();
                orders.Modify(modifiedOrder);
            }
            catch (Exception ex)
            {
                Trace.WriteError("({0})", Trace.GetMethodName(), CLASSNAME, ex, modifiedOrder);
                throw;
            }
        }