public IActionResult UpdateCountryDetails(int id, UpdateCountryDTO updateCountryDTO)
        {
            LoginToken <Administrator> admin_token = DesirializeToken();

            if (id == 0)
            {
                return(NotFound());
            }

            if (id != updateCountryDTO.Id)
            {
                return(BadRequest());
            }

            Country country = _mapper.Map <Country>(updateCountryDTO);

            try
            {
                _loggedInAdministratorFacade.UpdateCountryDetails(admin_token, country);

                _countriesManager.SetCountry(admin_token, country);
            }
            catch (RecordAlreadyExistsException)
            {
                return(Conflict());
            }

            return(NoContent());
        }
Esempio n. 2
0
 public async Task <IActionResult> UpdateCountry(Guid id, [FromBody] UpdateCountryDTO country)
 {
     return(await _mediator.Send(new UpdateCountryRequest()
     {
         Id = id, Country = country
     }));
 }
Esempio n. 3
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            // id が 1 より小さい
            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }

            try
            {
                var country = await _unitOfWork.Countries.Get(q => q.Id == id);

                if (country == null)
                {
                    _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCountry)}");
                    return(BadRequest("Submitted data is invalid"));
                }

                _mapper.Map(countryDTO, country);
                _unitOfWork.Countries.Update(country);
                await _unitOfWork.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Something Went Wrong in the {nameof(UpdateCountry)}");
                return(StatusCode(500, "Internal Server Error. Please Try Again Later."));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            var location = GetControllerActionNames();

            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"{location}: Invalid UPDATE attempt");
                return(BadRequest(ModelState));
            }

            try
            {
                var country = await _unitOfWork.Countries.Get(c => c.Id == id);

                if (country == null)
                {
                    _logger.LogError($"{location}: Invalid UPDATE attempt");
                    return(BadRequest("Country not found"));
                }


                _mapper.Map(countryDTO, country);

                _unitOfWork.Countries.Update(country);
                await _unitOfWork.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{location}: Error", ex));
            }
        }
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            // Validate incoming JSON Form Data for Creating Hotel
            // ModelState IsValid checks if all the required data for CreateHotelDTO is in the JSON request
            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"Invalid POST attempt in {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }

            try
            {
                var country = await _unitOfWork.Countries.Get(q => q.Id == id);

                if (country == null)
                {
                    _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCountry)}");
                    return(BadRequest("Submitted data is invalid"));
                }

                // if not null then proceed with the update
                // so whatever is in hotelDTO put this into the "hotel" variable
                _imapper.Map(countryDTO, country);
                _unitOfWork.Countries.Update(country);
                await _unitOfWork.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Something went wrong in the {nameof(UpdateCountry)}");
                return(StatusCode(500, "Internal server Error. Please try again Later."));
            }
        }
Esempio n. 6
0
        public void Update(UpdateCountryDTO dto)
        {
            var country = _Db.Countries.SingleOrDefault(x => x.Id == dto.Id && !x.IsDelete);

            country.NameAr = dto.NameAr;
            country.NameEn = dto.NameEn;
            _Db.Countries.Update(country);
            _Db.SaveChanges();
        }
Esempio n. 7
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            if (!ModelState.IsValid || id < 0)
            {
                _logger.LogError($"Invalid POST attempt in  {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }
            var country = await _unitOfWork.Countries.Get(q => q.Id == id);

            if (country == null)
            {
                _logger.LogError($"Invalid UPDATE attempt in  {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }
            _mapper.Map(countryDTO, country);
            _unitOfWork.Countries.Update(country);
            await _unitOfWork.save();

            return(NoContent());
        }
Esempio n. 8
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"Invalid PUT attempt in {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }

            var country = await _unitOfWork.Countries.Get(c => c.Id == id);

            if (country == null)
            {
                return(NotFound($"Country with the specified id {id} was not found."));
            }

            _mapper.Map(countryDTO, country);
            _unitOfWork.Countries.Update(country);
            await _unitOfWork.Save();

            return(NoContent());
        }
Esempio n. 9
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            _logger.LogInformation("Updating Country!");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var country = await _unitOfWork.Countries.Get(q => q.Id == id);

            if (country == null)
            {
                _logger.LogError($"country not found {nameof(UpdateCountry)}");
                return(NotFound());
            }

            _mapper.Map(countryDTO, country);
            _unitOfWork.Countries.Update(country);
            await _unitOfWork.Save();

            return(NoContent());
        }
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"Invalid UPDATE attempt In {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }

            var country = await _unitOfWork.Countries.Get(q => q.Id == id);     //get a Hotel with an id that is equivalent to the id that come throught as parameter

            if (country == null)
            {
                _logger.LogError($"Invalid UPDATE attempt In {nameof(UpdateCountry)}");
                return(BadRequest("Submitted data is invalid"));
            }

            _mapper.Map(countryDTO, country);
            _unitOfWork.Countries.Update(country);
            await _unitOfWork.Save();

            return(NoContent());
        }
Esempio n. 11
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"Invalid Update attempt in {nameof(UpdateCountry)}");
                return(BadRequest(ModelState));
            }

            var country = await _unitOfWork.Countries.Get(q => q.Id == id);

            if (country == null)
            {
                _logger.LogError($"Invalid Update attempt in {nameof(UpdateCountry)}");
                return(BadRequest("Submitted data is invalid"));
            }

            //update 2nd using 1st
            _mapper.Map(countryDTO, country);

            _unitOfWork.Countries.Update(country);
            await _unitOfWork.Save();

            return(NoContent());
        }
Esempio n. 12
0
        public async Task <IActionResult> UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO)
        {
            try
            {
                var country = await _unitOfWork.Countries.Get(country => country.Id == id);

                if (country == null)
                {
                    _logger.LogError($"Invalid UPDATE attemp in {nameof(UpdateCountry)}");
                    return(BadRequest("Submitted data is invalid"));
                }

                _mapper.Map(countryDTO, country);
                _unitOfWork.Countries.Update(country);
                await _unitOfWork.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Something went wrong in the {nameof(UpdateCountry)}");
                return(StatusCode(500, "Internal server error. Please try again later"));
            }
        }
 public IActionResult Update([FromForm] UpdateCountryDTO dto)
 {
     _CountryService.Update(dto);
     return(Ok(GetRespons()));
 }