| 1234567891011121314151617181920212223242526272829303132 | using System.Linq;using Comal.Classes;using InABox.Core;namespace Comal.Stores{    public class StockWarehouseStore : BaseStore<StockWarehouse>    {        protected override void BeforeSave(StockWarehouse entity)        {            base.BeforeSave(entity);            // Try to make sure there is one and one only default warehouse            var otherdefaults = Provider.Query(                new Filter<StockWarehouse>(x => x.ID).IsNotEqualTo(entity.ID).And(x => x.Default).IsEqualTo(true),                new Columns<StockWarehouse>(x => x.ID, x => x.Default)            ).Rows.Select(x => x.ToObject<StockWarehouse>()).ToArray();            if (!entity.Default)                if (!otherdefaults.Any())                    entity.Default = true;            if (entity.Default)            {                entity.Active = true;                foreach (var otherdefault in otherdefaults)                    otherdefault.Default = false;                Provider.Save(otherdefaults);            }        }    }}
 |