コード例 #1
0
        public async Task <ActionResult <User> > DeleteUser([FromHeader] string APIKey, [FromQuery] string userName)
        {
            try
            {
                if (await UserDatabaseAccess.APIKeyExists(APIKey, base._context))
                {
                    var user = await UserDatabaseAccess.GetUser(APIKey, base._context);

                    #region Registering UserLog
                    string Method    = this.HttpContext.Request.Method;
                    string Path      = this.HttpContext.Request.Path;
                    var    logString = user.Role + " requested " + Method + " " + Path;

                    await UserDatabaseAccess.AddLog(logString, user, base._context);

                    #endregion

                    if (user.ApiKey == APIKey && user.UserName == userName)
                    {
                        await UserDatabaseAccess.BackupLog(APIKey, base._context);

                        await UserDatabaseAccess.RemoveUser(user, base._context);

                        return(StatusCode(200, true));
                    }
                }
                throw new Exception();
            }
            catch (Exception)
            {
                return(StatusCode(200, false));
            }
        }