Beispiel #1
0
        public async Task <IActionResult> InitializeTimetableForTestUsers([FromBody] StudentModel body)
        {
            _logger.LogInformation($"[TEST] Setting test timetable for test student: {body.Email}.");
            User user = await _userService.GetUserByEmailAsync(body.Email);

            if (user == null)
            {
                _logger.LogError($"[TEST] Test user with email: {body.Email} does not exist.");
                return(ErrorResponse($"User with email: {body.Email} does not exist."));
            }
            var timetable = _schoolScheduleProxy.GetFromJsonFile("TestTimetable.json");

            if (timetable == null)
            {
                return(ErrorResponse("Loading of test timetable failed."));
            }

            FRITeam.Swapify.SwapifyBase.Entities.Timetable studentTimetable = await ConverterApiToDomain.ConvertTimetableForPersonalNumberAsync(timetable, _courseService);

            Student student = user.Student;

            if (student == null)
            {
                student = new Student
                {
                    PersonalNumber = "000000",
                    UserId         = user.Id
                };
                await _studentService.AddAsync(student);

                user.Student = student;

                await _studentService.UpdateStudentTimetableAsync(student, studentTimetable);

                await _userService.UpdateUserAsync(user);

                return(Ok(student.Timetable));
            }
            if (student.PersonalNumber != null && student.PersonalNumber.Equals("000000"))
            {
                return(Ok(student.Timetable));
            }
            else
            {
                student.PersonalNumber = "000000";
                await _studentService.UpdateStudentTimetableAsync(student, studentTimetable);

                await _userService.UpdateUserAsync(user);

                return(Ok(student.Timetable));
            }
        }
        public async Task <ActionResult> AddOrUpdateStudent(
            [FromForm] StudentPostModel studentPostModel,
            [FromQuery] bool add)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Header = add ? ControllerConstants.AddStudentHeader : ControllerConstants.UpdateStudentHeader;
                await _viewBagDataProvider.InitFacultiesAndSpecialities(ViewBag);

                return(View(studentPostModel));
            }

            var student = _studentPostModelMapper.Map(studentPostModel);

            if (add)
            {
                await _studentService.AddAsync(student);
            }
            else
            {
                await _studentService.UpdateAsync(student);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public async Task <ResponseResult <int> > AddAsync([FromBody] Students studentInfo)
        {
            try
            {
                if (studentInfo == null)
                {
                    return new ResponseResult <int> {
                               ResCode = ResCodeOptions.Error
                    }
                }
                ;

                var effect = await _studentService.AddAsync(studentInfo);

                return(new ResponseResult <int> {
                    ResCode = ResCodeOptions.Success
                });
            }
            catch (Exception ex)
            {
                return(new ResponseResult <int> {
                    ResCode = ResCodeOptions.Error, Message = ex.Message
                });
            }
        }
Beispiel #4
0
        private async Task AddStudent()
        {
            var student = _studentMenu.GetFromInput();


            await _studentService.AddAsync(student);
        }
Beispiel #5
0
        public async Task <IActionResult> RegisterStudent(StudentDto studentDto, [FromHeader] CancellationToken cancellationToken)
        {
            var existsStudentCode = await _studentService.GetByStudentNumberAsync(cancellationToken, studentDto.UserName);

            if (existsStudentCode != null)
            {
                return(BadRequest("شماره دانشجویی تکراری است"));
            }

            var existsStudentId = await _userManager.FindByIdAsync(studentDto.Id);

            if (existsStudentId != null)
            {
                return(BadRequest("این دانشجو از قبل موجود است"));
            }

            var existsStudentUserName = await _userManager.FindByNameAsync(studentDto.UserName);

            if (existsStudentUserName != null)
            {
                return(BadRequest("این شماره دانشجویی قبلا ثبت شده است"));
            }

            var user = new User
            {
                UserName = studentDto.UserName,
                FullName = studentDto.FullName
            };
            var result = await _userManager.CreateAsync(user, "111111");

            if (result != IdentityResult.Success)
            {
                return(BadRequest("مشکلی در ثبت نام به وجود آمده است"));
            }

            var student = studentDto.ToEntity();

            studentDto.UserId    = user.Id;
            studentDto.EntryYear = int.Parse(studentDto.UserName.Substring(0, 2));
            var studentResult = await _studentService.AddAsync(cancellationToken, studentDto);

            if (studentResult == AddAsyncStatus.Exists)
            {
                return(BadRequest("این دانشجو از قبل موجود بوده است"));
            }

            if (studentResult == AddAsyncStatus.Bad)
            {
                return(BadRequest("مشکلی در ثبت نام به وجود آمده است"));
            }

            var roleResult = await _userManager.AddToRoleAsync(user, "Student");

            if (roleResult != IdentityResult.Success)
            {
                return(BadRequest("مشکلی در ثبت نام به وجود آمده است"));
            }

            return(Ok($"ثبت نام {user.FullName} با موفیت انجام شد"));
        }
Beispiel #6
0
        public async Task <IActionResult> PostStudent([FromBody] Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            student = await _studentService.AddAsync(student);

            return(Ok(student));
        }
Beispiel #7
0
 public async void TryAddStudent(User user)
 {
     if (user.Student == null)
     {
         user.Student = new Student
         {
             UserId = user.Id
         };
         await _studentService.AddAsync(user.Student);
         await UpdateUserAsync(user);
     }
 }
        public IActionResult Post([FromBody] StudentViewModel student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Student _newStudent = _mapper.Map <Student>(student);

            _studentService.AddAsync(_newStudent);

            return(Ok(_newStudent));
        }
Beispiel #9
0
        public async Task <IActionResult> PostAsync([FromBody] SaveStudentResource resource)
        {
            var student = _mapper.Map <SaveStudentResource, Student>(resource);
            var result  = await _studentService.AddAsync(student);

            if (!result.Success)
            {
                return(BadRequest(new ErrorResource(result.Message)));
            }

            var studentResource = _mapper.Map <Student, StudentResource>(result.Student);

            return(Ok(studentResource));
        }
Beispiel #10
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Degree,Address")] Student student)
        {
            if (ModelState.IsValid)
            {
                var result = await _studentService.AddAsync(student);

                if (!result.Success)
                {
                    ModelState.AddModelError("", result.Message);
                    return(View(student));
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Beispiel #11
0
        public async Task <IActionResult> Index()
        {
            var studentModel = new StudentDto
            {
                Name = "test",
                Age  = 18
            };

            var isSucceed = await _studentService.AddAsync(studentModel);

            var studentDto = await _studentService.GetByIdAsync(1);

            var studentDtos = await _studentService.GetAllAsync();

            return(View());
        }
Beispiel #12
0
        public async Task <IActionResult> Add([FromBody] Student student)
        {
            try
            {
                var id = await _studentService.AddAsync(student);

                _logger.LogInformation("Added new student");

                return(Ok(id));
            }
            catch (BusinessLogicException ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Create([Bind("EnrollmentDate,FirstName,LastName")] StudentDto student)
        {
            if (student == null)
            {
                return(BadRequest());
            }
            try
            {
                await _studentSvc.AddAsync(student);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View(student));
            }
        }
Beispiel #14
0
        public async Task <IActionResult> Create(CreateStudentViewModel viewModel, int universityId)
        {
            var studentDto = new AddStudentDTO {
                FirstName = viewModel.FirstName, LastName = viewModel.LastName, AverageGrade = viewModel.AverageGrade, UniversityId = universityId
            };
            var model = await _service.AddAsync(studentDto);

            if (model == null)
            {
                return(new JsonResult(new ReturnMessage {
                    MessageContent = "Unexpected error when creating a student"
                })
                {
                    StatusCode = (int)HttpStatusCode.BadRequest
                });
            }
            return(Ok(new StudentViewModel {
                StudentId = model.StudentId, FirstName = model.FirstName, LastName = model.LastName, AverageGrade = model.AverageGrade, UniversityId = model.UniversityId
            }));
        }
Beispiel #15
0
        public async Task <IHttpActionResult> AddStudent([FromBody] AddStudentRequest studentReq)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _service.AddAsync(studentReq);

                    await _service.CommitAsync();

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

                return(BadRequest(GetError(ex)));
            }
        }
        public async Task <HttpResponseMessage> CreateStudent([FromBody] StudentViewModel student)
        {
            await _studentService.AddAsync(Mapper.Map <StudentDto>(student));

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public async Task <IActionResult> Create(Student student)
        {
            await _studentService.AddAsync(student);

            return(RedirectToAction("Index"));
        }
Beispiel #18
0
        public async Task <ActionResult <Student> > AddAsync([FromBody] Student student)
        {
            var item = await _studentService.AddAsync(student);

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = item.Id }, item));
        }
Beispiel #19
0
 public async Task <IActionResult> Post([FromBody] Student model)
 {
     return(Ok(
                await _studentService.AddAsync(model)
                ));
 }
        public async Task <IActionResult> Post([FromBody] StudentDTO student)
        {
            var data = await _service.AddAsync(student);

            return(Created(nameof(Get), data));
        }
Beispiel #21
0
        public async Task <IActionResult> Create(StudentDto studentDto, [FromHeader] CancellationToken cancellationToken)
        {
            try
            {
                var existsStudentCode = await _studentService.GetByStudentNumberAsync(cancellationToken, studentDto.UserName);

                if (existsStudentCode != null)
                {
                    TempData["Error"] = "شماره دانشجویی تکراری است";
                    return(View(studentDto));
                }

                var existsStudentId = await _userManager.FindByIdAsync(studentDto.Id);

                if (existsStudentId != null)
                {
                    TempData["Error"] = "این دانشجو از قبل موجود است";
                    return(View(studentDto));
                }

                var existsStudentUserName = await _uRepository.TableNoTracking.Where(c => c.UserName == studentDto.UserName).SingleOrDefaultAsync(cancellationToken);

                if (existsStudentUserName != null)
                {
                    TempData["Error"] = "این شماره دانشجویی قبلا ثبت شده است";
                    return(View(studentDto));
                }
                var stStatus = studentDto.UserName.Substring(6, 2);

                var user = new User
                {
                    UserName = studentDto.UserName,
                    FullName = studentDto.FullName
                };

                var result = await _userManager.CreateAsync(user, studentDto.UserName);

                if (result != IdentityResult.Success)
                {
                    TempData["Error"] = "مشکلی در ثبت نام به وجود آمده است";
                    return(View(studentDto));
                }

                var student = studentDto.ToEntity();

                studentDto.UserId    = user.Id;
                studentDto.EntryYear = int.Parse(studentDto.UserName.Substring(0, 2));


                if (stStatus == "11")
                {
                    studentDto.StudentStatus = Common.Enums.StudentStatus.Daily;
                }
                else
                {
                    studentDto.StudentStatus = Common.Enums.StudentStatus.Nightly;
                }

                var studentResult = await _studentService.AddAsync(cancellationToken, studentDto);

                if (studentResult == AddAsyncStatus.Exists)
                {
                    TempData["Error"] = "این دانشجو از قبل موجود بوده است";
                    return(View(studentDto));
                }

                if (studentResult == AddAsyncStatus.Bad)
                {
                    TempData["Error"] = "مشکلی در ثبت نام به وجود آمده است";
                    return(View(studentDto));
                }

                var roleResult = await _userManager.AddToRoleAsync(user, "Student");

                if (roleResult != IdentityResult.Success)
                {
                    TempData["Error"] = "مشکلی در ثبت نام به وجود آمده است";
                    return(View(studentDto));
                }
                TempData["Success"] = $"ثبت نام {user.FullName} با موفیت انجام شد";
                return(LocalRedirect("/Admin/Student/Index"));
            }
            catch
            {
                TempData["Error"] = "لطفا در وارد کردن اطلاعات دقت نمایید";
                return(View(studentDto));
            }
        }
Beispiel #22
0
 public async Task AddAsync([FromBody] Student Student)
 {
     await m_StudentService.AddAsync(Student);
 }