public bool AddTeacher(NewPersonDTO request)
 {
     try
     {
         return(_TeachersRepo.AddTeacher(request.ClientId, request.Name, request.LastName1, request.LastName2, request.Birthday, request.Genre, request.Email, request.Phone));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
 public bool AddStudent(NewPersonDTO request)
 {
     try
     {
         return(_StudentsRepo.AddStudent(request.ClientId, request.Name, request.LastName1, request.LastName2, request.Birthday, request.Genre));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
 public bool AddParent(NewPersonDTO request)
 {
     try
     {
         return(_ParentsRepo.AddParentForStudent(request.ClientId, request.Name, request.LastName1, request.LastName2,
                                                 request.Birthday, request.Genre, request.Email, request.Phone, request.StudentId,
                                                 request.Cedula));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 4
0
        public string validateNewUser(NewPersonDTO person)
        {
            string ret = "";

            if (string.IsNullOrEmpty(person.Name))
            {
                ret = "Name must not be empty";
            }
            if (string.IsNullOrEmpty(person.Surname))
            {
                ret = "Surname must not be empty";
            }

            return(ret);
        }
Esempio n. 5
0
        public void Create(NewPersonDTO model)
        {
            try
            {
                Person person = new Person();
                person = mapper.Map <Person>(model);

                context.Persons.Add(person);

                context.SaveChanges();
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 6
0
        public async Task <ActionResult <UserToken> > CreateUser([FromBody] NewPersonDTO model)
        {
            if (ModelState.IsValid)
            {
                string validPerson = _personService.validateNewUser(model);

                if (!string.IsNullOrEmpty(validPerson))
                {
                    return(BadRequest(validPerson));
                }

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    model.Points = _personService.AssignInitialPoints();

                    _personService.Create(model);

                    PersonDTO person = new PersonDTO {
                        Email = model.Email, Id = model.Id, Name = model.Name, Points = model.Points, Surname = model.Surname
                    };

                    return(BuildToken(person, new List <string>()));
                }
                else
                {
                    return(BadRequest("Username or password invalid"));
                }
            }
            else
            {
                return(BadRequest("Invalid model"));
            }
        }