示例#1
0
        public ActionResult RegisterProfesor()
        {
            var viewModel = new ProfesorFormViewModel()
            {
                Specializations = _unitOfWork.Specializations.GetSpecializations()
                                  // Profesors = _ProfesorRepository.GetProfesor()
            };

            return(View("ProfesorForm", viewModel));
        }
示例#2
0
        public ActionResult Edit(ProfesorFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Specializations = _unitOfWork.Specializations.GetSpecializations();
                return(View(viewModel));
            }

            var ProfesorInDb = _unitOfWork.Profesors.GetProfesor(viewModel.Id);

            ProfesorInDb.Id               = viewModel.Id;
            ProfesorInDb.Name             = viewModel.Name;
            ProfesorInDb.Phone            = viewModel.Phone;
            ProfesorInDb.Address          = viewModel.Address;
            ProfesorInDb.IsAvailable      = viewModel.IsAvailable;
            ProfesorInDb.SpecializationId = viewModel.Specialization;

            _unitOfWork.Complete();

            return(RedirectToAction("Details", new { id = viewModel.Id }));
        }
示例#3
0
        public ActionResult Edit(int id)
        {
            var Profesor = _unitOfWork.Profesors.GetProfesor(id);

            if (Profesor == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new ProfesorFormViewModel()
            {
                Id              = Profesor.Id,
                Name            = Profesor.Name,
                Phone           = Profesor.Phone,
                Address         = Profesor.Address,
                IsAvailable     = Profesor.IsAvailable,
                Specialization  = Profesor.SpecializationId,
                Specializations = _unitOfWork.Specializations.GetSpecializations()
            };

            return(View(viewModel));
        }
示例#4
0
        public async Task <ActionResult> RegisterProfesor(ProfesorFormViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = viewModel.RegisterViewModel.Email,
                    Email    = viewModel.RegisterViewModel.Email,
                    IsActive = true
                };
                var result = await UserManager.CreateAsync(user, viewModel.RegisterViewModel.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, RoleName.ProfesorRoleName);
                    Profesor Profesor = new Profesor()
                    {
                        Name             = viewModel.Name,
                        Phone            = viewModel.Phone,
                        Address          = viewModel.Address,
                        IsAvailable      = true,
                        SpecializationId = viewModel.Specialization,
                        PhysicianId      = user.Id
                    };
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, Profesor.Name));
                    //Mapper.Map<ProfesorFormViewModel, Profesor>(model, Profesor);
                    _unitOfWork.Profesors.Add(Profesor);
                    _unitOfWork.Complete();
                    return(RedirectToAction("Index", "Profesors"));
                }

                this.AddErrors(result);
            }

            viewModel.Specializations = _unitOfWork.Specializations.GetSpecializations();

            // If we got this far, something failed, redisplay form
            return(View("ProfesorForm", viewModel));
        }