示例#1
0
        public async Task <IActionResult> PutLearner(string id, LearnerViewModel learner)
        {
            if (learner.Id != id)
            {
                throw new Exception(string.Format("Id và Id của người học không giống nhau!"));
            }

            try
            {
                await Task.Run(() =>
                {
                    learner.DateModified = DateTime.Now;
                    _learnerService.Update(learner);
                    _learnerService.SaveChanges();
                    return(Ok());
                });
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LearnerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <Learner> > PostLearner(LearnerViewModel learner)
        {
            if (learner != null)
            {
                try
                {
                    await Task.Run(() =>
                    {
                        learner.DateCreated = DateTime.Now;
                        if (String.IsNullOrEmpty(learner.ParentFullName) || String.IsNullOrEmpty(learner.ParentPhone))
                        {
                            learner.ParentFullName = "";
                            learner.ParentPhone    = "";
                        }

                        _learnerService.Add(learner);
                        _learnerService.SaveChanges();
                        return(Ok("thêm khóa học thành công!"));
                    });
                }
                catch
                {
                    throw new Exception(string.Format("Lỗi khi thêm dữ liệu"));
                }
            }

            return(CreatedAtAction("GetLearner", new { id = learner.Id }, learner));
        }
示例#3
0
        public bool Add(LearnerViewModel leanerVm)
        {
            try
            {
                var learner = Mapper.Map <LearnerViewModel, Learner>(leanerVm);
                #region sinh mã cardId tăng tự động
                learner.DateCreated = DateTime.Now;
                learner.Id          = TextHelper.RandomString(10);
                string cardId = _learnerRepository.FindAll().OrderByDescending(x => x.DateCreated).First().CardId;
                learner.CardId = cardId.Substring(2);

                int newCardId = Convert.ToInt32(learner.CardId) + 1;

                cardId = newCardId.ToString();
                while (cardId.Length < 5)
                {
                    cardId = "0" + cardId;
                }
                learner.CardId = "HV" + cardId;
                #endregion
                _learnerRepository.Add(learner);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public List <StudyProcessViewModel> GetAllInClass(string classId, int status)
        {
            var studyprocess = _studyProcessRepository.FindAll().Where(x => x.LanguageClassId == classId);

            Status _status = (Status)status;    //

            if (_status == Status.Active || _status == Status.InActive || _status == Status.Pause)
            {
                studyprocess = studyprocess.Where(x => x.Status == _status).OrderBy(x => x.Learner.LastName);
            }

            var studyprocessViewModel = Mapper.Map <List <StudyProcessViewModel> >(studyprocess);

            foreach (var item in studyprocessViewModel)
            {
                var learner          = _learnerRepository.FindById(item.LearnerId);
                var learnerViewModel = new LearnerViewModel();
                learnerViewModel.Id        = learner.Id;
                learnerViewModel.CardId    = learner.CardId;
                learnerViewModel.FirstName = learner.FirstName;
                learnerViewModel.LastName  = learner.LastName;
                learnerViewModel.Sex       = learner.Sex;
                learnerViewModel.Birthday  = learner.Birthday;
                learnerViewModel.Address   = learner.Address;
                learnerViewModel.Phone     = learner.Phone;
                item.Learner = learnerViewModel;
            }
            return(studyprocessViewModel);
        }
        public LearnerView()
        {
            var viewModel = new LearnerViewModel();

            DataContext = viewModel;
            viewModel.CheckboxChanged += OnCheckboxChanged;

            InitializeComponent();
        }
示例#6
0
        //GET
        public ViewResult Index(string currCourse, int page = 1)
        {
            string teacherName = UO.NickName.GetAll()
                                 .Where(m => m.UserName == HttpContext.User.Identity.Name)
                                 .First().Teacher.TeacherName;

            //chech for validation error
            if (TempData["CustomError"] != null)
            {
                ModelState.AddModelError("Mark", TempData["CustomError"].ToString());
            }


            //initializing view model
            LearnerViewModel learnerView = new LearnerViewModel()
            {
                CoursesList   = new List <string>(),
                logs          = new List <Log>(),
                CurrentCourse = currCourse,
                PagingInfo    = new PagingInfo()
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                }
            };

            var courses = UO.Courses.GetAll();

            //select course name according current name
            if (currCourse == null)
            {
                learnerView.CurrentCourse = courses.Where(x => x.Teacher.TeacherName == teacherName).First().CourseName;
            }

            //geting log records according current teacher
            foreach (var log in UO.Logs.GetAll().Where(x => x.Course.CourseName == learnerView.CurrentCourse))
            {
                learnerView.logs.Add(log);
            }
            learnerView.PagingInfo.TotalItems = learnerView.logs.Count();

            //skiping courses without teaches
            foreach (var course in courses)
            {
                if ((course.Teacher != null) && (course.Teacher.TeacherName == teacherName))
                {
                    learnerView.CoursesList.Add(course.CourseName);
                }
            }

            //selecting logs according page context
            learnerView.logs = learnerView.logs.Skip((page - 1) * PageSize)
                               .Take(PageSize).ToList();

            return(View(learnerView));
        }
示例#7
0
        public async Task <ActionResult> CommitTrialLearner(LearnerViewModel viewModel)
        {
            var profile = await HttpContext.GetUserAsync();

            ViewBag.ViewModel  = viewModel;
            viewModel.RealName = viewModel.RealName.GetEfficientString();
            if (viewModel.RealName == null)
            {
                ModelState.AddModelError("realName", "請輸入學員姓名!!");
            }

            viewModel.Phone = viewModel.Phone.GetEfficientString();
            //if (viewModel.Phone == null)
            //{
            //    ModelState.AddModelError("Phone", "請輸入聯絡電話");
            //}

            if (!ModelState.IsValid)
            {
                return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: ModelState.ErrorMessage()));
            }

            if (viewModel.KeyID != null)
            {
                viewModel.UID = viewModel.DecryptKeyValue();
            }

            UserProfile profileItem = null;

            if (!viewModel.UID.HasValue)
            {
                profileItem = models.GetTable <UserProfile>().Where(u => u.UID == viewModel.UID).FirstOrDefault();
            }

            if (profileItem == null)
            {
                profileItem = models.CreateLearner(viewModel);

                if (profileItem == null)
                {
                    return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "無法新增體驗學員!!"));
                }
                viewModel.UID = profile.UID;
            }
            else
            {
                profileItem.RealName = viewModel.RealName;
                profileItem.UserProfileExtension.Gender = viewModel.Gender;
                profileItem.Phone = viewModel.Phone;
                models.SubmitChanges();
            }

            ViewBag.Icon = "success";
            return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", "資料已更新!!"));
        }
