public static void AgregarCustomer(CustomerModel newCustomer)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {   //Entidades de la base de datos
                    ProjectHelpers.AppData.Customer customer = new ProjectHelpers.AppData.Customer
                    {
                        CustomerID       = newCustomer.CustomerID,
                        CustomerName     = newCustomer.CustomerName,
                        CustomerLastname = newCustomer.CustomerLastname,
                        Telephone        = newCustomer.Telephone,
                        Address          = "No indica",
                        Email            = newCustomer.Email,
                        ContrasenaEmail  = newCustomer.ContrasenaEmail
                    };
                    db.Customers.Add(customer);
                    db.SaveChanges();

                    Payment payment = new Payment
                    {
                        CartID      = newCustomer.CustomerID,
                        Quantity    = 0,
                        Total       = 0,
                        Description = "Carrito de " + newCustomer.CustomerName
                    };
                    db.Payments.Add(payment);
                    db.SaveChanges();
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
Exemplo n.º 2
0
        public static List <ErrorLogModel> FiltrarErrores(ErrorLogModel modelo)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var logs = from valor in db.ErrorLogs
                               select new ErrorLogModel
                    {
                        LogID       = valor.LogID,
                        LogDate     = valor.LogDate,
                        ErrCode     = valor.ErrCode,
                        Description = valor.Description
                    };

                    if (modelo.EndDate != DateTime.Parse("01/01/0001 12:00:00 a. m."))
                    {
                        logs = logs.Where(valor => valor.LogDate <= modelo.EndDate);
                    }

                    if (modelo.StartDate != DateTime.Parse("01/01/0001 12:00:00 a. m."))
                    {
                        logs = logs.Where(valor => valor.LogDate >= modelo.StartDate);
                    }

                    return(logs.ToList());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
        }
