Ejemplo n.º 1
0
        public ActionResult Put(Guid id, [FromBody] StudentRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var student = studentRepository.Get(id);
                if (student != null)
                {
                    student.FirstName  = request.FirstName;
                    student.MiddleName = request.MiddleName;
                    student.LastName   = request.LastName;
                    student.BirthDate  = request.BirthDate;
                    student.Gender     = Gender.FromId(request.Gender) ?? Gender.NotSpecified;
                    student.GPA        = request.Gpa;
                    this.studentRepository.Update(student);

                    return(Ok());

                    //TODO: Add audit info in response
                    //var response = new UpdateStudentResponse(student.Id);
                    //return Ok(response);
                }

                return(NotFound());
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] StudentRequest req)
        {
            try
            {
                if (req == null)
                {
                    return(new ErrorResult());
                }

                Student student = new Student
                {
                    StudentName = req.StudentName,
                    StudentRA   = req.StudentRA,
                    CampusID    = req.CampusID,
                    GroupID     = req.GroupID
                };

                _unitOfWork.Student.Add(student);
                await _unitOfWork.Complete();

                return(new MyOkResult((StudentResult)student));
            }
            catch (Exception ex)
            {
                return(new ErrorResult(ex.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([FromBody] StudentRequest studentRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ValidFildeFormBody()));
            }
            var student = new Student
            {
                Code     = studentRequest.Code,
                Address  = studentRequest.Address,
                FullName = studentRequest.FullName,
                Years    = studentRequest.Years
            };

            if (!await _studentService.CreateStudent_Async(student))
            {
                return(BadRequest(new AuthFailedResponse
                {
                    Errors = new List <string> {
                        "This Code is existed"
                    }
                }));
            }
            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.Students.Get.Replace("{code}", student.Code);


            return(Created(locationUri, student));
        }
Ejemplo n.º 4
0
        public Boolean UpdateStudent(StudentRequest request)
        {
            /*
             * ICollection<Student> students = _context.Student.ToList();
             * var oldStudents = students.Where((emp) => emp.IndexNumber == request.IndexNumber);
             * if (oldStudents.Count() == 0)    return false;
             * var oldStudt = oldStudents.ElementAt(0);
             * students.Remove(oldStudt);
             * oldStudt.BirthDate = request.BirthDate;
             * oldStudt.FirstName = request.FirstName;
             * oldStudt.LastName = request.LastName;
             * oldStudt.IdEnrollment = request.IdEnrollment;
             * students.Add(oldStudt);
             */
            var student = _context.Student.Find(request.IndexNumber);

            if (student == null)
            {
                return(false);
            }
            _context.Student.Remove(student);
            _context.SaveChanges();
            student.BirthDate    = request.BirthDate;
            student.FirstName    = request.FirstName;
            student.LastName     = request.LastName;
            student.IdEnrollment = request.IdEnrollment;
            _context.Student.Add(student);
            _context.SaveChanges();

            return(true);
        }
Ejemplo n.º 5
0
        public async Task <JsonResult <StudentResponse> > UpdateStudent(int id, StudentRequest studentRequest)
        {
            var student = await _unitOfWork.StudentRepository
                          .Find(x => x.Id == id)
                          .FirstOrDefaultAsync();

            if (student is null || student.IsActive == false)
            {
                return(new JsonResult <StudentResponse>(false, null, "The student doesn't exist", 2));
            }

            var studentUpdate = _mapper.Map(studentRequest, student);

            studentUpdate.ModifiedAt = DateTime.Now;
            var result = await _unitOfWork.StudentRepository.UpdateAsync(studentUpdate, new StudentValidator());

            if (!result.IsValid)
            {
                return(new JsonResult <StudentResponse>(false, null, "Update Error", 4));
            }
            await _unitOfWork.SaveChangesAsync();

            var response = _mapper.Map <Student, StudentResponse>(studentUpdate);

            return(new JsonResult <StudentResponse>(true, response, "Success", 0));
        }
Ejemplo n.º 6
0
        public int UpdateStudentRequest(StudentRequest oNaghs)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = _conn;
            cmd.CommandText = "Request.[SP_UpdateStudentRequest]";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@StudentRequestID", oNaghs.StudentRequestId);
            cmd.Parameters.AddWithValue("@stcode", oNaghs.StCode);
            cmd.Parameters.AddWithValue("@Erae_Be", oNaghs.Erae_Be);
            cmd.Parameters.AddWithValue("@RequestLogID", oNaghs.RequestLogId);
            cmd.Parameters.AddWithValue("@HasStamp", oNaghs.HasStamp);
            var dt = new DataTable();

            try
            {
                if (_conn.State == ConnectionState.Closed)
                {
                    _conn.Open();
                }
                var rd = cmd.ExecuteNonQuery();
                _conn.Close();
                return(rd);
            }
            catch (Exception)
            {
                if (_conn.State == ConnectionState.Open)
                {
                    _conn.Close();
                }
                return(-1);

                throw;
            }
        }
