Example #1
0
        /// <summary>
        /// Creates an Entity specified by its table with the form dictionary values, as an asynchronous operation.
        /// </summary>
        /// <param name="tableName">The name of the table the entity resides in.</param>
        /// <param name="formDict">The form dictionary containing the values to create the entity.</param>
        /// <returns>
        /// The System.Threading.Tasks.Task that represents the asynchronous operation, containing the KerykeionDbResult of the operation.
        /// </returns>
        public async Task <KerykeionDbResult> CreateAsync(string tableName, Dictionary <string, StringValues> formDict)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                return(KerykeionDbResult.Fail(new KerykeionDbError {
                    Message = $"{await _translationsService.TranslateAsync("Please specify a valid table name")}."
                }));
            }

            var type = FindEntityTypeByTableName(tableName);

            if (type == null)
            {
                return(KerykeionDbResult.Fail(new KerykeionDbError {
                    Message = _translationsService.TranslateErrorByDescriber(ErrorDescriberConstants.TableNotExists, $"There are no entities in a table called '{tableName}'.", tableName)
                }));
            }

            if (formDict.ContainsKey(PropertyNameConstants.Name))
            {
                var exists = await ExistsAsync(formDict[PropertyNameConstants.Name], tableName);

                if (exists)
                {
                    return(KerykeionDbResult.Fail(new KerykeionDbError {
                        Message = _translationsService.TranslateErrorByDescriber(ErrorDescriberConstants.NameDuplicate, $"The name '{formDict[PropertyNameConstants.Name]}' is already taken.", formDict[PropertyNameConstants.Name])
                    }));
                }
            }

            var entity = Activator.CreateInstance(type.ClrType);

            var result = await SetPropertiesAsync(entity, formDict);

            if (!result.Successfull)
            {
                return(result);
            }

            return(await CreateAsync(entity));
        }
        public async Task <IActionResult> OnGetAsync(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(RedirectToPage("/Index"));
            }

            var user = await _userService.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }

            code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
            var result = await _userService.ConfirmEmailAsync(user, code);

            StatusMessage = result.Succeeded ? $"{await _translationsService.TranslateAsync("Bedankt om uw e-mail te bevestigen.")}" : $"{await _translationsService.TranslateAsync("Het bevestigen van uw e-mail is mislukt.")}";
            return(Page());
        }