0

Estoy desarrollando una aplicación con ASP.NET MVC usando Visual Studio 2017 aplicando el enfoque de Code First. Tengo tres clases (tablas) en el modelo, una es un repositorio llamado DataBase y una interfaz IDataBase. Estoy almacenando datos en la memoria sin usar db. Esta es mi clase "FacturadeArticulo"

public class FacturadeArticulo   {
public int ID { get; set; }
public Nullable<int> InvoiceID { get; set; }
public string ArticleNumber { get; set; }
[DataType(DataType.MultilineText)]
public string ArticleDescription { get; set; }
public Nullable<int> Quantity { get; set; }
public Nullable<decimal> PricePerUnit { get; set; }
public Nullable<decimal> TaxPercentage { get; set; }
public Nullable<decimal> NettoAmount { get; set; }
public Nullable<decimal> BruttoAmount { get; set; }

public virtual Supplier Supplier { get; set; }
public virtual Invoice Invoice { get; set; }}

Mi pregunta es: Como puedo calcular los valores en esta Classe: (Quantity*PricePerUnit =NettoAmount) y ((PricePerUnit * TaxPercentage) / 100 + PricePerUnit*Quantity=BruttoAmount). ¿Es esto posible? Repositorio DataBase:

public class DataBase:IDataBase{   
private static List<Supplier> suppliers = new List<Supplier>();
private static List<Invoice> invoices = new List<Invoice>();
private static List<FacturadeArticulo> facturadeArticulos = new List<FacturadeArticulo>();

private static int _nextId = 1;

public DataBase()
{     
}
public FacturadeArticulo Add(FacturadeArticulo item)
{
    if (item == null)
    {
        throw new ArgumentNullException("item");
    }
    // TO DO : Code to save record into database 
    item.ID = _nextId++;
    facturadeArticulos.Add(item);
    return item;
} public IEnumerable<FacturadeArticulo> getAll()
{    
    return facturadeArticulos;
}
1
  • estas seguro que la cantidad el precio unitario pueden ser un dato null ? debeeria ser obligatorios el 11 nov. 2018 a las 16:26

1 respuesta 1

1

Podrias definir la propiedad como la formula que describes

public Nullable<decimal> NettoAmount { 
   get{
       if(this.Quantity == null || this.PricePerUnit == null)
          return null;

       return this.Quantity.Value * this.PricePerUnit.Value; 
   }
}



public Nullable<decimal> NettoAmount { 
   get{
       if(this.Quantity == null 
           || this.PricePerUnit == null 
           || this.TaxPercentage == null)
          return null;

       return ((this.PricePerUnit.Value * this.TaxPercentage.Value) / 100 + this.PricePerUnit.Value * this.Quantity.Value); 
   }
}

como veras son propiedades get ya que solo podras obtener el resultado, son de solo lectura

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.