示例#8
0
 public bool Update(LearnerViewModel leanerVm)
 {
     try
     {
         var learner = Mapper.Map <LearnerViewModel, Learner>(leanerVm);
         _learnerRepository.Update(learner);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public StudyProcessViewModel GetById(int id)
        {
            var studyProcess          = _studyProcessRepository.FindById(id);
            var studyProcessViewModel = Mapper.Map <StudyProcessViewModel>(studyProcess);
            //////// tìm kiếm thêm học viên
            var item = studyProcessViewModel;

            var learner          = _learnerRepository.FindById(item.LearnerId);
            var learnerViewModel = new LearnerViewModel();

            learnerViewModel.Id        = learner.Id;
            learnerViewModel.FirstName = learner.FirstName;
            learnerViewModel.LastName  = learner.LastName;
            learnerViewModel.Sex       = learner.Sex;
            learnerViewModel.Birthday  = learner.Birthday;
            learnerViewModel.Address   = learner.Address;
            item.Learner = learnerViewModel;


            return(studyProcessViewModel);
        }
示例#10
0
        public async Task <ActionResult> SearchLearnerAsync(LearnerViewModel viewModel)
        {
            ViewBag.ViewModel  = viewModel;
            viewModel.UserName = viewModel.UserName.GetEfficientString();
            if (viewModel.UserName == null)
            {
                this.ModelState.AddModelError("userName", "請輸入查詢學員!!");
                ViewBag.ModelState = this.ModelState;
                return(View(ConsoleHomeController.InputErrorView));
            }

            var profile = await HttpContext.GetUserAsync();

            var items = viewModel.UserName.PromptUserProfileByName(models);

            if (items.Any())
            {
                return(View("~/Views/LearnerProfile/ProfileModal/SelectLearnerProfile.cshtml", items));
            }
            else
            {
                if (viewModel.UserName.IsMobilPhone() && (profile.IsAssistant() || profile.IsManager() || profile.IsViceManager()))
                {
                    viewModel.Phone        = viewModel.UserName;
                    viewModel.CurrentTrial = 1;
                    return(View("~/Views/LearnerProfile/ProfileModal/CreateLearnerProfile.cshtml"));
                }
                else if ((String.Compare(viewModel.UserName, "null", true) == 0 && profile.IsAssistant()))
                {
                    viewModel.CurrentTrial = 1;
                    return(View("~/Views/LearnerProfile/ProfileModal/CreateLearnerProfile.cshtml"));
                }
                //return View("~/Views/ConsoleHome/Shared/AlertMessage.cshtml", model: "Opps!您確定您輸入的資料正確嗎!?");
                return(Json(new { result = false, message = "Opps!您確定您輸入的資料正確嗎!?" }));
            }
        }
示例#11
0
        public async Task<IActionResult> CreateAccount([Bind("Person", "Address", "Photo", "Learner", "Cv")] LearnerViewModel learnerViewModel)
        {
            if (ModelState.IsValid)
            { 
                // This Uploads learner profile image
                var photoPath =  _fconfig.Images  + learnerViewModel.Person.NationalId + "/" + Utils.GenerateImageFolderId() + "/";
               
                if (learnerViewModel.Photo != null)
                { 
                   _fileService.UploadFile( learnerViewModel.Photo,_env.WebRootPath + photoPath);    
                    
                   learnerViewModel.Person.PhotoName = learnerViewModel.Photo.FileName; 
                   learnerViewModel.Person.PhotoPath = photoPath;
                   Console.WriteLine(" FILE NAME : " + learnerViewModel.Photo.FileName); 
                }
                
                var cvPath =  _fconfig.Documents  + learnerViewModel.Person.NationalId + "/" + Utils.GenerateDocsFolderId() + "/";

                if (learnerViewModel.Cv != null)
                { 
                    _fileService.UploadFile( learnerViewModel.Cv,_env.WebRootPath + cvPath);    
                    
                    learnerViewModel.Person.CvName = learnerViewModel.Cv.FileName; 
                    learnerViewModel.Person.CvPath = cvPath;
                    Console.WriteLine(" FILE NAME : " + learnerViewModel.Cv.FileName); 
                }
  
                learnerViewModel.Person.CreatedBy = "admin";
                learnerViewModel.Person.DateCreated = DateTime.Now; 

                learnerViewModel.Person.LastUpdatedBy = "admin";
                learnerViewModel.Person.DateUpdated = DateTime.Now;
                
                learnerViewModel.Address.CreatedBy = "admin";
                learnerViewModel.Address.DateCreated = DateTime.Now;

                learnerViewModel.Address.LastUpdatedBy = "admin";
                learnerViewModel.Address.DateUpdated = DateTime.Now;
                            
                learnerViewModel.Learner.CreatedBy = "admin";
                learnerViewModel.Learner.DateCreated = DateTime.Now;
 
                learnerViewModel.Learner.LastUpdatedBy = "admin";
                learnerViewModel.Address.DateUpdated = DateTime.Now;
                
                learnerViewModel.Learner.AppliedYn = Const.FALSE;
                learnerViewModel.Learner.RecruitedYn = Const.FALSE;
                
                //Link the Address to the Person     
                learnerViewModel.Person.Address.Add(learnerViewModel.Address); 

                // Add the Person into the Database
                var user = await _lookUpService.GetUserByUsrname(User.Identity.Name);

                learnerViewModel.Person.UserId = user.Id;
                learnerViewModel.Person.Email = user.Email;
                
                //Now link the learner to this Person Profile created 
                learnerViewModel.Learner.Person = learnerViewModel.Person;

                //Then Add the Company

                //Then Add the Learner to the Database     
                _context.Add(learnerViewModel.Learner);
 
                //Save the Person and Address in to the Database
                await _context.SaveChangesAsync();
                _notyf.Warning("Profile created successful...", 5);
                
                ViewData["CitizenshipStatusId"] = new SelectList(_context.CitizenshipStatus, "CitizenshipStatusId", "CitizenshipStatusDesc",learnerViewModel.Person.CitizenshipStatusId);
                ViewData["DisabilityStatusId"] = new SelectList(_context.DisabilityStatus, "DisabilityStatusId", "DisabilityStatusDesc",learnerViewModel.Person.DisabilityStatusId);
                ViewData["EquityId"] = new SelectList(_context.Equity, "EquityId", "EquityDesc",learnerViewModel.Person.EquityId);
                ViewData["GenderId"] = new SelectList(_context.Gender, "GenderId", "GenderDesc",learnerViewModel.Person.GenderId);
                ViewData["HomeLanguageId"] = new SelectList(_context.HomeLanguage, "HomeLanguageId", "HomeLanguageDesc",learnerViewModel.Person.HomeLanguageId);
                ViewData["NationalityId"] = new SelectList(_context.Nationality, "NationalityId", "NationalityDesc",learnerViewModel.Person.NationalityId);
                ViewData["SuburbId"] = new SelectList(_lookUpService.GetSuburbs().Result, "id", "name",learnerViewModel.Address.SuburbId);
                ViewData["CityId"] = new SelectList(await _lookUpService.GetCities(), "id", "name",learnerViewModel.Address.CityId);
                ViewData["ProvinceId"] = new SelectList(_lookUpService.GetProvinces().Result, "id", "name",learnerViewModel.Address.ProvinceId);
                ViewData["CountryId"] = new SelectList(_lookUpService.GetCountries().Result, "id", "name",learnerViewModel.Address.CountryId);
                ViewData["AddressTypeId"] = new SelectList(_lookUpService.GetAddressTypes().Result, "id", "name",learnerViewModel.Person.CitizenshipStatusId);
                /*ViewData["InstitutionId"] = new SelectList(_lookUpService.GetInstitutions().Result, "id", "name",learnerViewModel.Learner.);
                ViewData["CourseId"] = new SelectList(_lookUpService.GetCourses().Result, "id", "name",learnerViewModel.Person.CitizenshipStatusId);*/
                ViewData["SchoolId"] = new SelectList(_lookUpService.GetSchools().Result, "id", "name",learnerViewModel.Learner.SchoolId);
                ViewData["SchoolGradeId"] = new SelectList(_lookUpService.GetSchoolGrades().Result, "id", "name",learnerViewModel.Learner.SchoolGradeId); 
                return RedirectToAction(nameof(Details), new { id = learnerViewModel.Person.NationalId });
            }

            return View();
        }