public async Task <ExhibitResultModel> UpdateExhibit(ExhibitDomainModel updateExhibit) { var data = await _exhibitRepository.GetByIdAsync(updateExhibit.ExhibitId); ExhibitEntity exhibit = new ExhibitEntity { ExhibitId = updateExhibit.ExhibitId, AuditoriumId = updateExhibit.AuditoriumId, ExhibitionId = updateExhibit.ExhibitionId, ExhibitName = updateExhibit.Name, Year = updateExhibit.Year, PicturePath = updateExhibit.PicturePath }; var exhibitUpdate = _exhibitRepository.Update(exhibit); if (exhibitUpdate == null) { return(new ExhibitResultModel { IsSuccessful = false, ErrorMessage = Messages.EXHIBIT_UPDATE_ERROR, Exhibit = null }); } _exhibitRepository.Save(); ExhibitResultModel result = new ExhibitResultModel { IsSuccessful = true, ErrorMessage = null, Exhibit = new ExhibitDomainModel { ExhibitId = exhibitUpdate.ExhibitionId, AuditoriumId = exhibitUpdate.AuditoriumId, ExhibitionId = exhibitUpdate.ExhibitionId, Year = exhibitUpdate.Year, Name = exhibitUpdate.ExhibitName, PicturePath = exhibitUpdate.PicturePath, } }; return(result); }
public async Task <ExhibitResultModel> CreateExhibit(ExhibitDomainModel exhibitModel) { ExhibitEntity newExhibit = new ExhibitEntity { ExhibitId = exhibitModel.ExhibitId, ExhibitionId = exhibitModel.ExhibitionId, ExhibitName = exhibitModel.Name, Year = exhibitModel.Year, PicturePath = exhibitModel.PicturePath, AuditoriumId = exhibitModel.AuditoriumId, }; bool auditorium = false; var listOfAuditoriums = await _auditoriumsRepository.GetAll(); foreach (var item in listOfAuditoriums) { if (item.AuditoriumId == exhibitModel.AuditoriumId) { auditorium = true; } ; } if (auditorium == false) { return(new ExhibitResultModel { IsSuccessful = false, ErrorMessage = Messages.AUDITORIUM_WITH_THIS_ID_DOES_NOT_EXIST, Exhibit = null }); } bool exhibition = false; var listOfExhibitions = await _exhibitionsRepository.GetAll(); foreach (var item in listOfExhibitions) { if (item.ExhibitionId == exhibitModel.ExhibitionId) { exhibition = true; } ; } if (exhibition == false) { return(new ExhibitResultModel { IsSuccessful = false, ErrorMessage = Messages.EXHIBITION_WITH_THIS_ID_DOES_NOT_EXIST, Exhibit = null }); } var data = _exhibitRepository.Insert(newExhibit); if (data == null) { return(new ExhibitResultModel { IsSuccessful = false, ErrorMessage = Messages.EXHIBIT_WITH_THIS_ID_ALREADY_EXISTS, Exhibit = null }); } ExhibitResultModel domainModel = new ExhibitResultModel { IsSuccessful = true, ErrorMessage = null, Exhibit = new ExhibitDomainModel { ExhibitId = data.ExhibitId, ExhibitionId = data.ExhibitionId, Name = data.ExhibitName, Year = data.Year, PicturePath = data.PicturePath, AuditoriumId = data.AuditoriumId, } }; return(domainModel); }