public static void Main() { CurrentPath = SetPath; var dex = new CreateFullTimeStudent(); StudentBase st = dex.CreateStudent("Rick", new[] { "020" }); StudentBase st1 = dex.CreateStudent("Alex", new[] { "6", "9" }); var deg = new CreatePartTimeStudent(); StudentBase st2 = deg.CreateStudent("Nick", new[] { "4", "5" }); List <StudentBase> students = new List <StudentBase> { st, st1, st2 }; Serialize(students); var c = new CreateTechCourse(); CourseBase co = c.CreateCourse("Math", new[] { "0" }, new[] { "001", "002" }); CourseBase co1 = c.CreateCourse("CS", new[] { "0" }, new[] { "001", "002" }); List <CourseBase> courses = new List <CourseBase> { co, co1 }; Serialize(courses); var n = new CreateFullTimeTeacher(); TeacherBase t = n.CreateTeacher("K", 5, new[] { "001", "002" }); var q = new CreatePartTimeTeacher(); TeacherBase t1 = q.CreateTeacher("gfgd", 5, new[] { "009", "005" }); List <TeacherBase> teachers = new List <TeacherBase> { t, t1 }; Serialize(teachers); Console.ReadKey(); }
public async Task <IActionResult> Update(Guid ID, StudentBase info) { var student = await _context.Students.SingleOrDefaultAsync(c => c.ID == ID); Action copy = () => { student.FirstName = info.FirstName; student.LastName = info.LastName; student.Program = info.Program; }; if (student != null) { copy(); _context.Students.Update(student); Response.StatusCode = StatusCodes.Status200OK; } else { student = new Student(); copy(); _context.Students.Add(student); Response.StatusCode = StatusCodes.Status201Created; } await _context.SaveChangesAsync(); return(Ok(student)); }
public async Task <ActionResult <Student> > Update(Guid id, [Bind("FirstName,LastName,Program")] StudentBase studentBase) { Student student = new Student { FirstName = studentBase.FirstName, LastName = studentBase.LastName, Program = studentBase.Program }; if (!StudentExists(id)) { Response.StatusCode = 404; return(View()); } Student dbStudent = await _context.Student.FindAsync(id); dbStudent.FirstName = student.FirstName; dbStudent.LastName = student.LastName; dbStudent.Program = student.Program; _context.Update(dbStudent); await _context.SaveChangesAsync(); return(Ok(dbStudent)); }
public async Task <ActionResult <Student> > Update(Guid id, [Bind("FirstName,LastName, Program")] StudentBase studentBase) { Student student = new Student { FirstName = studentBase.FirstName, LastName = studentBase.LastName, Program = studentBase.Program }; if (!StudentExists(id)) { //student.ID = id; //_context.Add(student); //await _context.SaveChangesAsync(); //return CreatedAtAction(nameof(GetById), new { id = student.ID }, student); return(NotFound()); } Student dbStudent = await _context.Students.FindAsync(id); dbStudent.FirstName = student.FirstName; dbStudent.LastName = student.LastName; dbStudent.Program = student.Program; _context.Update(dbStudent); await _context.SaveChangesAsync(); return(Ok(dbStudent)); }
public async Task <ActionResult <Student> > Update(Guid ID, [Bind("FirstName,LastName,Program")] StudentBase studentBase) { Student student = new Student { FirstName = studentBase.FirstName, LastName = studentBase.LastName, Program = studentBase.Program }; if (!StudentExists(ID)) { return(NotFound("Student not found")); } Student dbStudent = await _context.Students.FindAsync(ID); dbStudent.FirstName = student.FirstName; dbStudent.LastName = student.LastName; dbStudent.Program = student.Program; _context.Update(dbStudent); await _context.SaveChangesAsync(); return(Ok(dbStudent)); }
public async Task <IActionResult> Post([FromBody] StudentBase student) { try { if (student.UserId != this.GetAuthenticatedUserId()) { this._logger.Log(LogHelper.CreateLog( DateTime.Now, LogType.Fail, Constants.ForbiddenStudentCreation, null)); return(this.Forbid()); } var result = (Error)await this._dm.OperateAsync <StudentBase, object>( Constants.CreateStudentProfile, student); if (result == Error.StudentAlreadyExists) { this._logger.Log(LogHelper.CreateLog( DateTime.Now, LogType.Fail, Constants.StudentAlreadyExists, null)); return(this.BadRequest(Constants.StudentAlreadyExists)); } return(this.Ok($"Student ID : {(int)result}")); } catch (Exception ex) { this._logger.Log(LogHelper.CreateLog( DateTime.Now, LogType.Fatal, Constants.StudentCreationUnknownError, ex)); return(this.BadRequest(Constants.StudentCreationUnknownError)); } }
public async Task<ActionResult<Student>> CreateAsync([Bind("FirstName,LastName,Program")] StudentBase studentBase) { Student student = new Student { FirstName = studentBase.FirstName, LastName = studentBase.LastName, Program = studentBase.Program }; _context.Add(student); await _context.SaveChangesAsync(); return CreatedAtAction(nameof(GetById), new { id = student.ID }, student); }
public async Task <ActionResult <Student> > Create([FromBody] StudentBase student) { var newly = new Student() { FirstName = student.FirstName, LastName = student.LastName, Program = student.Program }; _context.Students.Add(newly); await _context.SaveChangesAsync(); Response.StatusCode = StatusCodes.Status201Created; return(Ok(newly)); }
public async Task <ActionResult <Student> > Update(Guid id, [Bind("FirstName, LastName, Program")] StudentBase studentBase) { if (!StudentExists(id)) { StatusCodeResult temp = new NotFoundResult(); return(temp); } Student dbStudent = await _context.Students.FindAsync(id); dbStudent.FirstName = studentBase.FirstName; dbStudent.LastName = studentBase.LastName; dbStudent.Program = studentBase.Program; _context.Update(dbStudent); await _context.SaveChangesAsync(); return(Ok(dbStudent)); }
public async Task <ActionResult <Student> > Update(Guid id, [Bind("FirstName,LastName,Program")] StudentBase StudentBase) { Student Student = new Student { FirstName = StudentBase.FirstName, LastName = StudentBase.LastName, Program = StudentBase.Program }; Student dbStudent = await _context.Students.FindAsync(id); dbStudent.FirstName = Student.FirstName; dbStudent.LastName = Student.LastName; dbStudent.Program = Student.Program; _context.Update(dbStudent); await _context.SaveChangesAsync(); return(Ok(dbStudent)); }
public async Task <ActionResult <Student> > Update(Guid id, [Bind("FirstName,LastName,Program")] StudentBase studentBase) { Student student = new Student { FirstName = studentBase.FirstName, LastName = studentBase.LastName, Program = studentBase.Program }; if (!_context.Students.Any(e => e.ID == id)) { return(NotFound()); } Student dbStudent = await _context.Students.FindAsync(id); dbStudent.FirstName = student.FirstName; dbStudent.LastName = student.LastName; dbStudent.Program = student.Program; _context.Update(dbStudent); await _context.SaveChangesAsync(); return(Ok(dbStudent)); }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, StudentBase serviceImpl) { serviceBinder.AddMethod(__Method_GetStudentById, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::gRPCServer.Protos.GetStudentByIdModel, global::gRPCServer.Protos.StudentModel>(serviceImpl.GetStudentById)); serviceBinder.AddMethod(__Method_GetAllStudents, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod <global::gRPCServer.Protos.GetAllStudentsRequest, global::gRPCServer.Protos.StudentModel>(serviceImpl.GetAllStudents)); }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(StudentBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_GetStudentById, serviceImpl.GetStudentById) .AddMethod(__Method_GetAllStudents, serviceImpl.GetAllStudents).Build()); }
public async Task <Response <string> > AddStudentProfileAsync(StudentBase student) { return(await this.SendPostRequest(STUDENTS_URI, student)); }