public int AddBeneficiaryCheckDuplicate(BusinessObject.Beneficiary beneficiary) { try { //Re-Map Object to Entity Object var myEntityObj = BeneficiaryMapper.Map <BusinessObject.Beneficiary, Beneficiary>(beneficiary); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { if (db.Beneficiaries.Any()) { if (db.Beneficiaries.Count(m => m.FullName.ToLower().Replace(" ", string.Empty) == beneficiary.FullName.ToLower().Replace(" ", string.Empty) && m.CompanyName.ToLower().Replace(" ", string.Empty) == beneficiary.CompanyName.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } if (db.Beneficiaries.Count(m => m.GSMNO1 == beneficiary.GSMNO1) > 0) { return(-4); } if (db.Beneficiaries.Count(m => m.Email == beneficiary.Email) > 0) { return(-5); } } db.AddToBeneficiaries(myEntityObj); db.SaveChanges(); beneficiary.BeneficiaryId = myEntityObj.BeneficiaryId; return(beneficiary.BeneficiaryId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddBeneficiary(BusinessObject.Beneficiary beneficiary) { try { //Re-Map Object to Entity Object var myEntityObj = BeneficiaryMapper.Map <BusinessObject.Beneficiary, Beneficiary>(beneficiary); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { db.AddToBeneficiaries(myEntityObj); db.SaveChanges(); beneficiary.BeneficiaryId = myEntityObj.BeneficiaryId; return(beneficiary.BeneficiaryId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }