public IActionResult UpdatePhone(Guid organizationId, Guid phoneId, [FromBody] PhoneForUpdateDto phoneForUpdate)
        {
            if (organizationId == new Guid())
            {
                return(BadRequest());
            }

            if (phoneId == new Guid())
            {
                return(BadRequest());
            }

            if (!_unitOfWork.Organizations.IsOrganizationExists(organizationId))
            {
                return(NotFound());
            }

            if (!_unitOfWork.Phones.IsPhoneExists(organizationId, phoneId))
            {
                return(NotFound());
            }

            var phoneFromContext = _unitOfWork.Phones.GetPhone(organizationId, phoneId);

            _mapper.Map(phoneForUpdate, phoneFromContext);

            if (!_unitOfWork.Complete())
            {
                return(StatusCode(500, "A problem happened while handling your request!"));
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> UpdatePhone(int id, PhoneForUpdateDto phoneForUpdateDto)
        {
            var phoneFromRepo = await _repo.GetPhone(id);

            _mapper.Map(phoneForUpdateDto, phoneFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating phone details failed on save");
        }