public override bool Create(SesionCatado entity) { //Validaciones... Random rnd = new Random(); entity.Id = Convert.ToString(rnd.Next(10000, 99999)); if (sesionCatadoBll.ValidateCreate(entity).StartsWith("Ok")) { MuestraFactoryPrototype muestraPrototype = new MuestraFactoryPrototype(); muestraPrototype.Estado = "Incompleto"; muestraPrototype.Especie = entity.Protocolo; muestraPrototype.IdSesionCatado = entity.Id; for (int i = 1; i <= entity.CantidadMuestras; i++) { Muestra muestraClone = muestraPrototype.CreateMuestra(); muestraClone.Id = Convert.ToString(rnd.Next(10000, 99999)); muestraClone.Identificador = i; ArabicaFactoryPrototype arabicaPrototype = new ArabicaFactoryPrototype(); //----- Arabica arabicaClone = arabicaPrototype.CloneArabica(); arabicaClone.Id = Convert.ToString(rnd.Next(100000, 999999)); arabicaClone.Muestra = muestraClone; entity.Muestras.Add(muestraClone); } _sesionCatadoRepository.Add(entity); _unitOfWork.Commit(); } else { return(false); } return(true); }
public string Create(string idMuestra) { Random rnd = new Random(); //------Preparamos el clon ArabicaFactoryPrototype arabicaPrototype = new ArabicaFactoryPrototype(); arabicaPrototype.IdMuestra = idMuestra; //----- Arabica entity = arabicaPrototype.CloneArabica(); entity.Id = Convert.ToString(rnd.Next(1000000, 9999999)); try { _arabicaRepository.Add(entity); _unitOfWork.Commit(); } catch (Exception ex) { return("Error. " + ex.ToString()); } return("Ok"); }