Ejemplo n.º 1
0
        public ActionResult <PersonReadDto> CreatePerson(PersonCreateDto personCreateDto)
        {
            var personModel = _mapper.Map <Person>(personCreateDto);

            _repository.CreatePerson(personModel);
            _repository.SaveChanges();

            var personReadDto = _mapper.Map <PersonReadDto>(personModel);

            return(CreatedAtRoute(nameof(GetPersonById), new { Id = personReadDto.Id }, personReadDto));
        }
Ejemplo n.º 2
0
        public ActionResult <PersonReadDto> CreatePerson(PersonCreateDto personCreateDto)
        {
            var personModel = _mapper.Map <Person>(personCreateDto);

            _personRepository.CreatePerson(personModel);
            _personRepository.SaveChanges();

            var personReadDto = _mapper.Map <PersonReadDto>(personModel);

            //Look at Microsoft documentation on CreatedAtRoute method
            return(CreatedAtRoute(nameof(GetPersonById), new { Id = personReadDto.Personid }, personReadDto));
        }
        public ActionResult <PersonReadDTO> CreatePerson(PersonCreateDTO personCreateDTO)
        {
            var Person = _mapper.Map <Person>(personCreateDTO);

            Person.Id = new Guid();

            _PersonRepo.CreatePerson(Person);
            _PersonRepo.SaveChanges();
            // sends location and 201 status with header
            return(CreatedAtRoute(nameof(GetPersonById), new { Id = Person.Id }, personCreateDTO));
            // sends 200 status only
            // return Ok(_mapper.Map<PersonReadDTO>(_PersonRepo.GetPersonById(Person.Id)));
        }
Ejemplo n.º 4
0
        public ActionResult CreateNewPerson(PersonContactViewModel pcv)
        {
            if (!ModelState.IsValid)
            {
                var modelErrors = new List <string>();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var modelError in modelState.Errors)
                    {
                        modelErrors.Add(modelError.ErrorMessage);
                    }
                }

                foreach (var item in modelErrors)
                {
                    System.Console.WriteLine(item);
                }
            }
            try
            {
                Person prs = new Person();
                // mapez datele
                prs.Nume    = pcv.Person.Nume;
                prs.Prenume = pcv.Person.Prenume;
                // le adaug in baza de date
                _personRepo.CreatePerson(prs);
                // salvez modificarile
                _personRepo.SaveChanges();

                // obiect de tipul contact
                ContactInfo cti = new ContactInfo();
                // mapez datele
                cti.PersonRef = prs.PersonId;
                cti.Adresa    = pcv.ContactInfo.Adresa;
                cti.NrTelefon = pcv.ContactInfo.NrTelefon;
                cti.Email     = pcv.ContactInfo.Email;
                cti.CodPostal = pcv.ContactInfo.CodPostal;
                cti.Person    = _personRepo.GetPersonById(cti.PersonRef);

                _contactRepo.CreateContacInfo(cti);

                _contactRepo.SaveChanges();
                return(RedirectToAction("Index", "personcontactviewmodels"));
            } catch (Exception e)
            {
                return(View("NewPerson", pcv));
            }
        }