internal BusinessObjectActionReport <RatingDataRepositoryActionStatus> Create(CMSContentRating cmsContentRating, bool getBaseRatingInfo, bool allowSelfRating, out BaseRatingInfo baseRatingInfo) { baseRatingInfo = null; BusinessObjectActionReport <RatingDataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <RatingDataRepositoryActionStatus>(RatingDataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContentRating); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_ContentRatings_InsertOrUpdate(cmsContentRating.Rating, cmsContentRating.CMSContentId, cmsContentRating.CMSUserId, allowSelfRating); if (getBaseRatingInfo) { baseRatingInfo = dataStoreContext.cms_Contents_GetBaseRatingInfo(cmsContentRating.CMSContentId); } } } catch (Exception ex) { _Log.Error("Error at cms_ContentRatings_InsertOrUpdate, cms_Contents_GetBaseRatingInfo", ex); throw new DataStoreException(ex, true); } switch (num) { case -1: businessObjectActionReport.Status = RatingDataRepositoryActionStatus.SelfRatingNotAllowed; break; case 0: cmsContentRating.DateCreatedUtc = DateTime.UtcNow; break; default: businessObjectActionReport.Status = RatingDataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSContentRating {0} was not inserted at the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsContentRating), num); break; } } else { businessObjectActionReport.Status = RatingDataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSContentRating {0} was not inserted at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsContentRating) , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }
internal BusinessObjectActionReport <DataRepositoryActionStatus> Update(CMSContentRating cmsContentRating) { BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success); businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(cmsContentRating); if (businessObjectActionReport.ValidationResult.IsValid) { int num = 0; try { using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext()) { num = dataStoreContext.cms_ContentRatings_InsertOrUpdate(cmsContentRating.Rating, cmsContentRating.CMSContentId, cmsContentRating.CMSUserId, true); } } catch (Exception ex) { _Log.Error("Error at cms_ContentRatings_InsertOrUpdate", ex); throw new DataStoreException(ex, true); } if (num == 0) { cmsContentRating.DateCreatedUtc = DateTime.UtcNow; } else { businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError; _Log.ErrorFormat("CMSContentRating {0} was not updated at the database (ErrorCode: {1})." , DebugUtility.GetObjectString(cmsContentRating), num); } } else { businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed; _Log.WarnFormat("CMSContentRating {0} was not updated at the database because the validation failed.\nReport: {1}" , DebugUtility.GetObjectString(cmsContentRating), businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII)); } return(businessObjectActionReport); }