public IActionResult Post([FromBody] Empdetails empdetails) { try { pokerDAO.insertIntoEmpDetails(empdetails); return(Ok(new { message = "User created with Oracle Id : " + empdetails.EmpOracleId + " and Name : " + empdetails.EmpName })); } catch (System.Exception e) { return(NotFound(new { message = e.Message })); } }
public void insertIntoEmpDetails(Empdetails empdetails) { try { pokerplanningContext context = new pokerplanningContext(); bool empIdResult = context.Empdetails.Any(x => x.EmpOracleId == empdetails.EmpOracleId); if (empIdResult == true) { throw new Exception("Employee is already registered"); } context.Empdetails.Add(empdetails); context.SaveChanges(); } catch (System.Exception e) { throw new Exception(e.Message); } }
public List <Empdetails> getdata() { List <Empdetails> Empdetails = new List <Empdetails>(); // var con = "Server=tcp:sarojwebappdb.database.windows.net,1433;Initial Catalog=sarojwebappdb;Persist Security Info=False;User ID=sarojwebappdb;Password=Saroj@12345678;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";// ConfigurationManager.ConnectionStrings["Yourconnection"].ToString(); var con = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString; using (SqlConnection myConnection = new SqlConnection(con)) { string oString = "Select * from EmpDetails"; SqlCommand oCmd = new SqlCommand(oString, myConnection); //oCmd.Parameters.AddWithValue("@Fname", fName); myConnection.Open(); using (SqlDataReader oReader = oCmd.ExecuteReader()) { int i = 1; while (oReader.Read()) { common cmn = new common(); Empdetails EmpdetailsObj = new Empdetails(); EmpdetailsObj.Name = oReader["Name"].ToString(); EmpdetailsObj.Description = oReader["Description"].ToString(); EmpdetailsObj.DOB = cmn.getDOB(oReader["DOB"].ToString()); EmpdetailsObj.aid = "#" + "div" + i.ToString(); EmpdetailsObj.dvid = "div" + i.ToString(); if (Convert.ToString(oReader["ImagePath"]) == "") { EmpdetailsObj.Image = "NoImage.png"; } else { EmpdetailsObj.Image = oReader["ImagePath"].ToString(); } Empdetails.Add(EmpdetailsObj); i++; } myConnection.Close(); } } return(Empdetails); }