using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace Tango.BL.Entities
{
public partial class Configuration
{
[NotMapped]
[XmlIgnore]
[JsonIgnore]
public IEnumerable<IdsPack> NoneEmptyIdsPacks
{
get { return IdsPacks.Where(x => !x.IsEmpty); }
}
public IEnumerable<IdsPack> GetSupportedIdsPacks(Rml rml)
{
if (rml == null)
{
throw new NullReferenceException("The specified RML cannot be null.");
}
return NoneEmptyIdsPacks.Where(x => rml.LiquidTypesRmls.ToList().Exists(y => y.LiquidType.Guid == x.LiquidType.Guid)).OrderBy(x => x.PackIndex).ToList();
}
public override void DefferedDelete(ObservablesContext context)
{
IdsPacks.ToList().ForEach(x => x.DefferedDelete(context));
var machine_configurations = context.MachinesConfigurations.Where(x => x.Configuration == this);
MachinesConfigurations.ToList().ForEach(x => x.DefferedDelete(context));
base.DefferedDelete(context);
IdsPacks.Clear();
}
public override void Delete(ObservablesContext context)
{
IdsPacks.ToList().ForEach(x => x.DefferedDelete(context));
var machine_configurations = context.MachinesConfigurations.Where(x => x.Configuration == this);
MachinesConfigurations.ToList().ForEach(x => x.DefferedDelete(context));
base.Delete(context);
IdsPacks.Clear();
}
public override Configuration Clone()
{
Configuration cloned = base.Clone();
cloned.CreationDate = DateTime.UtcNow;
foreach (var idsPack in this.IdsPacks)
{
IdsPack clonedPack = idsPack.Clone();
clonedPack.Configuration = cloned;
clonedPack.DispenserType = idsPack.DispenserType;
clonedPack.CartridgeType = idsPack.CartridgeType;
clonedPack.MidTankType = idsPack.MidTankType;
clonedPack.IdsPackFormula = idsPack.IdsPackFormula;
clonedPack.IsEmpty = idsPack.IsEmpty;
cloned.IdsPacks.Add(clonedPack);
}
return cloned;
}
}
}