public ActionResult Edit(Student student)
        {
            ViewData["ReturnUrl"] = ReturnUrl;
            PopulateGrades();
            PopulateStudents();
            PopulateParents();
            if (ModelState.IsValid)
            {
                db.Entry(student).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("List"));
            }
            //Use automapper to map the objects or assign the data as below
            EditStudentViewModel model = new EditStudentViewModel
            {
                FirstName    = student.FirstName,
                LastName     = student.LastName,
                Stud_Email   = student.Stud_Email,
                Parent_Email = student.Parent_Email,
                Class_Id     = student.Class_Id,
                Active       = student.Active
            };

            return(View(model));
        }
 public ActionResult Edit(int id)
 {
     if (CheckAccess())
     {
         if (id == 0)
         {
             return(NotFound());
         }
         PopulateGrades();
         PopulateStudents();
         PopulateParents();
         Student student            = db.Student.Find(id);
         EditStudentViewModel model = new EditStudentViewModel
         {
             FirstName    = student.FirstName,
             LastName     = student.LastName,
             Stud_Email   = student.Stud_Email,
             Parent_Email = student.Parent_Email,
             Class_Id     = student.Class_Id,
             Active       = student.Active
         };
         return(View(model));
     }
     else
     {
         return(RedirectToAction("Denied", "Access"));
     }
 }
Example #3
0
        public IActionResult Update(int ID)
        {
            Student student            = _studentRepository.GetStudentByID(ID);
            EditStudentViewModel model = new EditStudentViewModel()
            {
                ID                = student.id,
                FirstName         = student.firstName,
                MiddleName        = student.middleName,
                LastName          = student.lastName,
                Age               = student.age,
                Email             = student.email,
                BirthDate         = student.birthDate,
                EntryYear         = student.entryYear,
                Semester          = student.season,
                PhoneNumber       = student.phoneNumber,
                Grade             = student.grade,
                Gender            = student.gender,
                Address           = student.address,
                City              = student.city,
                State             = student.state,
                existingPhotoPath = student.photoPath,
            };

            return(View(model));
        }
Example #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null || !id.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            studentService = new StudentService();

            Student student = studentService.GetStudentByID((int)id);

            if (student == null)
            {
                return(RedirectToAction("Index"));
            }

            EditStudentViewModel viewModel = new EditStudentViewModel()
            {
                Email     = student.Email,
                Name      = student.Name,
                StudentId = student.ID
            };

            return(View(viewModel));
        }
        public ActionResult EditStudentFullList(string ID)
        {
            EditStudentViewModel esvm = new EditStudentViewModel();

            if (ID != null)
            {
                UserStore <Models.Identity.ApplicationUser>   userStore   = new UserStore <Models.Identity.ApplicationUser>(context);
                UserManager <Models.Identity.ApplicationUser> userManager = new UserManager <Models.Identity.ApplicationUser>(userStore);

                var student = userManager.FindById(ID);

                if (student == null)
                {
                    return(HttpNotFound());
                }

                esvm = new EditStudentViewModel
                {
                    FirstName = student.FirstName,
                    LastName  = student.LastName,
                    Email     = student.Email,
                    Id        = ID
                };
            }
            return(PartialView("_EditStudentPartialFullList", esvm));
        }
Example #6
0
        public ActionResult Edit(EditStudentViewModel student)
        {
            var input = new StudentInputUpdate
            {
                Address   = student.Address,
                Birthdate = student.Birthdate,
                City      = student.City,
                Country   = student.Country,
                CourseId  = student.SelectedCourse,
                Email     = student.Email,
                FirstName = student.FirstName,
                Gender    = student.Gender,
                LastName  = student.LastName,
                Phone     = student.Phone,
                StudentId = student.Id
            };
            var result = _studentCommand.Handle(input);

            if (!result.IsValid)
            {
                foreach (var n in result.Notifications)
                {
                    ModelState.AddModelError(n.Key, n.Value);
                }
                student.Courses = GetComboboxCourse();
                return(View(student));
            }
            return(RedirectToAction("Index"));
        }
