예제 #1
0
        public string InsertarVenta(DataModels.Ventas venta, string userCode)
        {
            string logStatus  = string.Empty;
            string logMessage = string.Empty;

            try
            {
                using (var db = new BDEvaluacionVehiculosEntities())
                {
                    if (venta != null && !string.IsNullOrEmpty(userCode))
                    {
                        db.Ventas.Add(venta);
                        db.SaveChanges();
                        string service           = "Venta Patente: " + venta.Patente.ToString() + " Rut Dueño: " + venta.RUTDueno.ToString() + " Total Venta: " + string.Format("{0:C}", venta.TotalVenta);
                        bool   seEliminoVehiculo = EliminarVehiculoDueno(venta);
                        if (seEliminoVehiculo)
                        {
                            var logged = ws.LoggedPurchase(userCode, service);
                            logStatus  = logged.LogStatus;
                            logMessage = logged.LogMessage;
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                }
                return(logStatus + " " + logMessage);
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
예제 #2
0
 public bool CrearVehiculo(DataModels.Vehiculo vehiculo)
 {
     try
     {
         using (var db = new BDEvaluacionVehiculosEntities())
         {
             vehiculo.Patente = FormatoPatente(vehiculo.Patente);
             if (vehiculo.IdDueno != 0)
             {
                 db.Vehiculo.Add(vehiculo);
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #3
0
 public bool EliminarVehiculoDueno(DataModels.Ventas venta)
 {
     DataModels.Vehiculo vehiculo = new Vehiculo();
     try
     {
         using (var db = new BDEvaluacionVehiculosEntities())
         {
             var query = (from oVehiculo in db.Vehiculo
                          join oVenta in db.Ventas
                          on oVehiculo.Patente equals oVenta.Patente
                          where oVehiculo.Patente == venta.Patente
                          select oVehiculo).FirstOrDefault();
             vehiculo = query;
             db.Vehiculo.Attach(vehiculo);
             db.Entry(vehiculo).State = System.Data.EntityState.Deleted;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }