public int CreateMerchant(MerchantCreation merchant) { //validate duplicate //insert merchant try { bool duplicated = ValidateDuplicateEnrollment(merchant); if (duplicated) { return(99); //duplicate exists code } MSQconn con = new MSQconn(ConString); string sql = "insert into Merchant (Name,SettlementAccount,PhoneNumber,EmailAddress,Username,Password,CreatedOn,CreatedBy,Status) values (@Name,@SettlementAccount,@PhoneNumber,@EmailAddress,@Username,@Password,@CreatedOn,@CreatedBy,@Status)"; con.SetSQL(sql); merchant.Password = Helper.Encrypt(merchant.Password); con.AddParam("@Name", merchant.Name); con.AddParam("@SettlementAccount", merchant.SettlementAccount); con.AddParam("@PhoneNumber", merchant.PhoneNumber); con.AddParam("@EmailAddress", merchant.EmailAddress); con.AddParam("@Username", merchant.Username); con.AddParam("@Password", merchant.Password); con.AddParam("@CreatedOn", merchant.CreatedOn); con.AddParam("@Status", merchant.Status); var resp = con.Insert(); int r = Convert.ToInt16(resp); return(r); } catch (Exception ex) { new ErrorLog("merchant creation error:" + ex.ToString()); return(99); //error occored } }
public bool ValidateDuplicateEnrollment(MerchantCreation r) { try { MSQconn con = new MSQconn(ConString); string sql = "Select * from Merchant where PhoneNumber=@PhoneNumber or SettlementAccount=@SettlementAccount or EmailAddress=@EmailAddress"; con.SetSQL(sql); // Dbcon.AddParam("@bvn", r.bvn); con.AddParam("@PhoneNumber", r.PhoneNumber); con.AddParam("@SettlementAccount", r.SettlementAccount); con.AddParam("@EmailAddress", r.EmailAddress); // Dbcon.AddParam("@HandleUsername", r.HandleUsername); DataSet ds = con.Select(); if (ds != null && ds.Tables[0].Rows.Count > 0) { //duplicate return(true); } else { return(false); } } catch (Exception ex) { new ErrorLog("ValidateDuplicateEnrollment error:" + ex.ToString()); return(false); } }