public async Task <ActionResult <CountryDto> > ChangeCountryByID(int id, [FromBody] CountryDto countryDto)
        {
            try
            {
                var oldCountry = await _countryRepo.GetCountryById(id);

                if (oldCountry == null)
                {
                    return(NotFound($"Couldn't find any country with id: {id}"));
                }

                var newCountry = _mapper.Map(countryDto, oldCountry);
                _countryRepo.Update(newCountry);

                if (await _countryRepo.Save())
                {
                    return(NoContent());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
            return(BadRequest());
        }
Exemplo n.º 2
0
        public Country Edit(int id, CreateCountryViewModel edit)
        {
            Country editedcountry = new Country()
            {
                CountryId = id, CountryName = edit.CountryName
            };

            return(_countryRepo.Update(editedcountry));
        }
Exemplo n.º 3
0
        public Country Edit(int id, Country country)
        {
            Country editedCountry = new Country()
            {
                Id = id, CountryName = country.CountryName
            };

            return(_countryRepo.Update(editedCountry));
        }
Exemplo n.º 4
0
        public Country Edit(int id, CreateCountry country)
        {
            Country originCountry = FindById(id);

            if (originCountry == null)
            {
                return(null);
            }
            originCountry.CountryName = country.CountryName;
            originCountry             = _countryRepo.Update(originCountry);

            return(originCountry);
        }
Exemplo n.º 5
0
        public Country Edit(int id, CreateCountry country)
        {
            Country newCountry = FindbyId(id);

            if (newCountry == null)
            {
                return(null);
            }
            newCountry.CountryName = country.CountryName;
            newCountry             = _countryRepo.Update(newCountry);

            return(newCountry);
        }
        public Country Edit(int id, EditCountryViewModel countryVM)
        {
            Country originalCountry = FindBy(id);

            if (originalCountry == null)
            {
                return(null);
            }

            originalCountry.Name   = countryVM.CreateVM.Name;
            originalCountry.Cities = countryVM.CreateVM.CityList;
            originalCountry        = _countryRepo.Update(originalCountry);

            return(originalCountry);
        }
Exemplo n.º 7
0
        public Country Edit(int id, EditCountryViewModel countryvmodel)
        {
            Country OriginalCountry = FindBy(id);

            if (OriginalCountry == null)
            {
                return(null);
            }

            OriginalCountry.Name  = countryvmodel.Createveiwmodelforcntr.Name;
            OriginalCountry.Towns = countryvmodel.Createveiwmodelforcntr.CityList;


            return(_countryRepo.Update(OriginalCountry));
        }
Exemplo n.º 8
0
        public Country Edit(int id, CreateCountry country)
        {
            Country c = FindById(id);

            if (c == null)
            {
                return(null);
            }

            c.CountryName = country.CountryName;

            c = _countryRepo.Update(c);

            return(c);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> EditAsync(CountryEditVM model)
        {
            if (ModelState.IsValid)
            {
                var country = _countryRepos.GetAll().FirstOrDefault(c => c.Name == model.Name);
                if (country == null)
                {
                    var serverPath = _env.ContentRootPath;   //Directory.GetCurrentDirectory(); //_env.WebRootPath;
                    var folerName  = @"\wwwroot\Uploads\";
                    var path       = serverPath + folerName; //

                    System.IO.File.Delete(Path.Combine(path, _countryRepos.GetById(model.Id).Flag));

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    string ext      = Path.GetExtension(model.Flag.FileName);
                    string fileName = Path.GetRandomFileName() + ext;

                    string filePathSave = Path.Combine(path, fileName);

                    // сохраняем файл в папку Files в каталоге wwwroot
                    using (var fileStream = new FileStream(filePathSave, FileMode.Create))
                    {
                        await model.Flag.CopyToAsync(fileStream);
                    }

                    _countryRepos.Update(
                        new Country
                    {
                        Id         = model.Id,
                        Name       = model.Name,
                        Flag       = fileName,
                        DateModify = DateTime.Now
                    });
                }

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Дані вказано не коректно");
            return(View(model));
        }
Exemplo n.º 10
0
 public Country Edit(Country country)
 {
     return(_countryRepo.Update(country));
 }