Exemplo n.º 3
0
        public static void AddDB(ProductoModel modelo, TipoPrecioToProduct modeloTipoPrecio)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {
                    string codigoDeProducto = ConsecutivoModel.GetConsecutivo("Productos");
                    //Entidades de la base de datos
                    Product product = new Product
                    {
                        ProductCode        = codigoDeProducto,
                        ProductDescription = modelo.ProductDescription,
                        FoodOptionCode     = modelo.FoodOptionCode,
                        ProductContent     = modelo.ProductContent,
                        ProductImage       = modelo.ProductImage
                    };
                    db.Products.Add(product);
                    db.SaveChanges();

                    PriceTypeToProduct priceToProduct = new PriceTypeToProduct
                    {
                        PriceTypeCode = modeloTipoPrecio.PriceTypeCode,
                        ProductCode   = codigoDeProducto,
                        Price         = modeloTipoPrecio.Price
                    };

                    db.PriceTypeToProducts.Add(priceToProduct);
                    db.SaveChanges();
                    BitacoraModel.AddLogBook("a", "Anadir", Admin.ObtenerIdUsuario());
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
        public static void AddLogBook(string tipo, string description, int userID)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {   //Entidades de la base de datos
                    LogBook log = new LogBook();

                    //Toda la data de la base de datos, se almacena en la lista numeroConsecutivo
                    var numeroConsecutivo = (from valor in db.LogBooks
                                             select valor);

                    //Primary key
                    int code = numeroConsecutivo.Count() + 1;

                    log.LogID       = code;
                    log.UserID      = userID;
                    log.LogDate     = DateTime.Now;
                    log.RegCode     = ConsecutivoModel.GetConsecutivo("Bitacoras");
                    log.LogType     = tipo;
                    log.Description = description;
                    log.RegDetails  = "N/A";
                    //log.User = Admin.ObtenerUsuarioUnico(userID);
                    db.LogBooks.Add(log);
                    db.SaveChanges();
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
        public static void AddDB(ConsecutivoModel consecutivoM)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {
                    //Toda la data de la base de datos, se almacena en la lista numeroConsecutivo
                    var numeroConsecutivo = (from valor in db.Consecutives
                                             select valor);

                    //Primary key
                    int code = numeroConsecutivo.Count() + 1;

                    //Tabla base de datos
                    Consecutive consecutive = new Consecutive
                    {
                        //Dando valor al objeto
                        ConsecutiveCode    = code,
                        Description        = consecutivoM.Description,
                        CurrentConsecutive = consecutivoM.CurrentConsecutive,
                        HasPrefix          = consecutivoM.HasPrefix,
                        Prefix             = consecutivoM.Prefix
                    };

                    //Se agrega el objeto a la base de datos
                    db.Consecutives.Add(consecutive);
                    //Commit a la base de datos
                    db.SaveChanges();
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
Exemplo n.º 6
0
        public static void AddProductDB(ProductoModel modelo, int Carrito)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                var log = (from valor in db.Payments
                           where valor.CartID == Carrito
                           select valor).SingleOrDefault();

                var precio = (from valor in db.PriceTypeToProducts
                              where valor.ProductCode == modelo.ProductCode
                              select valor).SingleOrDefault();


                try
                {
                    //Entidades de la base de datos
                    ProductToCar agregarACarro = new ProductToCar
                    {
                        CartID      = Carrito,
                        ProductCode = modelo.ProductCode,
                        Quantity    = 1,
                    };
                    db.ProductToCars.Add(agregarACarro);
                    db.SaveChanges();

                    log.Quantity = log.Quantity + 1;
                    log.Total    = log.Total + precio.Price;
                    db.SaveChanges();
                    //BitacoraModel.AddLogBook("a", "Anadir", Customer.ObtenerIdCustomer());
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
 public static string GetConsecutivo(string descripcionConsecutivo)
 {
     try
     {
         //Instancia base datos
         efooddatabaseEntities db = new efooddatabaseEntities();
         //Se consulta el currentConsecutive
         var data = (from valor in db.Consecutives
                     where valor.Description == descripcionConsecutivo
                     select valor).SingleOrDefault();
         //Se cambia de formato
         int n = int.Parse(data.CurrentConsecutive);
         //Consecutivo
         string resultado = data.Prefix + n;
         //--Aumenta consecutivo en la base de datos--//
         data.CurrentConsecutive = "" + (n + 1);
         //Actualiza
         db.SaveChanges();
         return(resultado);
     }
     catch (Exception e) {
         ErrorLogModel.AddError(e);
         return(null);
     }
 }
Exemplo n.º 8
0
        public static void DeleteAllPedido(int Carrito)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {
                    var productToCar = (from productos in db.ProductToCars
                                        where productos.CartID == Carrito
                                        select productos);

                    var carrito = (from carro in db.Payments
                                   where carro.CartID == Carrito
                                   select carro).SingleOrDefault();
                    foreach (var item in productToCar)
                    {
                        db.ProductToCars.Remove(item);
                    }
                    db.SaveChanges();

                    carrito.Quantity = 0;
                    carrito.Total    = 0;
                    db.SaveChanges();
                    //BitacoraModel.AddLogBook("a", "Anadir", Customer.ObtenerIdCustomer());
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
Exemplo n.º 9
0
        public static void DeleteProductDB(ProductoModel modelo, int Carrito)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {
                    var log = (from valor in db.Payments
                               where valor.CartID == Carrito
                               select valor).SingleOrDefault();

                    var precio = (from valor in db.PriceTypeToProducts
                                  where valor.ProductCode == modelo.ProductCode
                                  select valor).SingleOrDefault();

                    var productoAEliminar = (from producto in db.ProductToCars
                                             where producto.CartID == Carrito &&
                                             producto.ProductCode == modelo.ProductCode
                                             select producto).SingleOrDefault();

                    log.Quantity = log.Quantity - productoAEliminar.Quantity;
                    log.Total    = log.Total - (precio.Price * productoAEliminar.Quantity);
                    db.SaveChanges();


                    db.ProductToCars.Remove(productoAEliminar);
                    db.SaveChanges();
                    //BitacoraModel.AddLogBook("a", "Anadir", Customer.ObtenerIdCustomer());
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
Exemplo n.º 10
0
        public static List <ConsultaCarrito> CargarCarrito(int idCarrito)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var log = from carrito in db.Payments
                              join productosEnCarrito in db.ProductToCars on carrito.CartID equals productosEnCarrito.CartID
                              join productos in db.Products on productosEnCarrito.ProductCode equals productos.ProductCode
                              join preciosProducto in db.PriceTypeToProducts on productos.ProductCode equals preciosProducto.ProductCode
                              where carrito.CartID == idCarrito

                              select new ConsultaCarrito
                    {
                        CartID             = carrito.CartID,
                        ProductCode        = productos.ProductCode,
                        DescriptionCarrito = carrito.Description,
                        ProductDescription = productos.ProductDescription,
                        PrecioUnitario     = preciosProducto.Price,
                        Quantity           = productosEnCarrito.Quantity,
                        Total        = carrito.Total,
                        ProductImage = productos.ProductImage
                    };

                    return(log.ToList());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
        }
Exemplo n.º 11
0
        public static List <ProductoModel> ObtenerProductosFiltrados(ProductoModel modelo)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var logs = from productos in db.Products
                               select new ProductoModel
                    {
                        ProductCode        = productos.ProductCode,
                        ProductDescription = productos.ProductDescription,
                        FoodOptionCode     = productos.FoodOptionCode,
                        ProductContent     = productos.ProductContent,
                        ProductImage       = productos.ProductImage
                    };

                    if (modelo.FoodOptionCode != null)
                    {
                        logs = logs.Where(producto => producto.FoodOptionCode == modelo.FoodOptionCode);
                    }

                    return(logs.ToList());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
        }
Exemplo n.º 12
0
        public static void EditProductDB(ProductoModel modelo, int Carrito)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {
                    var log = (from valor in db.Payments
                               where valor.CartID == Carrito
                               select valor).SingleOrDefault();

                    var precio = (from valor in db.PriceTypeToProducts
                                  where valor.ProductCode == modelo.ProductCode
                                  select valor).SingleOrDefault();

                    var productoAEditar = (from producto in db.ProductToCars
                                           where producto.CartID == Carrito &&
                                           producto.ProductCode == modelo.ProductCode
                                           select producto).SingleOrDefault();

                    int valorACalcular = productoAEditar.Quantity - modelo.cantidad;

                    if (modelo.cantidad == 0)
                    {
                        DeleteProductDB(modelo, Carrito);
                    }
                    else if (valorACalcular < 0)
                    {
                        // Si la resta del valor actual menos la cantidad nueva ingresada da valores negativo,
                        // este significa que esta agregando más productos.
                        log.Quantity = log.Quantity + Math.Abs(valorACalcular);
                        log.Total    = log.Total + (precio.Price * Math.Abs(valorACalcular));
                        db.SaveChanges();
                    }
                    else if (valorACalcular > 0)
                    {
                        // Si la resta del valor actual menos la cantidad nueva ingresada da valores positivos,
                        // este significa que están eliminando productos.
                        log.Quantity = log.Quantity - Math.Abs(valorACalcular);
                        log.Total    = log.Total - (precio.Price * Math.Abs(valorACalcular));
                        db.SaveChanges();
                    }

                    if (modelo.cantidad != 0)
                    {
                        productoAEditar.Quantity = modelo.cantidad;
                        db.SaveChanges();
                    }

                    //BitacoraModel.AddLogBook("a", "Anadir", Customer.ObtenerIdCustomer());
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
 public static List <TarjetaCreditoDebitoModel> ObtenerTarjetas()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from card in db.Cards
                     select new TarjetaCreditoDebitoModel
             {
                 CardCode = card.CardCode,
                 CardDescription = card.CardDescription,
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
 }
Exemplo n.º 14
0
 public static List <LineaComidaModel> ObtenerLineasComida()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from valor in db.FoodOptions
                     select new LineaComidaModel
             {
                 FoodOptionCode = valor.FoodOptionCode,
                 FoodOptionDescription = valor.FoodOptionDescription,
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
 }
 public static List <TipoPrecioModelo> ObtenerTerritorio()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from territorio in db.PriceTypes
                     select new TipoPrecioModelo
             {
                 PriceTypeCode = territorio.PriceTypeCode,
                 PriceTypeDescription = territorio.PriceTypeDescription,
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x);  return(null); }
 }
Exemplo n.º 16
0
        public static void DeletetDB(LineaComidaModel modelo)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var datos = (from valor in db.FoodOptions
                                 where valor.FoodOptionCode == modelo.FoodOptionCode
                                 select valor).SingleOrDefault();

                    db.FoodOptions.Remove(datos);
                    db.SaveChanges();
                    BitacoraModel.AddLogBook("n", "Borrar", Admin.ObtenerIdUsuario());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); }
        }
        public static void EditDB(TipoPrecioModelo modelo)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var datos = (from valor in db.PriceTypes
                                 where valor.PriceTypeCode == modelo.PriceTypeCode
                                 select valor).SingleOrDefault();

                    datos.PriceTypeDescription = modelo.PriceTypeDescription;
                    db.SaveChanges();
                    BitacoraModel.AddLogBook("e", "Edicion", Admin.ObtenerIdUsuario());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); }
        }
