public async Task <ActionResult <Student> > CreateAsync([FromBody] StudentReq input) { try { //verify firstname and lastname is not null if (string.IsNullOrEmpty(input.FName) && string.IsNullOrEmpty(input.LName)) { throw new ValidationNotEmptyException("first name and last name can not be empty"); } //create a new user var student = new Student { FirstName = input.FName, LastName = input.LName, MidName = input.MName, EnrollmentDate = DateTime.Now, StudentId = GenerateCoupon(12), Email = input.Email }; student.Id = await _repository.AddStudentAsync(student); return(Ok(student)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e)); } }
public SingleRsp DeleteStudent(StudentReq stu) { var res = new SingleRsp(); Student student = new Student(); student.Id = stu.Id; student.Fullname = stu.Fullname; student.DateBirth = stu.DateBirth; student.Address = stu.Address; student.Email = stu.Email; student.Phone = stu.Phone; res = _rep.DeleteStudent(student); return(res); }
/// <summary> /// Create Student /// </summary> /// <param name="model">Student DTO</param> /// <returns>Student DTO</returns> public async Task <StudentMinRes> CreateAsync(StudentReq model) { // create user User user = await _userService.CreateAsync(model.Email, model.Password, UserRoles.StudentInact); // create address Address address = _addressService.Create(model.Address); // create student Student student = new Student { FirstName = model.FirstName, LastName = model.LastName, DateOfBirth = model.DateOfBirth.Value, User = user, Address = address }; _context.Students.Add(student); await _context.SaveChangesAsync(); return(new StudentMinRes(student)); }
public IActionResult DeleteStudent([FromBody] StudentReq req) { var res = _svc.DeleteStudent(req); return(Ok(res)); }
public async Task <ActionResult <StudentMinRes> > Post([FromBody] StudentReq request) { var response = await _studentService.CreateAsync(request); return(StatusCode(201, response)); }