public ActionResult addNewRepresentative(AddNewRepresentative representative) { int value = new DataAccess.StaffDAL().addNewRepresent(representative); if (value == -1) { //successfully added ViewBag.message = "UnSuccessfull in adding the representative ....Please Try Again"; } else { ViewBag.message = "Successfull in adding the representative .... RepresentativeId = " + value; } return View("successNewRepresentative"); }
//----------------------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------Add New Representative----------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------- public int addNewRepresent(AddNewRepresentative represent) { string connectionString = Connstr(); int repid=-1; string queryString = null; queryString = "INSERT INTO RepDetails(CompanyName,Password,Address,PhoneNumber,EmailID,Training,Workshop,Job,Internship) " + "values(@company,@pass,@addr,@phone,@email,@train,@workshop,@job,@intern) ;"; using (SqlConnection connection = new SqlConnection(connectionString)) { char train = (represent.Training == true) ? 'Y' : 'N'; char workshop = (represent.Workshop == true) ? 'Y' : 'N'; char job = (represent.Job == true) ? 'Y' : 'N'; char intern = (represent.Internship == true) ? 'Y' : 'N'; string password = GetHashedText(represent.Password); SqlCommand command = new SqlCommand(queryString, connection); command.Parameters.AddWithValue("@company",represent.companyName); command.Parameters.AddWithValue("@pass", password); command.Parameters.AddWithValue("@addr", represent.Address); command.Parameters.AddWithValue("@phone", represent.phoneNumber); command.Parameters.AddWithValue("@email", represent.EmailId); command.Parameters.AddWithValue("@train", train); command.Parameters.AddWithValue("@workshop", workshop); command.Parameters.AddWithValue("@job", job); command.Parameters.AddWithValue("@intern", intern); connection.Open(); command.ExecuteNonQuery(); connection.Close(); queryString = "SELECT RepID from RepDetails Where CompanyName=@name COLLATE Latin1_General_CS_AS;"; SqlCommand command1 = new SqlCommand(queryString, connection); command1.Parameters.AddWithValue("@name", represent.companyName); connection.Open(); repid = (int)command1.ExecuteScalar(); connection.Close(); } return repid; }