Esempio n. 1
0
        public ActionResult <ContactUpdateDto> UpdateContact(int id, ContactUpdateDto contactUpdateDto)
        {
            var existingContactFromDb = _repository.GetContactById(id);

            if (existingContactFromDb == null)
            {
                return(NotFound());
            }
            _mapper.Map(contactUpdateDto, existingContactFromDb);
            _repository.UpdateContact(existingContactFromDb);
            _repository.SaveChanges();
            return(NoContent());
        }
        public IActionResult UpdateContact(string id, [ModelBinder(BinderType = typeof(JsonModelBinder))] ContactDTO contact, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                if (file != null && file.Length > 0 && Path.GetExtension(file.FileName) == "JPEG")
                {
                    contact.Image = file;
                }

                if (_repo.UpdateContact(id, contact))
                {
                    return(Ok());
                }
                else
                {
                    ModelState.AddModelError("Update Contact", "Error Occured");
                }
            }
            return(BadRequest(ModelState));
        }