public void Post([FromBody] CountryViewModel country) { ICountry countryModel; try { countryModel = _countryManager.GetCountry(country.CountryId); countryModel.Name = country.Name; countryModel.UrlName = country.UrlName; countryModel.Category = TourTypesConverter.ConvertFromString(country.Category); countryModel.ThreeStarsPrice = country.ThreeStarsPrice; countryModel.FourStarsPrice = country.FourStarsPrice; countryModel.FiveStarsPrice = country.FiveStarsPrice; countryModel.Description = country.Description; countryModel.PageContent = country.PageContent; } catch (CountryNotFoundException) { countryModel = _countryManager.CreateCountry( country.Name, country.UrlName, TourTypesConverter.ConvertFromString(country.Category), country.ThreeStarsPrice, country.FourStarsPrice, country.FiveStarsPrice, country.Description, country.PageContent ); } countryModel.PageContentBottom = country.PageContentBottom; countryModel.Title = country.Title; countryModel.MetaDescription = country.MetaDescription; countryModel.MetaKeywords = country.MetaKeywords; countryModel.PageHeader = country.PageHeader; var imageForDeleteCollection = countryModel.ImageIdCollection.Where(imageId => !country.OldImageCollection.Contains(imageId)).ToList(); foreach (var newImage in country.NewImageCollection) { var image = CreateImage(newImage); countryModel.AddImage(image.ImageId); } foreach (var imageId in imageForDeleteCollection) { countryModel.DeleteImage(imageId); } countryModel.Save(); }