Example #7
0
        public ActionResult Edit(EditStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                Student student = db.Students.Find(model.ID);

                if (student == null)
                {
                    return(HttpNotFound());
                }

                student.LastName      = model.LastName;
                student.FirstMidName  = model.FirstMidName;
                student.EnrolmentDate = model.EnrolmentDate;

                db.Entry(student).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    // log the error
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }
            }

            return(View(model));
        }
        public void EditStudent(EditStudentViewModel studentVM)
        {
            var student = studentVM.Student;

            context.Entry(student).State = System.Data.Entity.EntityState.Modified;
            Save();
        }
Example #9
0
        // GET: Student/Delete/5
        public ActionResult Delete(int?id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (saveChangesError.GetValueOrDefault())
            {
                ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator.";
            }

            Student student = db.Students.Find(id);

            if (student == null)
            {
                return(HttpNotFound());
            }

            EditStudentViewModel model = new EditStudentViewModel
            {
                ID            = student.ID,
                LastName      = student.LastName,
                FirstMidName  = student.FirstMidName,
                EnrolmentDate = student.EnrolmentDate
            };

            return(View(model));
        }
        public ActionResult EditStudentFullList(EditStudentViewModel editStudentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("_FullStudentListPartial"));
            }

            if (editStudentViewModel == null)
            {
                return(HttpNotFound());
            }

            UserStore <Models.Identity.ApplicationUser>   userStore   = new UserStore <Models.Identity.ApplicationUser>(context);
            UserManager <Models.Identity.ApplicationUser> userManager = new UserManager <Models.Identity.ApplicationUser>(userStore);

            ApplicationUser student = userManager.FindById(editStudentViewModel.Id);

            if (student == null)
            {
                return(RedirectToAction("_FullStudentListPartial"));
            }

            student.FirstName = editStudentViewModel.FirstName;
            student.LastName  = editStudentViewModel.LastName;
            student.Email     = editStudentViewModel.Email;
            student.UserName  = editStudentViewModel.Email;

            var result = userManager.Update(student);

            // Want to change password?
            if (editStudentViewModel.Password != null)
            {
                if (editStudentViewModel.Password != "")
                {
                    //result = userManager.ChangePassword(teacher.Id, teacher.PasswordHash, edited.Password);

                    PasswordHasher ph = new PasswordHasher();

                    string hashed = ph.HashPassword(editStudentViewModel.Password);

                    var updatedUserPw = context.Users.Find(student.Id);

                    updatedUserPw.PasswordHash = hashed;

                    context.Entry(updatedUserPw).State = EntityState.Modified;

                    context.SaveChanges();
                }
            }

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                }
            }

            return(RedirectToAction("_FullStudentListPartial"));
        }
