public IHttpActionResult ScholarAccountInformation(AccountStatusDTO accountStatusDTO)
        {
            // Check model binding
            Validate(accountStatusDTO);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Update info in database.
            try
            {
                Account account;
                // Verifying the requested account exists
                if (_accountLogic.Exists(accountStatusDTO.username))
                {
                    account = _accountLogic.GetByUsername(accountStatusDTO.username);
                }
                // The requested account does not exist.
                else
                {
                    return(BadRequest("The requested account with the given username does not exist!"));
                }
                account.AccountStatus = accountStatusDTO.accountStatus;
                _accountLogic.Update(account);
            } catch (Exception ex)
            {
                return(BadRequest(ex.Source + "\n" + ex.Message + "\n" + ex.InnerException + "\n" + ex.StackTrace));
            }

            // Return successful response if update correctly.
            return(Ok("Put Account Information"));
        }
        public async Task <dynamic> postAccountStatusUpdates([FromBody] AccountStatusDTO StatusData)
        {
            AccountStatus existingData = db.AccountStatus.Where(acs => acs.AccountId == StatusData.AccountId).FirstOrDefault();

            if (existingData != null)
            {
                existingData.LoggedIn  = StatusData.LoggedIn;
                existingData.GameId    = StatusData.GameId;
                existingData.ChannelId = StatusData.ChannelId;
                existingData.WorldId   = StatusData.WorldId;
                existingData.GameName  = StatusData.GameName;
                db.AccountStatus.Attach(existingData);
                db.Entry(existingData).State = EntityState.Modified;
            }
            db.SaveChanges();

            return(await getAccountStatus(StatusData.AccountId));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Posts the current account status.
        /// </summary>
        /// <param name="status">Account status.</param>
        /// <returns>Success or failure.</returns>
        public async Task <bool> PostAccountStatus(AccountStatusDTO status)
        {
            bool result = false;

            try
            {
                if (_settings.SimulatedMode)
                {
                    result = false;
                }
                else
                {
                    result = (await PostDbAsync($"Account/postAccountStatusUpdates", JsonConvert.SerializeObject(status))).IsSuccessStatusCode;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get account status by account id.
        /// </summary>
        /// <param name="accountId">Unique id of account.</param>
        /// <returns>Account status.</returns>
        public async Task <AccountStatusDTO> GetAccountStatus(int accountId)
        {
            AccountStatusDTO result = null;

            try
            {
                if (_settings.SimulatedMode)
                {
                    result = null;
                }
                else
                {
                    result = await GetDbAsync <AccountStatusDTO>($"Account/getAccountStatus?AccountId={accountId}");
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            return(result);
        }