public static void ProjectTo(this UpdateInformationStudentRequest request, Student student)
 {
     student.Age = request.Age;
     student.Civility = request.Civility;
     student.ClassRoomId = request.ClassRoomId;
     student.SchoolYearId = request.SchoolYearId;
     request.User.ProjectTo(student.User);
 }
Esempio n. 2
0
        public override async Task UpdateAsync(object request)
        {
            if (!(request is UpdateInformationStudentRequest))
            {
                throw new Exception("Convert type not allowed");
            }

            UpdateInformationStudentRequest req = (UpdateInformationStudentRequest)request;
            Student std = await _repository.GetByIdAsync(req.Id);

            if (std == null)
            {
                throw new Exception("Student not found");
            }

            req.ProjectTo(std);

            await _repository.AddOrUpdateAsync(std);
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> UpdateStudent([FromBody] UpdateInformationStudentRequest studentReq)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _service.UpdateAsync(studentReq);

                    await _service.CommitAsync();

                    return(Ok());
                }
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                await _service.RollbackAsync();

                return(BadRequest(GetError(ex)));
            }
        }