예제 #1
0
        public IActionResult RegisterStudent([FromBody] RegisterStudentDto dto)
        {
            var    command = new RegisterStudentCommand(dto.Name, dto.Age, dto.Address);
            Result result  = _messages.Dispatch(command);

            return(FromResult(result));
        }
예제 #2
0
        public IActionResult RegisterStudent(RegisterStudentDto dto)
        {
            var command = new RegisterStudentCommand(dto.Name, dto.Surname);
            var result  = _messages.Dispatch(command);

            return(HandleCommandResult(result));
        }
예제 #3
0
 public void RegisterStudent(RegisterStudentDto student)
 {
     try
     {
         var id = Connection.ExecuteScalar <int>(
             @"INSERT INTO [dbo].[Students]
                ([Name]
                ,[Age]
                ,[Address])
          VALUES
                (@Name
                ,@Age
                ,@Address);
         SELECT SCOPE_IDENTITY();",
             param: new
         {
             Name    = student.Name,
             Age     = student.Age,
             Address = student.Address
         },
             transaction: Transaction);
     }
     catch (Exception)
     {
         //stop being lazy and implement log here
         throw;
     }
 }
예제 #4
0
        public async Task <ActionResult <StudentDto> > RegisterStudentAsync(RegisterStudentDto student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (await _manager.IsStudentExistAsync(student.MatricNumber))
                    {
                        return(BadRequest("Student Already Exist"));
                    }

                    var studentEntities = _mapper.Map <Student>(student);
                    await _manager.RegisterStudentAsync(studentEntities);

                    var studentToReturn = _mapper.Map <StudentDto>(studentEntities);
                    return(CreatedAtRoute("GetStudent", new { StudentId = studentToReturn.StudentId }, studentToReturn));


                    //_manager.RegisterStudent(stud);
                    //return CreatedAtRoute("GetStudentById", new { student.StudentId }, student);
                }
                else
                {
                    return(BadRequest("Student Already Exist"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #5
0
        public Result Handle(RegisterStudentCommand command)
        {
            var validator = new RegisterStudentValidator();
            var result    = validator.Validate(command);

            if (!result.IsValid)
            {
                return(Result.Fail($"Business Error: '{ result.Errors[0].ErrorMessage }'"));
            }

            var student = new RegisterStudentDto()
            {
                Name    = command.Name,
                Age     = command.Age,
                Address = command.Address
            };

            using (var UoW = new UnitOfWork(_connectionString.Value))
            {
                UoW.StudentCommandRepository.RegisterStudent(student);
                UoW.Commit();
            }

            return(Result.Ok());
        }
예제 #6
0
        public async Task <IActionResult> RegisterStudent(RegisterStudentDto dto)
        {
            var command = new RegisterStudentCommand(dto.FirstName, dto.LastName, dto.NameSuffixId, dto.Email,
                                                     dto.FavoriteCourseId, dto.FavoriteCourseGrade);

            Result result = await _messages.Dispatch(command);

            return(FromResult(result));
        }
예제 #7
0
        public async Task <IActionResult> Register(RegisterStudentDto register)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(register));
                }

                using (var httpClient = new HttpClient())
                {
                    httpClient.BaseAddress = new Uri(_apiRequestUri.BaseUri);
                    httpClient.DefaultRequestHeaders.Accept.Clear();
                    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var student = new RegisterStudentDto()
                    {
                        FirstName    = register.FirstName,
                        LastName     = register.LastName,
                        MatricNumber = register.MatricNumber,
                        StudentLevel = register.StudentLevel
                    };
                    //var uri = string.Format(_apiRequestUri.BaseUri + _apiRequestUri.GetStudentById, id);
                    var uri = string.Format(_apiRequestUri.AddStudent, student);
                    //var StringContent = new StringContent(JsonConvert.SerializeObject(register));
                    StringContent content = new StringContent(JsonConvert.SerializeObject(register));

                    //HttpResponseMessage response = await httpClient.PostAsync(uri, content);
                    HttpResponseMessage response = (HttpResponseMessage)null;

                    response = await httpClient.PostAsJsonAsync(uri, register);

                    if (response.IsSuccessStatusCode)
                    {
                        return(View());
                    }
                    if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                    {
                        ModelState.AddModelError("", await response.Content.ReadAsStringAsync());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(View());
        }
        public async Task <IActionResult> RegisterStudent(
            [FromBody] RegisterStudentDto Student)
        {
            var resp = await _messages.DispatchAsync(
                _mapper.Map <RegisterStudentInfoCommand>(Student));

            if (resp.IsSuccessful)
            {
                var studentToReturn = _mapper.Map <StudentsViewDto>(resp.ResponseMessage);
                return(CreatedAtRoute("GetStudentById",
                                      new { studentToReturn.Id },
                                      studentToReturn));
            }
            return(FromResult(resp));
        }
예제 #9
0
        public IActionResult Register()
        {
            var Register = new RegisterStudentDto();

            return(View(Register));
        }