示例#1
0
        public long AddBankBranch(BankBranchObject bankBranch)
        {
            try
            {
                if (bankBranch == null || bankBranch.ImporterId < 1)
                {
                    return(-2);
                }

                var bankEntity = ModelMapper.Map <BankBranchObject, BankBranch>(bankBranch);
                if (bankEntity == null || string.IsNullOrEmpty(bankEntity.Name) || string.IsNullOrEmpty(bankEntity.BranchCode))
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.BankBranches.Count(m => m.Name.ToLower().Trim() == bankBranch.Name.ToLower().Trim() && m.BankId == bankBranch.BankId) > 0)
                    {
                        return(-3);
                    }
                    var bankId = GetBankId(bankBranch.ImporterId);

                    if (bankId < 1)
                    {
                        return(-2);
                    }
                    bankEntity.BankId = bankId;
                    var returnStatus = db.BankBranches.Add(bankEntity);
                    db.SaveChanges();
                    return(returnStatus.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }