Example #1
0
        public async Task <IActionResult> UpdateFamily(int id, [FromBody] Family family)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            if (id != family.FamilyId)
            {
                return(BadRequest(ErrorMessageContracts.MismatchedId));
            }

            var existing = await _context.Families.FindAsync(id);

            if (existing == null)
            {
                return(NotFound());
            }

            FamilyHelper.UpdateFamily(existing, family);

            try
            {
                _context.Families.Update(existing);
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(NoContent());
        }