public IActionResult Create(AddPersonBindingModel bindingModel)
        {
            var personToCreate = new Person
            {
                Title     = bindingModel.Title,
                Name      = bindingModel.Name,
                Address   = bindingModel.Address,
                Email     = bindingModel.Email,
                CreatedAt = DateTime.Now
            };

            dbContext.People.Add(personToCreate);
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult <Person> CreatePerson([FromBody] AddPersonBindingModel BindingModel)
        {
            var _Person = _ApplicationDbContext.Persons.FirstOrDefault(opt => opt.EmailAddress == BindingModel.EmailAddress);

            if (_Person != null)
            {
                return(Conflict());
            }
            //check existing data before creating
            var PersonToCreate = new Person()
            {
                Name         = BindingModel.Name,
                Address      = BindingModel.Address,
                EmailAddress = BindingModel.EmailAddress,
                Phone        = BindingModel.Phone,
                CreatedDate  = DateTime.Now,
                IsActive     = true
            };

            _ApplicationDbContext.Persons.Add(PersonToCreate);
            _ApplicationDbContext.SaveChanges();
            return(Created($"/get-person/{PersonToCreate.ID}", PersonToCreate));
            //return Ok(PersonToCreate);
        }