コード例 #1
0
        public virtual async Task<ActionResult> Create(AddTeacherViewModel viewModel)
        {
            if (!viewModel.NationalCode.IsValidNationalCode())
                this.AddErrors("NationalCode", "لطفا کد ملی را به شکل صحیح وارد کنید");

            if (await _TeacherService.IsTeacherNationalCodeExist(viewModel.NationalCode, null))
                this.AddErrors("NationalCode", "یک استاد بااین کد ملی قبلا در سیستم ثبت شده است");
           
            if (!ModelState.IsValid)
            {
                await _TeacherService.FillAddViewMoel(viewModel, IranCitiesPath);

                return View(viewModel);
            }

            _TeacherService.Create(viewModel);
            await _unitOfWork.SaveChangesAsync();
           this.NotyInformation("استاد جدید با موفقیت ثبت شد.");
            return RedirectToAction(MVC.Teacher.Create());
        }
コード例 #2
0
ファイル: TeacherService.cs プロジェクト: raminmjj/Decision
        public async Task FillAddViewMoel(AddTeacherViewModel viewModel, string path)
        {
            viewModel.StatesForBirthPlace = viewModel.BirthPlaceState == null
                ? new List<SelectListItem>()
                : _stateService.GetAsSelectListItemAsync(viewModel.BirthPlaceState, path);

            viewModel.StatesForTrainingCeneter = viewModel.TrainingCenterState == null
                ? new List<SelectListItem>()
                : _stateService.GetAsSelectListItemAsync(viewModel.TrainingCenterState,
                    path);

            viewModel.CitiesForBirthPlace = viewModel.BirthPlaceState == null
                ? new List<SelectListItem>()
                : viewModel.BirthPlaceCity == null
                    ? new List<SelectListItem>()
                    : _cityService.GetAsSelectListByStateNameAsync(viewModel.BirthPlaceState,
                        viewModel.BirthPlaceCity, path);

            viewModel.CitiesForTrainingCeneter = viewModel.TrainingCenterState == null
                ? new List<SelectListItem>()
                : viewModel.TrainingCenterCity == null
                    ? new List<SelectListItem>()
                    : _cityService.GetAsSelectListByStateNameAsync(viewModel.TrainingCenterState,
                        viewModel.TrainingCenterCity,
                        path);

            viewModel.TrainingCenters = viewModel.TrainingCenterCity == null
                ? new List<SelectListItem>()
                : viewModel.TrainingCenterId == null
                    ? new List<SelectListItem>()
                    : await
                        _trainingCenterService.GetAsSelectListItemAsync(viewModel.TrainingCenterCity,
                            viewModel.TrainingCenterId);


            viewModel.TrainingCourses = viewModel.TrainingCenterId == null
                ? new List<SelectListItem>()
                : viewModel.TrainingCourseId == null
                    ? new List<SelectListItem>()
                    : await
                        _trainingCourseService.GetAsSelectListByTrainingCenterIdAsync(viewModel.TrainingCenterId.Value,
                            viewModel.TrainingCourseId);

            viewModel.Positions =
                await _titleService.GetAsSelectListItemAsync(TitleType.TeacherPosition, viewModel.PositionId);
        }
コード例 #3
0
ファイル: TeacherService.cs プロジェクト: raminmjj/Decision
 public async Task<AddTeacherViewModel> GetForCreate(string path)
 {
     var viewModel = new AddTeacherViewModel
     {
         Positions = await _titleService.GetAsSelectListItemAsync(TitleType.TeacherPosition, null),
         StatesForBirthPlace = _stateService.GetAsSelectListItemAsync(null, path),
         StatesForTrainingCeneter = _stateService.GetAsSelectListItemAsync(null, path)
     };
     return viewModel;
 }
コード例 #4
0
ファイル: TeacherService.cs プロジェクト: raminmjj/Decision
        public void Create(AddTeacherViewModel viewModel)
        {
            var Teacher = _mappingEngine.Map<Teacher>(viewModel);
            Teacher.CreatorId = _userManager.GetCurrentUserId();

            if (_userManager.IsAdministrator())
            {
                Teacher.IsInReference = false;
                Teacher.IsApproved = true;
                Teacher.ApproveById = Teacher.CreatorId;
            }
            else if (_userManager.IsOperator())
            {
                _referentialTeacherService.Create(new AddReferentialTeacherViewModel
                {
                    TeacherId = Teacher.Id,
                    ReferencedToId = Teacher.CreatorId
                });
            }

            if (viewModel.PhotoScan.HasValue())
                Teacher.Photo = Convert.FromBase64String(viewModel.PhotoScan).ResizeImageFile(150, 150);
            else if (viewModel.PhotoFile.HasFile())
            {
                Teacher.Photo = viewModel.PhotoFile.InputStream.ResizeImageFile(150, 150);
            }
            else
            {
                Teacher.Photo = ImageManage.ResizeImageFile(_httpContextBase.Server.MapPath(DefaultAvatarPath), 150, 150);
            }

            if (viewModel.CopyOfBirthCertificateScan.HasValue())
                Teacher.CopyOfBirthCertificate = Convert.FromBase64String(viewModel.CopyOfBirthCertificateScan).ResizeImageFile(A5Width, A5Height);
            else if (viewModel.CopyOfBirthCertificateFile.HasFile())
            {
                Teacher.CopyOfBirthCertificate = viewModel.CopyOfBirthCertificateFile.InputStream.ResizeImageFile(A5Width, A5Height);
            }
            
            if (viewModel.CopyOfNationalCardScan.HasValue())
                Teacher.CopyOfNationalCard = Convert.FromBase64String(viewModel.CopyOfNationalCardScan).ResizeImageFile(A6Width, A6Height);
            else if (viewModel.CopyOfNationalCardFile.HasFile())
            {
                Teacher.CopyOfNationalCard = viewModel.CopyOfNationalCardFile.InputStream.ResizeImageFile(A6Width, A6Height);
            }
            _Teachers.Add(Teacher);
        }