コード例 #1
0
        public User UpdateProfessor(string accountId, EnableProfessorModel model)
        {
            var professor = _professorRepository.GetByAccountId(accountId);

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

            // mapeo
            professor.AccountId        = model.AccountId;
            professor.Name             = model.FirstName + " " + model.LastName;
            professor.Password         = _encryption.Encrypt(model.Password);
            professor.Major            = null;
            professor.Campus           = "USPS";
            professor.Email            = model.Email;
            professor.ModificationDate = DateTime.Now;
            professor.Status           = Status.Inactive;

            _professorRepository.Update(professor);
            _professorRepository.Save();
            return(professor);
        }
コード例 #2
0
        public IHttpActionResult EnableProfessor(EnableProfessorModel model)
        {
            /* check if the account Id exists on the system
             *  if exists, check
             *      if the status = inactive (0)
             *          update account information and send email
             *      else
             *          cannot update information
             *  else -> account doesnt exist
             *      create account with the model
             *      send email
             */

            var professor = _professorsServices.FindNullable(model.AccountId);

            // Check if account exists
            if (professor != null)
            {
                // Check if account is inactive
                if (((User)professor).Status == 0)
                {
                    var updatedProfessor = _professorsServices.UpdateProfessor(model.AccountId, model);

                    // Send confirmation email

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

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

                _professorsServices.AddProfessor(newProfessor);

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