// POST: api/ListOC public void Post([FromBody] ListOfCountry value) { if (value != null) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ListOfCountry, ListOfCountryDTO>()).CreateMapper(); service.MakeList(mapper.Map <ListOfCountry, ListOfCountryDTO>(value)); } }
// PUT: api/ListOC/5 public void Put(int id, [FromBody] ListOfCountry value) { if (value != null) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ListOfCountry, ListOfCountryDTO>()).CreateMapper(); value.Id = id; service.EditListOC(mapper.Map <ListOfCountry, ListOfCountryDTO>(value)); } }
public void EditListOC(ListOfCountryDTO DTO)//(TourDTO tourDTO) { //ListOCDeserialize deserialize = new ListOCDeserialize(); //ListOfCountryDTO DTO = deserialize.deserializeVary(Vary); Tour tour = Database.Tours.Get(DTO.TourId); if (tour == null) { throw new ValidationException("Data - info/type is not found", ""); } ListOfCountry data = new ListOfCountry { Id = DTO.Id, CountryId = DTO.CountryId, TourId = DTO.TourId, }; Database.ListOfCountries.Update(data); Database.Save(); }
public void MakeList(ListOfCountryDTO listOCDDTO)//(ListOfCountryDTO listOCDDTO) { //IDeserialize<ListOfCountryDTO> deserializeList = new ListOCDeserialize(); //ListOfCountryDTO listOCDDTO = deserializeList.deserializeVary(data); Tour tour = Database.Tours.Get(listOCDDTO.TourId); Country country = Database.Countries.Get(listOCDDTO.CountryId); // валидация if (tour == null || country == null) { throw new ValidationException("Data - country/tour is not found", ""); } ListOfCountry listOC = new ListOfCountry { TourId = listOCDDTO.TourId, CountryId = listOCDDTO.CountryId, }; Database.ListOfCountries.Create(listOC); Database.Save(); }