Ejemplo n.º 7
0
        public async Task <dynamic> Add(StudentRequest studentRequest)
        {
            if (studentRequest == null)
            {
                AddError("20000");
                return(null);
            }

            var student = Student.Create(studentRequest.Name);

            if (!student.IsValid)
            {
                AddErrors(student.Error);
                return(null);
            }

            //var course = await _courseRepository.FindById(Guid.Parse("B0DDB957-E4D4-482D-88AC-686ECE51CB52"));
            //var studentCourse = StudentCourse.Create(student, course);
            //student.RegistreStudent(studentCourse);
            _studentRepository.Add(student);

            var studentResponse = _mapper.Map <Student, StudentResponse>(student);

            return(await Task.FromResult(studentResponse));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Insert(StudentRequest oStudent)
        {
            //StudentRequest students = new StudentRequest();
            var students = await _service.AddStudentAsync(oStudent);

            return(Ok(students));
        }
Ejemplo n.º 9
0
        public void AddStudent(StudentRequest studentRequest)
        {
            var student = Mapper.Map <StudentRequest, Student>(studentRequest);

            student.Id = 0;
            _studentRepository.Add(student);
        }
Ejemplo n.º 10
0
        public ActionResult <NewRecordResponse> Post([FromBody] StudentRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var student = new Student
                {
                    FirstName  = request.FirstName,
                    MiddleName = request.MiddleName,
                    LastName   = request.LastName,
                    BirthDate  = request.BirthDate,
                    Gender     = Gender.FromId(request.Gender) ?? Gender.NotSpecified,
                    GPA        = request.Gpa
                };

                this.studentRepository.Create(student);

                var response = new NewRecordResponse(student.Id);

                return(CreatedAtAction(nameof(Get), new { id = student.Id }, response));
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
Ejemplo n.º 11
0
        public Student AddStudent(StudentRequest studentRequest)
        {
            Guid    guid    = Guid.NewGuid();
            Student student = new Student(guid, studentRequest.Name, studentRequest.Age);

            _dictionary[guid.ToString()] = ToStudentDataModel(student);
            return(student);
        }
        public IActionResult Create([FromBody] StudentRequest request)
        {
            var student = _mapper.Map <Student>(request);

            _iStudentService.Insert(student);

            return(Ok());
        }
Ejemplo n.º 13
0
 public override Task <StudentGrades> getStudentGrades(StudentRequest request, ServerCallContext context)
 {
     return(Task.FromResult(new StudentGrades
     {
         StudentId = 1,
         Grades = 78,
         Subject = "Mathematics"
     }));
 }
Ejemplo n.º 14
0
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            StudentRequest studentRequest = await db.StudentRequest.FindAsync(id);

            db.StudentRequest.Remove(studentRequest);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 15
0
        public IActionResult InsertStudents(StudentRequest request)
        {
            var res = _service.InsertStudents(request);

            if (res != null)
            {
                return(BadRequest("400 Bad Request Error!"));
            }
            return(Ok("A student has been successfully added"));
        }
Ejemplo n.º 16
0
        public async Task <StudentResponse> Create(StudentRequest obj)
        {
            _logger.LogInformation("Attempting to create student in service");
            var student        = _mapper.Map <Student>(obj);
            var createdStudent = await _studentRepo.Insert(student);

            var studentResponse = _mapper.Map <StudentResponse>(createdStudent);

            return(studentResponse);
        }
Ejemplo n.º 17
0
 public override Task <Student> GetStudent(StudentRequest request, ServerCallContext context)
 {
     return(Task.FromResult <Student>(new Student()
     {
         Id = request.Id,
         Gender = request.Gender,
         Name = request.Name,
         ResponseTime = GetDateTimeNowString()
     }));
 }
Ejemplo n.º 18
0
        public IActionResult DeleteStudents(StudentRequest request)
        {
            var res = _service.DeleteStudents(request);

            if (res != null)
            {
                return(BadRequest("400 Bad Request Error!"));
            }
            return(Ok("A student has been deleted"));
        }
        public async Task <ActionResult <StudentResponse> > Post([FromBody] StudentRequest student)
        {
            var studentModel = _mapper.Map <Models.Student>(student);

            await _studentDocumentRepository.AddAsync(studentModel, student.LastName);

            await PostAuditMessage("create", studentModel);

            return(CreatedAtRoute("GetStudent", new { studentModel.Id, studentModel.LastName }, _mapper.Map <StudentResponse>(studentModel)));
        }
Ejemplo n.º 20
0
        public IActionResult EnrollStudent([FromBody] StudentRequest request)
        {
            var enrollment = _service.EnrollStudent(request);

            if (enrollment == null)
            {
                return(BadRequest("400 Bad Request Error!"));
            }
            return(CreatedAtAction(nameof(EnrollStudent), enrollment));
        }
Ejemplo n.º 21
0
 public static Student GetEntity(StudentRequest item)
 {
     return(new Student()
     {
         FirstName = item.FirstName,
         LastName = item.LastName,
         Age = item.Age,
         Sex = GetEnum(item.Sex)
     });
 }
        public async Task <IActionResult> PostStudent([FromBody] StudentRequest studentRequest)
        {
            var studentResponse = await _studentService.Create(studentRequest);

            if (studentRequest == null)
            {
                return(BadRequest("Failed to create student, please check request"));
            }
            var uri = Url.Link("GetStudentById", new { id = studentResponse.Id });

            return(Created(uri, studentResponse));
        }
Ejemplo n.º 23
0
        public async Task <string> Update(StudentRequest request)
        {
            var json        = JsonConvert.SerializeObject(request);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            var client = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri("https://localhost:44372");
            var response = await client.PutAsync("api/Student", httpContent);

            return(await response.Content.ReadAsStringAsync());
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Post([FromBody] StudentRequest studentRequest)
        {
            if (studentRequest == null)
            {
                return(BadRequest());
            }

            var model      = studentRequest.ToModel();
            var newStudent = await _studentRepository.PostAsync(model);

            return(Ok(StudentResponse.Create(newStudent)));
        }
        public async Task <ActionResult <StudentResponse> > Put(Guid id, [FromBody] StudentRequest student)
        {
            var studentModel = _mapper.Map <Models.Student>(student);

            studentModel.Id = id.ToString();

            await _studentDocumentRepository.UpdateAsync(studentModel, student.LastName);

            await PostAuditMessage("update", studentModel);

            return(Ok(_mapper.Map <StudentResponse>(studentModel)));
        }
Ejemplo n.º 26
0
        public async Task <StudentResult> Post(StudentRequest req)
        {
            try
            {
                var result = await WebClientOfT <StudentResult> .PostJsonAsync(ApiEndPoint, req);

                return(result);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 27
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,AdvisorID,EducationTypeID,HomeCityID,RequestTrackingID,Name,Surname,DateTime,IsDeleted")] StudentRequest studentRequest)
        {
            if (ModelState.IsValid)
            {
                db.Entry(studentRequest).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.EducationTypeID   = new SelectList(db.EducationType, "ID", "Name", studentRequest.EducationTypeID);
            ViewBag.RequestTrackingID = new SelectList(db.RequestTracking, "ID", "Name", studentRequest.RequestTrackingID);
            return(View(studentRequest));
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Post([FromBody] StudentRequest request)
        {
            try
            {
                var entity = await _studentClient.Post(request);

                return(new MyOkResult(entity));
            }
            catch (Exception ex)
            {
                return(new ErrorResult(ex));
            }
        }
Ejemplo n.º 29
0
        public async Task <ActionResult> CreateStudent([FromForm] StudentRequest studentRequest)
        {
            var result = await _studentRepository.CreateStudent(studentRequest);

            if (result.StatusCode == Helpers.Success)
            {
                return(StatusCode(StatusCodes.Status200OK, result));
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest, result));
            }
        }
Ejemplo n.º 30
0
        public IActionResult UpdateStudent(StudentRequest request)
        {
            // new s19314Context().Student.Remove();

            if (_context.UpdateStudent(request))
            {
                return(Ok("Student " + request.IndexNumber + " was updated! "));
            }
            else
            {
                return(NotFound("Student " + request.IndexNumber + " Not Found!"));
            }
        }