Example #11
0
        // GET: Student/Edit/5
        public ActionResult Edit(Guid id)
        {
            if (!UserIsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var result = _studentQuery.Handle(new StudentInputGetById {
                StudentId = id
            });
            var student = new EditStudentViewModel
            {
                Id             = result.Student.Id,
                Email          = result.Student.Email.Address,
                FirstName      = result.Student.FirstName,
                LastName       = result.Student.LastName,
                Phone          = result.Student.Phone,
                Address        = result.Student.Address,
                City           = result.Student.City,
                Birthdate      = result.Student.Birthdate,
                Country        = result.Student.Country,
                SelectedCourse = result.Student.Course.CourseId,
                Gender         = result.Student.Gender,
                Courses        = GetComboboxCourse()
            };

            return(View(student));
        }
        public async Task <IHttpActionResult> EditStudent([FromUri] int id, [FromBody] EditStudentViewModel info)
        {
            #region Parameter validation

            if (info == null)
            {
                info = new EditStudentViewModel();
                Validate(info);
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            #endregion

            #region Find class

            var students = UnitOfWork.RepositoryStudent.Search();

            var student = await students.Where(x => x.Id == id).FirstOrDefaultAsync();

            if (student == null)
            {
                return(ResponseMessage(
                           Request.CreateErrorResponse(HttpStatusCode.NotFound, HttpMessages.StudentNotFound)));
            }

            #endregion

            #region Update student information

            // Check whether information has been updated or not.
            var bHasInformationChanged = false;

            // Phone number is specified.
            if (info.Phone != student.Phone)
            {
                student.Phone          = info.Phone;
                bHasInformationChanged = true;
            }

            // Status is defined.
            if (info.Status != null && info.Status != student.Status)
            {
                student.Status         = info.Status.Value;
                bHasInformationChanged = true;
            }

            // Information has been changed. Update the date time.
            if (bHasInformationChanged)
            {
                // Save information into database.
                await UnitOfWork.CommitAsync();
            }

            #endregion

            return(Ok(student));
        }
        public async Task <IActionResult> Edit(EditStudentViewModel model)
        {
            // Update the student
            await _studentService.UpdateAsync(model.Id, model.Form.Name);

            // Redirect back to the list
            return(RedirectToAction(nameof(Index)));
        }
Example #14
0
        public void UpdateUser(EditStudentViewModel viewmodel)
        {
            var obj = GetUserById(viewmodel.User.Id);

            obj.Email    = viewmodel.Email;
            obj.Password = viewmodel.Password;
            obj.UserName = viewmodel.UserName;
        }
Example #15
0
 public EditStudentView(EditStudentViewModel viewmodel)
 {
     InitializeComponent();
     NumericUpDown.ValueChanged += viewmodel.ValueChanged;
     viewmodel.CurrentWindow     = this;
     Loaded     += viewmodel.ViewAppear;
     DataContext = viewmodel;
 }
Example #16
0
        public IActionResult Edit(int id, PaginationParameters paginationParameters)
        {
            StudentWithSchool    student              = _studentService.GetStudent(id);
            StudentViewModel     studentViewModel     = _mapper.Map <StudentWithSchool, StudentViewModel>(student);
            EditStudentViewModel editStudentViewModel = new EditStudentViewModel(studentViewModel, paginationParameters);

            return(View(editStudentViewModel));
        }
 public ActionResult Edit([Bind(Include = "Student")] EditStudentViewModel vm)
 {
     if (ModelState.IsValid)
     {
         repo.EditStudent(vm);
         return(RedirectToAction("Index"));
     }
     return(View(vm));
 }
Example #18
0
        public async Task <IActionResult> Edit(long id,
                                               [Bind("Id,FirstName,LastName,MatricNumber,Email,Age,Parent,Class")] EditStudentViewModel student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Parent parent = _context.Parent.Where(p => string.Compare(p.Fullname, student.Parent, true) == 0).FirstOrDefault();
                    if (parent == null)
                    {
                        return(View(student));
                    }

                    Classroom classroom = _context.Classroom.Where(c => string.Compare(c.ClassName, student.Class, true) == 0).FirstOrDefault();
                    if (classroom == null)
                    {
                        return(View(student));
                    }

                    var _student = _context.Student.Find(student.Id);
                    if (_student == null)
                    {
                        return(View(student));
                    }


                    _student.FirstName    = student.FirstName;
                    _student.LastName     = student.LastName;
                    _student.MatricNumber = student.MatricNumber;
                    _student.Email        = student.Email;
                    _student.Age          = student.Age;
                    _student.Parent       = parent;
                    _student.Class        = classroom;

                    _context.Update(_student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Example #19
0
        public void UpdateStudent(EditStudentViewModel editedStudent)
        {
            Student student = new Student();

            student       = GetStudentByID(editedStudent.StudentId);
            student.Name  = editedStudent.Name;
            student.Email = editedStudent.Email;

            db.SaveChanges();
        }
Example #20
0
        public IActionResult Edit(EditStudentViewModel student)
        {
            if (!ModelState.IsValid)
            {
                return(View(student));
            }

            _studentService.Edit(_mapper.Map <StudentDTO>(student.StudentViewModel));
            return(RedirectToAction("Index", "Home", new { PageNumber = student.PaginationParameters.PageNumber, PageSize = student.PaginationParameters.PageSize }));
        }
Example #21
0
        public ActionResult Edit(EditStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var service = new StudentService(HttpContext.GetOwinContext().Get <WebAppDbContext>());
                service.EditStudent(model);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Example #22
0
        public async Task <ActionResult> Edit(EditStudentViewModel student)
        {
            try
            {
                await _studentService.EditAsync(student);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Example #23
0
        public void Update(EditStudentViewModel viewModel)
        {
            var obj = GetById(viewModel.Id);

            obj.AvatarPath = viewModel.AvatarPath;
            obj.Average    = viewModel.Average;
            obj.BirthDay   = viewModel.BirthDay;
            obj.City       = viewModel.City;
            obj.FirstName  = viewModel.FirstName;
            obj.Gender     = viewModel.Gender;
            obj.LastName   = viewModel.LastName;
            obj.SNO        = viewModel.SNO;
        }
Example #24
0
        public EditStudentViewModel MapStudent(User user)
        {
            var model = new EditStudentViewModel {
                UserId    = user.Id,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Sex       = user.Sex,
                Email     = user.Email,
                Phone     = user.PhoneNumber
            };

            return(model);
        }
Example #25
0
        public void EditStudent(EditStudentViewModel model)
        {
            var user = db.Users.Find(model.UserId);

            user.FirstName   = model.FirstName;
            user.LastName    = model.LastName;
            user.Sex         = model.Sex;
            user.Email       = model.Email;
            user.UserName    = model.Email;
            user.PhoneNumber = model.Phone;

            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();
        }
Example #26
0
        public ActionResult Edit(EditStudentViewModel editedStudent)
        {
            if (editedStudent.Email == null || editedStudent.Name == null ||
                editedStudent.StudentId == 0)
            {
                return(RedirectToAction("Index"));
            }

            studentService = new StudentService();

            studentService.UpdateStudent(editedStudent);

            return(RedirectToAction("Index"));
        }
Example #27
0
        public async Task <IActionResult> EditStudent(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                return(this.NotFound());
            }

            EditStudentViewModel model = new EditStudentViewModel();

            model.ApplicationUser = this.mapper.Map <ApplicationUser, BaseApplicationUserVM>(await this.userManager.GetUserAsync(this.User), model.ApplicationUser);
            model.Student         = this.usersService.GetStudentByUserId <BaseStudentVM>(userId);
            model.Student.Stages  = this.stagesService.GetAllAsSelectList();
            return(this.View(model));
        }
Example #28
0
        public ViewResult Edit(int id)
        {
            Student student            = _employeeRepository.GetStudent(id);
            EditStudentViewModel model = new EditStudentViewModel
            {
                Name      = student.Name,
                Email     = student.Email,
                Gender    = student.Gender,
                Age       = student.Age,
                StudentId = student.StudentId
            };

            return(View(model));
        }
Example #29
0
        public async Task EditAsync(EditStudentViewModel student)
        {
            if (student.Comment != null)
            {
                Comment comment = new Comment
                {
                    StudentId = student.Id,
                    Text      = student.Comment,
                    Create    = DateTime.Now
                };
                await _unitOfWork.Comments.CreateAsync(comment);
            }
            if (student.Status != student.StudentStatusEnum)
            {
                var something = await GetStudentInterface(student.StudentStatusEnum);

                student.IStatusStudent = something;
                IStatusStudent statusStudent = null;
                switch (student.Status)
                {
                case StudentStatusEnum.interested:
                    statusStudent = new StatusInterested(_unitOfWork);
                    break;

                case StudentStatusEnum.trial:
                    statusStudent = new StatusTrial(_unitOfWork);
                    break;

                case StudentStatusEnum.studying:
                    statusStudent = new StatusStudying(_unitOfWork);
                    break;

                case StudentStatusEnum.archive:
                    statusStudent = new StatusArchive(_unitOfWork);
                    break;
                }
                statusStudent?.CreatePeriod(student);
                statusStudent?.CreateComment(student);
                var model = Mapper.Map <Student>(student);
                _unitOfWork.Student.UpdateAsync(model);
                await _unitOfWork.CompleteAsync();
            }
            else
            {
                var model = Mapper.Map <Student>(student);
                _unitOfWork.Student.UpdateAsync(model);
                await _unitOfWork.CompleteAsync();
            }
        }
Example #30
0
        public ActionResult Edit(EditStudentViewModel model)
        {
            if (!DataRepository.IsChild <Data.Models.Student>(SessionItems.TeacherId.Value, model.Student))
            {
                throw new AccessViolationException($"User does not have access to {model.Student.Id.ToString()}");
            }
            if (!ModelState.IsValid)
            {
                model.Classes = GetClasses(model.Student.ClassId).ToList();
                return(View(model));
            }

            DataRepository.UpdateStudent(model.Student);
            return(RedirectToAction("Index", new { selectedClassId = model.Student.ClassId }));
        }