示例#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 override async Task BaseValidation(UpdateCollectionModel model)
        {
            var collections = await collectionsCrudService.GetAllAsync();

            if (!collections.Any(c => c.Id == model.CollectionId))
            {
                ValidationResult.AddError("Collection not found");
            }
            if (collections.Any(c => c.Name == model.Name && c.Id != model.CollectionId))
            {
                ValidationResult.AddError("Collection with such name already exists");
            }
            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");
            }
            var theme = await themesCrudService.GetAsync(model.ThemeId);

            if (theme is null)
            {
                ValidationResult.AddError("Theme not found");
            }
        }
        public async Task <AppRegistResult> ExternalRegistAsync()
        {
            var info = await identityUnitOfWork.SignInManager.GetExternalLoginInfoAsync();

            var appUser = await identityUnitOfWork.UserManager.FindByEmailAsync(info.Principal.FindFirstValue(ClaimTypes.Email));

            if (appUser is null)
            {
                appUser = mapper.Map <AppUser>(info);
                var createRes = await identityUnitOfWork.UserManager.CreateAsync(appUser);

                if (!createRes.Succeeded)
                {
                    return(new AppRegistResult(createRes));
                }
            }
            var addLoginRes = await identityUnitOfWork.UserManager.AddLoginAsync(appUser, info);

            if (!addLoginRes.Succeeded)
            {
                return(new AppRegistResult(addLoginRes));
            }
            var user = await userCrudService.GetAsync(appUser.Id);

            if (user is null)
            {
                user    = mapper.Map <UserModel>(info);
                user.Id = appUser.Id;
                await userCrudService.CreateAsync(user);
            }
            return(new AppRegistResult());
        }
        public async Task <AppUserModel> GetUserAsync(int id)
        {
            var user = await userCrudService.GetAsync(id);

            var idenUser = await identityUnitOfWork.UserManager.FindByIdAsync(id.ToString());

            var appUser = mapper.Map <AppUserModel>(user);

            appUser.Roles = await identityUnitOfWork.UserManager.GetRolesAsync(idenUser);

            return(appUser);
        }
示例#5
0
        protected async override Task BaseValidation(CommentItemModel model)
        {
            var user = await userCrudService.GetAsync(model.UserId);

            if (user is null)
            {
                ValidationResult.AddError("User not found");
            }
            if (model.Value.Length > 512 || string.IsNullOrWhiteSpace(model.Value))
            {
                ValidationResult.AddError("Value out of range");
            }
        }
示例#6
0
        protected async override Task BaseValidation(LikeItemModel model)
        {
            var user = await userCrudService.GetAsync(model.UserId);

            if (user is null)
            {
                ValidationResult.AddError("User not found");
            }
            var item = await itemsCrudService.GetAsync(model.ItemId);

            if (item is null)
            {
                ValidationResult.AddError("Item not found");
            }
        }
示例#7
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");
            }
        }
示例#8
0
        protected async override Task BaseValidation(DeleteItemModel model)
        {
            item = await itemsCrudService.GetAsync(model.ItemId);

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

            if (owner is null)
            {
                ValidationResult.AddError("Owner not found");
            }
        }
示例#9
0
        public async Task <IActionResult> Info(int?id)
        {
            if (id is null)
            {
                id = sessionHelper.GetCurrentUserId();
            }
            var user = await userCrudService.GetAsync(id.Value);

            if (user is null)
            {
                return(RedirectToAction(nameof(Home.Index), nameof(Home)));
            }
            sessionHelper.RememberUserId(id.Value);
            var model = mapper.Map <UserVM>(user);

            return(View(model));
        }
示例#10
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 ");
            }
        }
        protected async override Task BaseValidation(CreateCollectionModel model)
        {
            var owner = await userCrudService.GetAsync(model.OwnerId);

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

            if (resource is null)
            {
                ValidationResult.AddError("Resource not found");
            }
            var theme = await themesCrudService.GetAsync(model.ThemeId);

            if (theme is null)
            {
                ValidationResult.Errors.Add("Theme not found");
            }
        }
        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");
            }
        }