I have a use case like I have a school having two branches in two different cities like say one branch is in taxas and one is in dallas , Now I would like to have an API which would work two ways , Like when some student comes to get register him/her self in DALLAS then It will first check if the statudent ID already exists in TAXAS branch then it does not allow to enroll him in Dallas , and if someone come to TAXAS but if that student already exists in DALLAS then it should not allow him to enroll as it is two way process how I can achieve it
Loading

Satyaprakash SamantarayRank #101 · 21.1K reputationPosted Dec 7, 2023, 3:26 AM EST
You need to create web api and u can refer from here (https://tinyurl.com/4d64rk9w) and dulicate functionality Web API and for duplicacy need to create SP and there u need to put logic and make sp parameters as per ur table definitions. No need to create 2 branches u can do it under one web api controller and a table.
CREATE PROCEDURE [dbo].[branch] @username varchar(20), @pword nvarchar(20), @empname varchar(20), @email nvarchar(50), @designation varchar(20), @reportto varchar(20) AS IF (SELECT COUNT(*) FROM Users WHERE username= @username) < 1 BEGIN INSERT INTO branchUsers(username,pword,empname,email,designation,reportto) VALUES(@username,@pword,@empname,@email,@designation,@reportto) ENDPakeeza172 reputationPosted Dec 7, 2023, 3:32 AM EST
Thanks Jayraj Chhaya for the response , my basic question was how two way communication can handle at the same time using web api like If I say the How this same API save the data at one use case and Pass the data to another school as second use case .
Pakeeza172 reputationPosted Dec 7, 2023, 3:37 AM EST
thanks for all the responses Let me clear the picture .
Unfortunately I need to modify my question a bit, Like I need to have one API which would work for saving as well as passing the flag or a bit value to another school like say
DALLA: CAN ENROLL THE STUDENTS ONLY UPTO FIVE CLASS
TAXAS: CAN ENROLL THE STUDENT AFTER FIFTH CLASS LIKE 6,7,8
SO when some students comes to DALLAS the API need to check if it need to be enrolled less then five class then it wil enroll if not then it will return something so that the other side the TAXAS API consumer knows that its my student and they can enroll , how same api can be consumed at both school to achive this
Sam HobbsRank #107 · 20.5K reputationPosted Dec 7, 2023, 4:54 PM EST
I do not know what Taxas is. Do you mean Texas or taxes? Note that Texas is a state. Dallas is a city in Texas.
Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 7, 2023, 1:00 AM EST
To achieve the desired functionality, you can create a C# web API using the ASP.NET Core framework. Here's a step-by-step guide on how to implement the two-way enrollment process:
Set up the API project: Create a new ASP.NET Core Web API project in Visual Studio or your preferred development environment.
Define the data model: Create a Student class with properties like StudentId, Name, Branch, etc. This class will represent the student entity in your application.
public class Student { public int StudentId { get; set; } public string Name { get; set; } public string Branch { get; set; } }[HttpPost("enroll")] public IActionResult EnrollStudent(Student student) { // Check if the student ID exists in the other branch bool isDuplicate = CheckDuplicateEnrollment(student); if (isDuplicate) { return BadRequest("Student already enrolled in the other branch."); } // Save the student's details to the database or collection SaveStudent(student); return Ok("Student enrolled successfully."); }private bool CheckDuplicateEnrollment(Student student) { // Query the database or collection to check if the student ID exists in the other branch bool isDuplicate = // Your logic to check for duplicate enrollment return isDuplicate; }private void SaveStudent(Student student) { // Save the student's details to the database or collection }