Exemplo n.º 1
0
        public long Add(Warehouse obj)
        {
            //var customer = _customerService.GetByDomain(obj.);

            if (IsDuplicate(obj.WarehouseCode, obj.Id, obj.CustomerId) == false)
            {
                return(_warehouseRepository.Add(obj));
            }
            else
            {
                Expression <Func <Warehouse, bool> > res = x => x.WarehouseCode == obj.WarehouseCode && x.CustomerId == obj.CustomerId && x.IsActive == false;
                var model = _warehouseRepository.Get(res);

                if (model != null)
                {
                    obj.Id       = model.Id;
                    obj.IsActive = true;

                    _warehouseRepository.Detach(model);

                    _warehouseRepository.Update(obj);
                    return(obj.Id);
                }
                else
                {
                    return(0);
                }
            }
        }