Esempio n. 1
0
        protected async override Task BaseValidation(UpdateItemModel model)
        {
            var item = await itemsCrudService.GetAsync(model.ItemId);

            if (item is null)
            {
                ValidationResult.AddError("Item not found");
            }
            var collection = await collectionsCrudService.GetAsync(model.CollectionId);

            if (collection is null)
            {
                ValidationResult.AddError("Collection not found");
            }
            var owner = await userCrudService.GetAsync(model.OwnerId);

            if (owner is null)
            {
                ValidationResult.AddError("User not found");
            }
            var resource = await resourceCrudService.GetAsync(model.ResourceId);

            if (resource is null)
            {
                ValidationResult.AddError("Resource not found");
            }
        }
        protected async override Task <bool> TrySetOwner(DeleteCollectionModel model)
        {
            var collection = await collectionsCrudService.GetAsync(model.CollectionId);

            if (collection is null)
            {
                return(false);
            }
            model.OwnerId = collection.OwnerId;
            return(true);
        }
Esempio n. 3
0
        protected async override Task BaseValidation(CreateOptionalFieldModel model)
        {
            var owner = await userCrudService.GetAsync(model.OwnerId);

            if (owner is null)
            {
                ValidationResult.AddError("User not found");
            }
            var collection = await collectionsCrudService.GetAsync(model.CollectionId);

            if (collection is null)
            {
                ValidationResult.AddError("Collection not found");
            }
            var type = (await fieldTypesCrudService.GetAllAsync()).FirstOrDefault();

            if (type is null)
            {
                ValidationResult.AddError("Available field types not found ");
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> GetCollectionFields(int id)
        {
            var collection = await collectionsCrudService.GetAsync(id);

            if (collection is null)
            {
                return(Json(null));
            }
            var fieldsVM = mapper.Map <IEnumerable <OptionalFieldVM> >(collection.OptionalFields);

            return(Json(fieldsVM));
        }
        protected async override Task BaseValidation(DeleteOptionalFieldModel model)
        {
            var owner = await userCrudService.GetAsync(model.OwnerId);

            if (owner is null)
            {
                ValidationResult.AddError("User not found");
            }
            var collection = await collectionsCrudService.GetAsync(model.CollectionId);

            if (collection is null)
            {
                ValidationResult.AddError("Collection not found");
            }
            var field = await optionalFieldsCrudService.GetAsync(model.OptionalFieldId);

            if (field is null)
            {
                ValidationResult.AddError("Optional field not found");
            }
        }
        protected async override Task OptionalValidation(UpdateCollectionModel model)
        {
            var collection = await collectionsCrudService.GetAsync(model.CollectionId);

            if (model.OwnerId != collection.OwnerId)
            {
                ValidationResult.AddError("Owner matching error");
            }
            if (!collection.OptionalFields.Select(of => of.Id).OrderBy(i => i).SequenceEqual(model.OptionalFields.Select(of => of.Id).OrderBy(i => i)))
            {
                ValidationResult.AddError("Optional fields matching error");
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Collection(int id)
        {
            var collection = await collectionsCrudService.GetAsync(id);

            if (collection is null)
            {
                return(RedirectToAction(nameof(Home.Index), nameof(Home)));
            }
            sessionHelper.RememberUserId(collection.OwnerId);
            var collectionVM = mapper.Map <CollectionVM>(collection);

            return(View(collectionVM));
        }
Esempio n. 8
0
        protected async override Task BaseValidation(DeleteCollectionModel model)
        {
            owner = await userCrudService.GetAsync(model.OwnerId);

            if (owner is null)
            {
                ValidationResult.AddError("Owner not found");
            }
            collection = await collectionsCrudService.GetAsync(model.CollectionId);

            if (collection is null)
            {
                ValidationResult.AddError("Collection not found");
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> EditCollection(int id)
        {
            var collection = await collectionsCrudService.GetAsync(id);

            if (collection is null)
            {
                return(RedirectToAction(nameof(Profile), nameof(Store)));
            }
            if (!User.IsInRole("admin") && collection.OwnerId != sessionHelper.GetCurrentUserId())
            {
                return(RedirectToAction(nameof(Home.Index), nameof(Home)));
            }
            var editVM = mapper.Map <EditCollectionVM>(collection);

            return(View(editVM));
        }
        public async Task <DeleteCollectionResult> DeleteAsync(DeleteCollectionModel deleteCollectionModel)
        {
            var authResult = await authenticatorsStore.DeleteCollectionModelAuthenticator.AuthenticateAsync(deleteCollectionModel);

            if (!authResult.Succeed)
            {
                return(new DeleteCollectionResult(authResult));
            }
            var validResult = await validatorsStore.DeleteCollectionModelValidator.ValidateAsync(deleteCollectionModel);

            if (!validResult.Succeed)
            {
                return(new DeleteCollectionResult(validResult));
            }
            var result   = new DeleteCollectionResult();
            var resource = (await collectionsCrudService.GetAsync(deleteCollectionModel.CollectionId)).Resource;
            await collectionsCrudService.DeleteAsync(deleteCollectionModel.CollectionId);

            await resourcesManager.DeleteAsync(resource);

            return(result);
        }