Exemplo n.º 18
0
 public static void AddDB(LineaComidaModel modelo)
 {
     using (efooddatabaseEntities db = new efooddatabaseEntities())
     {
         try
         {   //Entidades de la base de datos
             FoodOption foodOption = new FoodOption
             {
                 FoodOptionCode        = ConsecutivoModel.GetConsecutivo("Líneas de comida"),
                 FoodOptionDescription = modelo.FoodOptionDescription
             };
             db.FoodOptions.Add(foodOption);
             db.SaveChanges();
             BitacoraModel.AddLogBook("a", "Anadir", Admin.ObtenerIdUsuario());
         }
         catch (Exception e) { ErrorLogModel.AddError(e); }
     }
 }
 public static void AddDB(TipoPrecioModelo modelo)
 {
     using (efooddatabaseEntities db = new efooddatabaseEntities())
     {
         try
         {   //Entidades de la base de datos
             PriceType priceType = new PriceType
             {
                 PriceTypeCode        = ConsecutivoModel.GetConsecutivo("Precios"),
                 PriceTypeDescription = modelo.PriceTypeDescription
             };
             db.PriceTypes.Add(priceType);
             db.SaveChanges();
             BitacoraModel.AddLogBook("a", "Anadir", Admin.ObtenerIdUsuario());
         }
         catch (Exception e) { ErrorLogModel.AddError(e); }
     }
 }
