Ejemplo n.º 1
0
        public static DTOResult GetCustomerOrdersDTO()
        {
            DTOResult dtoResult = new DTOResult();

            try
            {
                //1 - Create instance of the database
                PapaBobsPizzasWebAppEntityModel db = new PapaBobsPizzasWebAppEntityModel();
                //2 - Create instance of target table and convert to a List
                var dbCustomerOrders = db.CustomerOrders.ToList();
                //3 - Create list of target DTO objects
                var dtoCustomerOrders = new List <DTO.CustomerOrderDTO>();
                //4 - Add each DAO to the DTO list
                foreach (var customerorder in dbCustomerOrders)
                {
                    var dtoCustomerOrder = Mapper.Map <DTO.CustomerOrderDTO>(customerorder);
                    if (customerorder.CustomerOrderComplete == 0)
                    {
                        dtoCustomerOrders.Add(dtoCustomerOrder);
                    }
                }
                dtoResult.Success       = true;
                dtoResult.DynamicObject = dtoCustomerOrders;
                return(dtoResult);
            }
            catch (Exception ex)
            {
                dtoResult.Success       = false;
                dtoResult.DynamicObject = ex;
                return(dtoResult);
            }
        }
        public static DTOResult GetPizzaToppingsDTO()
        {
            DTOResult dtoResult = new DTOResult();

            try
            {
                //1 - Create instance of the database
                PapaBobsPizzasWebAppEntityModel db = new PapaBobsPizzasWebAppEntityModel();
                //2 - Create instance of target table and convert to a List
                var dbPizzaToppings = db.PizzaToppings.ToList();
                //3 - Create list of target DTO objects
                var dtoPizzaToppings = new List <DTO.PizzaToppingDTO>();
                //4 - Add each DAO to the DTO list
                foreach (var pizzatopping in dbPizzaToppings)
                {
                    var dtoPizzaTopping = Mapper.Map <DTO.PizzaToppingDTO>(pizzatopping);
                    dtoPizzaToppings.Add(dtoPizzaTopping);
                }
                dtoResult.Success       = true;
                dtoResult.DynamicObject = dtoPizzaToppings;
                return(dtoResult);
            }
            catch (Exception ex)
            {
                dtoResult.Success       = false;
                dtoResult.DynamicObject = ex;
                return(dtoResult);
                //Logger.Instance.Error(result, this);
            }
        }