Exemplo n.º 1
0
        public User UpdateStudent(string accountId, EnableStudentModel model)
        {
            var student = _studentRepository.GetByAccountNumber(accountId);

            if (student == null)
            {
                throw new NotFoundException("No se encontro el professor");
            }

            // mapeo
            student.AccountId        = model.AccountId;
            student.Name             = model.FirstName + " " + model.LastName;
            student.Password         = _encryption.Encrypt(model.Password);
            student.Major            = _majorServices.Find(model.MajorId);
            student.Campus           = "USPS";
            student.Email            = model.Email;
            student.ModificationDate = DateTime.Now;
            _studentRepository.Update(student);
            return(student);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostChangePassword(EnableStudentModel model)
        {
            var student = _studentsServices.FindNullable(model.AccountId);

            if (student != null)
            {
                if (((User)student).Status == 0)
                {
                    var updatedStudent = _studentsServices.UpdateStudent(model.AccountId, model);

                    // Send confirmation email

                    var encryptedAccountId = HexadecimalEncoding.ToHexString(model.AccountId);
                    _email.Send(model.Email,
                                "Hacer click en el siguiente link para activar su cuenta: " +
                                backEndSite +
                                "/api/Students/" + HttpContext.Current.Server.UrlEncode(encryptedAccountId) + "/Active",
                                "Vinculación");
                    return(Ok());
                }
                else
                {
                    throw new Exception("account is already active");
                }
            }
            else
            {
                var newStudent = new User();

                //mapeo
                newStudent.AccountId        = model.AccountId;
                newStudent.Email            = model.Email;
                newStudent.Password         = _encryption.Encrypt(model.Password);
                newStudent.Name             = model.FirstName + " " + model.LastName;
                newStudent.Major            = _majorServices.Find(model.MajorId);
                newStudent.Campus           = "USPS";
                newStudent.CreationDate     = DateTime.Now;
                newStudent.ModificationDate = DateTime.Now;
                newStudent.Status           = Data.Enums.Status.Inactive;
                newStudent.Finiquiteado     = false;

                _studentsServices.Add(newStudent);

                // Send confirmation email
                var encryptedAccountId = HexadecimalEncoding.ToHexString(model.AccountId);
                _email.Send(model.Email,
                            "Hacer click en el siguiente link para activar su cuenta: " +
                            backEndSite +
                            "/api/Students/" + HttpContext.Current.Server.UrlEncode(encryptedAccountId) + "/Active",
                            "Vinculación");
                return(Ok());
            }
            //_studentsServices.ChangePassword(model);
            //var stringparameter = HexadecimalEncoding.ToHexString(model.AccountId);
            //_email.Send(model.Email,
            //    "Hacer click en el siguiente link para activar su cuenta: " +
            //        backEndSite +
            //        "/api/Students/" + HttpContext.Current.Server.UrlEncode(stringparameter) +
            //        "/Active",
            //    "Vinculación");
            //return Ok();
        }