public IActionResult Update(Family item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                return(Ok(_familyRepository.Update(item))); //or you can throw new Exception
            }
            catch
            {
                return(BadRequest(ModelState));
            }
        }
Esempio n. 2
0
        // POST api/<controller>
        public void Post([FromBody] List <Family> families)
        {
            using (SqlUnitOfWork unitOfWork = new SqlUnitOfWork("gp"))
            {
                FamilyRepository familyRepo = new FamilyRepository(unitOfWork);

                foreach (Family family in families)
                {
                    if (family.FamilyId == null)
                    {
                        familyRepo.Insert(family);
                    }
                    else
                    {
                        familyRepo.Update(family);
                    }
                }

                unitOfWork.Commit();
            }
        }