Ejemplo n.º 1
0
        public async Task <IActionResult> PutEmergencyCintact(int id, [FromBody] EmergencyContactFormViewModel emergencyContact)
        {
            /*if (id != emergency.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.EmergencyContacts.FindAsync(id);

                {
                    model.NameOfContact = emergencyContact.NameOfContact;
                    model.Relationship  = emergencyContact.Relationship;
                    model.PhoneNumber   = emergencyContact.PhoneNumber;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.EmergencyContacts.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmergencyContactExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <EmergencyContact> > PostEmergencyContact([FromBody] EmergencyContactFormViewModel emergencyContact)
        {
            VerifyUser();
            var model = new EmergencyContact()
            {
                NameOfContact = emergencyContact.NameOfContact,
                Relationship  = emergencyContact.Relationship,
                PhoneNumber   = emergencyContact.PhoneNumber
            };

            EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);
            _context.EmergencyContacts.Add(model);
            await _context.SaveChangesAsync();

            return(Created("", model));
        }