Exemplo n.º 20
0
 public static List <ErrorLogModel> CargarErrores()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from valor in db.ErrorLogs
                     select new ErrorLogModel
             {
                 LogID = valor.LogID,
                 LogDate = valor.LogDate,
                 ErrCode = valor.ErrCode,
                 Description = valor.Description
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
 }
 public static List <TiqueteDescuentoModel> ObtenerTiquetesDescuento()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from tiquetes in db.TicketDiscounts
                     select new TiqueteDescuentoModel
             {
                 TicketCode = tiquetes.TicketCode,
                 TicketDescription = tiquetes.TicketDescription,
                 TicketDiscountPercentage = tiquetes.TicketDiscountPercentage,
                 RemainingTickets = tiquetes.RemainingTickets
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x);  return(null); }
 }
 public static void AddDB(TarjetaCreditoDebitoModel modelo)
 {
     using (efooddatabaseEntities db = new efooddatabaseEntities())
     {
         try
         {   //Entidades de la base de datos
             Card newCard = new Card
             {
                 CardCode        = ConsecutivoModel.GetConsecutivo("Tarjetas"),
                 CardDescription = modelo.CardDescription
             };
             db.Cards.Add(newCard);
             db.SaveChanges();
             BitacoraModel.AddLogBook("a", "Anadir", Admin.ObtenerIdUsuario());
         }
         catch (Exception e) { ErrorLogModel.AddError(e); }
     }
 }
        public static void CambiarContrasena(CustomerModel model)
        {
            using (efooddatabaseEntities db = new efooddatabaseEntities())
            {
                try
                {
                    var log = (from customer in db.Customers
                               where customer.CustomerID == model.CustomerID
                               select customer).SingleOrDefault();


                    // Si la resta del valor actual menos la cantidad nueva ingresada da valores positivos,
                    // este significa que están eliminando productos.
                    log.ContrasenaEmail = model.ContrasenaNueva;
                    db.SaveChanges();
                }
                catch (Exception e) { ErrorLogModel.AddError(e); }
            }
        }
