Exemplo n.º 1
0
        public long Add(Brand obj)
        {
            long retId = 0;

            if (obj.ProductId != 0 && obj.ProductId != null)
            {
                var product = _productRepository.GetById(obj.ProductId ?? 0);
                obj.ProductCode = product.ProductCode;
            }
            if (IsDuplicate(obj.Code, obj.Id, obj.CustomerId) == false)
            {
                retId = _brandRepository.Add(obj);
            }
            else
            {
                Expression <Func <Brand, bool> > res;

                res = x => x.Code.ToLower() == obj.Code.ToLower() && x.CustomerId == obj.CustomerId && x.IsActive == false;
                var brand = _brandRepository.Get(res);
                if (brand != null)
                {
                    retId = brand.Id;

                    obj.Id       = retId;
                    obj.IsActive = true;

                    _brandRepository.Detach(brand);

                    _brandRepository.Update(obj);
                    //return obj.Id;
                }
            }

            return(retId);
        }