public Domain.Entities.Student Add(Domain.Entities.Student entity)
        {
            if (!_person.CheckIfExists(entity.Person))
            {
                try
                {
                    _person.Add(entity.Person);
                }
                catch (Exception ex)
                {
                    entity.AddError(ex.Message);
                    return(entity);
                }
            }

            if (VerifyStudentAlreadyEnrolled(entity))
            {
                entity.AddError("Estudante já matriculado");
                return(entity);
            }

            //TODO INCLUIR VERIFICAÇÃO SE ESTUDANTE TENTANDO SE MATRICULAR É PROFESSOR NO CURSO
            entity.EnrollmentID = GenerateEnrollmentID(entity);

            entity.Status = EEnrollmentStatus.WAITING_APROVEMENT;

            _studentRepository.Add(entity);

            //check if the person is a professor
            return(entity);
        }
        public IActionResult Create(PersonCreateModel newPerson)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (newPerson.PersonConsent)
                    {
                        var person = new Person();
                        person.FirstName           = newPerson.FirstName;
                        person.MiddleName          = newPerson.MiddleName;
                        person.LastName            = newPerson.LastName;
                        person.ExtensionName       = newPerson.ExtensionName;
                        person.NameTitleId         = newPerson.NameTitleId;
                        person.Sex                 = newPerson.Sex;
                        person.DateOfBirth         = newPerson.DateOfBirth;
                        person.CivilStatus         = newPerson.CivilStatus;
                        person.ContactNumber       = newPerson.ContactNumber;
                        person.DateCreated         = DateTime.Now;
                        person.DateTimeLastUpdated = person.DateCreated;
                        person.PersonConsent       = newPerson.PersonConsent;

                        _person.Add(person);
                        return(RedirectToAction("Index"));
                    }
                    return(View(newPerson));
                }
            }
            catch (Exception err)
            {
                ModelState.AddModelError(err.ToString(), "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }
            return(View(newPerson));
        }
        public IActionResult Create(PersonCreateModel newPerson)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (newPerson.PersonConsent)
                    {
                        var person = Mapper.Map <PersonCreateModel, Person>(newPerson);
                        _person.Add(person);
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    return(View(newPerson));
                }
            }
//            catch (Exception err)
            catch (Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException err)
            {
                ModelState.AddModelError(err.ToString(), "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }

            ////PopulateWorksDropDownList(newPerson.WorkId);
            ////PopulateNameTitleDropDownList(newPerson.NameTitleId);
            ////PopulateReligionDropDownList(newPerson.ReligionId);
            return(View(newPerson));
        }
예제 #4
0
        public async Task <IActionResult> Add([FromBody] Person person)
        {
            try
            {
                if (person == null)
                {
                    return(BadRequest());
                }

                await _person.Add(person);

                return(Ok(person));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
예제 #5
0
        public IActionResult AddPerson(Person person)
        {
            var checkPerson = _personRepo.Read(person.Id);

            if (checkPerson == null)
            {
                _personRepo.Add(person);
                return(RedirectToAction("Index", "Person"));
            }
            return(View());
        }
예제 #6
0
        public async Task <IActionResult> Post([FromForm] PersonDTO person)
        {
            if (person is null)
            {
                return(NoContent());
            }
            var byteArray = await _personRepository.GetByteArray(person.Picture);

            var personItem = new Person()
            {
                Name    = person.Name,
                Email   = person.Email,
                Picture = byteArray
            };
            await _personRepository.Add(personItem);

            return(Ok());
        }
예제 #7
0
        public async Task <IActionResult> Post([FromForm] PersonDTO person)
        {
            if (person is null)
            {
                return(NoContent());
            }
            var pictureUrl = await _personRepository.UploadBlobFileAsync(person.Picture);

            var personItem = new Person()
            {
                Name    = person.Name,
                Email   = person.Email,
                Picture = pictureUrl
            };
            await _personRepository.Add(personItem);

            return(Ok());
        }
예제 #8
0
        public IActionResult Post([FromBody] Domain.Entities.Person person)
        {
            try
            {
                var result = _person.Add(person);

                _unitOfWork.Commit();

                if (result.Errors.Any())
                {
                    return(BadRequest(result.Errors));
                }


                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
예제 #9
0
        public Domain.Entities.Professor Add(Domain.Entities.Professor entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("Nenhuma informação de professor enviada");
            }

            if (!_person.CheckIfExists(entity.Person))
            {
                try
                {
                    _person.Add(entity.Person);
                    entity.PersonId = entity.Person.Id.Value;
                }
                catch (Exception ex)
                {
                    entity.AddError(ex.Message);
                    return(entity);
                }
            }

            if (entity.RelatedSubjects.Any())
            {
                var validationResult = VerifyIfProfessorIsACurrentStudentFromClass(entity);

                if (validationResult.Errors.Any())
                {
                    entity.AddError(validationResult.Errors.ToArray());
                    return(entity);
                }
            }

            _professorRepository.Add(entity);

            return(entity);
        }
예제 #10
0
 public void Add(Person person)
 {
     person.Id = person.DocumentId;
     _repository.Add(person);
 }
예제 #11
0
 public void Add(IPerson person)
 {
     person.Add();
 }
예제 #12
0
 public void WriteAdd()  //static tanımlayamayız çünkü instance olmazsa hangi sınıfı kullanacağını bilemeyiz.
 {
     _person.Add();
 }