Exemplo n.º 24
0
 public static List <ProductoModel> ObtenerProductos()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from productos in db.Products
                     select new ProductoModel
             {
                 ProductCode = productos.ProductCode,
                 ProductDescription = productos.ProductDescription,
                 FoodOptionCode = productos.FoodOptionCode,
                 ProductContent = productos.ProductContent,
                 ProductImage = productos.ProductImage
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
 }
        public static void EditDB(TiqueteDescuentoModel modelo)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var datos = (from valor in db.TicketDiscounts
                                 where valor.TicketCode == modelo.TicketCode
                                 select valor).SingleOrDefault();

                    datos.TicketDescription        = modelo.TicketDescription;
                    datos.TicketDiscountPercentage = modelo.TicketDiscountPercentage;
                    datos.RemainingTickets         = modelo.RemainingTickets;
                    db.SaveChanges();
                    BitacoraModel.AddLogBook("e", "Edicion", Admin.ObtenerIdUsuario());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); }
        }
 public static void AddDB(TipoPrecioToProduct model)
 {
     using (efooddatabaseEntities db = new efooddatabaseEntities())
     {
         try
         {   //Entidades de la base de datos
             PriceTypeToProduct priceType = new PriceTypeToProduct
             {
                 PriceTypeCode = model.PriceTypeCode,
                 ProductCode   = model.ProductCode,
                 Price         = model.Price
             };
             db.PriceTypeToProducts.Add(priceType);
             db.SaveChanges();
             BitacoraModel.AddLogBook("a", "Anadir", Admin.ObtenerIdUsuario());
         }
         catch (Exception e) { ErrorLogModel.AddError(e); }
     }
 }
Exemplo n.º 27
0
        public static void EditDB(ProductoModel modelo)
        {
            try
            {
                using (efooddatabaseEntities db = new efooddatabaseEntities())
                {
                    var datos = (from valor in db.Products
                                 where valor.ProductCode == modelo.ProductCode
                                 select valor).SingleOrDefault();

                    datos.ProductDescription = modelo.ProductDescription;
                    datos.FoodOptionCode     = modelo.FoodOptionCode;
                    datos.ProductContent     = modelo.ProductContent;
                    //datos.ProductImage = null;
                    db.SaveChanges();
                    BitacoraModel.AddLogBook("e", "Edicion", Admin.ObtenerIdUsuario());
                }
            }
            catch (Exception x) { ErrorLogModel.AddError(x); }
        }
 public static void AddDB(TiqueteDescuentoModel modelo)
 {
     using (efooddatabaseEntities db = new efooddatabaseEntities())
     {
         try
         {   //Entidades de la base de datos
             TicketDiscount newTicketDiscount = new TicketDiscount
             {
                 TicketCode               = ConsecutivoModel.GetConsecutivo("Tiquetes de descuento"),
                 TicketDescription        = modelo.TicketDescription,
                 TicketDiscountPercentage = modelo.TicketDiscountPercentage,
                 RemainingTickets         = modelo.RemainingTickets
             };
             db.TicketDiscounts.Add(newTicketDiscount);
             db.SaveChanges();
             BitacoraModel.AddLogBook("a", "Anadir", Admin.ObtenerIdUsuario());
         }
         catch (Exception e) { ErrorLogModel.AddError(e); }
     }
 }
Exemplo n.º 29
0
 public static List <MediosPagoModel> ObtenerMediosDePago()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from metodoDePago in db.PaymentProcessors
                     select new MediosPagoModel
             {
                 PaymentProcessorCode = metodoDePago.PaymentProcessorCode,
                 PaymentProcessorName = metodoDePago.PaymentProcessorName,
                 PaymentProcessorDescription = metodoDePago.PaymentProcessorDescription,
                 PaymentProcessorType = metodoDePago.PaymentProcessorType,
                 PaymentProcessorMethod = metodoDePago.PaymentProcessorMethod,
                 PaymentProcessorStatus = false,
                 PaymentProcessorVerify = false,
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
 }
 public static List <BitacoraModel> CargarErrores()
 {
     try
     {
         using (efooddatabaseEntities db = new efooddatabaseEntities())
         {
             return((from valor in db.LogBooks
                     select new BitacoraModel
             {
                 LogID = valor.LogID,
                 UserID = valor.UserID,
                 LogDate = valor.LogDate,
                 RegCode = valor.RegCode,
                 LogType = valor.LogType,
                 Description = valor.Description,
                 RegDetails = valor.RegDetails
             }).ToList());
         }
     }
     catch (Exception x) { ErrorLogModel.AddError(x); return(null); }
 }