private ValidatorResult ValidateBase(ValidatorResult resultModel)
        {
            if (CurrentCategorySchema == null)
            {
                resultModel.Errors.Add(CATEGORY_SCHEMA_NULL_ERROR_MESSAGE);
            }

            if (this._categoryToValidate.Parent != null)
            {
                if (this._categoryToValidate.Parent.StartDate > this._categoryToValidate.StartDate)
                {
                    resultModel.Errors.Add(START_DATE_PARENT_ERROR_MESSAGE);
                }

                if (this._categoryToValidate.Parent.EndDate <= this._categoryToValidate.StartDate)
                {
                    resultModel.Errors.Add(END_DATE_PARENT_ERROR_MESSAGE);
                }

                if (CurrentCategorySchema != null)
                {
                    CategorySchema parentCategorySchema = FacadeFactory.Instance.CategorySchemaFacade.GetActiveCategorySchema(this._categoryToValidate.Parent.StartDate);
                    if (parentCategorySchema.Id != CurrentCategorySchema.Id)
                    {
                        resultModel.Errors.Add(ANOTHER_SCHEMA_PARENT_ERROR_MESSAGE);
                    }
                }
            }

            return(resultModel);
        }
        public async Task <CategorySchemaServiceModel> UpdateCategorySchemaAsync(UpdateCategorySchemaServiceModel model)
        {
            var categorySchema = await this.context.CategorySchemas.FirstOrDefaultAsync(x => x.CategoryId == model.CategoryId && x.Language == model.Language && x.IsActive);

            if (categorySchema != null)
            {
                categorySchema.Schema           = model.Schema;
                categorySchema.UiSchema         = model.UiSchema;
                categorySchema.LastModifiedDate = DateTime.UtcNow;
            }
            else
            {
                var newCategorySchema = new CategorySchema
                {
                    CategoryId = model.CategoryId.Value,
                    Language   = model.Language,
                    Schema     = model.Schema,
                    UiSchema   = model.UiSchema
                };

                this.context.CategorySchemas.Add(newCategorySchema.FillCommonProperties());
            }

            await this.context.SaveChangesAsync();

            return(await this.GetCategorySchemaAsync(new GetCategorySchemaServiceModel
            {
                CategoryId = model.CategoryId,
                Language = model.Language,
                OrganisationId = model.OrganisationId,
                Username = model.Username
            }));
        }
        private IQueryOver <Category, Category> FilterByYear(IQueryOver <Category, Category> queryOver)
        {
            CategorySchema categorySchema = null;

            queryOver = queryOver.JoinAlias(x => x.CategorySchema, () => categorySchema)
                        .Where(x => x.StartDate.Year <= Year.Value && (x.EndDate == null || x.EndDate.Value.Year >= Year.Value) && categorySchema.StartDate <= _today);
            return(queryOver);
        }
        private ValidatorResult ValidateRecoverRuleset(ValidatorResult resultModel)
        {
            CategorySchema currentSchema = FacadeFactory.Instance.CategorySchemaFacade.GetCurrentCategorySchema();

            if (currentSchema.Id != CurrentCategorySchema.Id)
            {
                resultModel.Errors.Add(ANOTHER_SCHEMA_PARENT_ERROR_MESSAGE);
            }

            return(resultModel);
        }
        private IQueryOver <Category, Category> FilterByDate(IQueryOver <Category, Category> queryOver)
        {
            DateTimeOffset dateToCheck = _today;

            dateToCheck = StartDate.HasValue ? StartDate.Value : dateToCheck;
            dateToCheck = !StartDate.HasValue && EndDate.HasValue ? EndDate.Value : dateToCheck;
            CategorySchema categorySchema = null;

            queryOver = queryOver.JoinAlias(x => x.CategorySchema, () => categorySchema)
                        .Where(x => x.StartDate <= dateToCheck && (x.EndDate == null || x.EndDate > dateToCheck) && categorySchema.StartDate <= _today);
            return(queryOver);
        }