Beispiel #1
0
        public async Task <PutAccountResponse> PutAccount(long playerId, PutAccountRequest request)
        {
            var response = new PutAccountResponse();

            var registeredAccount = await Common1DB.PlayerIds
                                    .Where(r => r.playerId == playerId)
                                    .Join(Common1DB.Accounts,
                                          p => new { AccountType = p.accountType, p.account },
                                          a => new { AccountType = a.type, a.account },
                                          (p, a) => a)
                                    .FirstOrDefaultAsync();

            if (registeredAccount == null)
            {
                // todo: error message
                throw new NotFoundException("account not exist");
            }

            registeredAccount.banExpiration = request.account.banExpiration;

            await Common1DB.SaveChangesAsync();

            return(response);
        }
Beispiel #2
0
 public async Task <EvoToolApiResponse> PutAccount(long playerId, PutAccountRequest request)
 {
     return(await _accountRepository.PutAccount(playerId, request));
 }
Beispiel #3
0
        public async Task <EvoToolApiResponse> PutAccount(long playerId, PutAccountRequest request)
        {
            var response = await PutAsync($"/api/gmtool/account/{playerId}", request);

            return(await BuildResponse(response));
        }
        public async Task <ActionResult <PutAccountResponse> > PutAccount(long playerId, PutAccountRequest request)
        {
            // todo: validation
            var response = await _accountService.PutAccount(playerId, request);

            return(Ok(response));
        }
        public async Task <PutAccountResponse> PutAccount(Guid id, PutAccountRequest model, Guid currentAccountId)
        {
            Account account = await _unitOfWork.Repository <Account>().GetAll().Where(x => x.Id == id && x.Active == true).Include(x => x.Brand).FirstOrDefaultAsync();

            if (account != null)
            {
                if (model.Fullname != "")
                {
                    account.Fullname = model.Fullname;
                }

                if (model.PhoneNumber != "")
                {
                    account.PhoneNumber = model.PhoneNumber;
                }

                if (model.Email != "")
                {
                    account.Email = model.Email;
                }

                if (model.Role > -1)
                {
                    account.Role = model.Role;
                }

                if (model.Role != 1)
                {
                    account.BrandId = null;
                }
                else
                {
                    if (model.BrandId > 0)
                    {
                        account.BrandId = model.BrandId;
                    }
                }
                if (model.ImageUrl != "")
                {
                    account.ImageUrl = model.ImageUrl;
                }

                try
                {
                    await _unitOfWork.Repository <Account>().UpdateGuid(account, id);

                    await _unitOfWork.CommitAsync();
                }
                catch (Exception e)
                {
                    throw new CrudException(HttpStatusCode.BadRequest, "Update Account Error!!!", e.InnerException?.Message);
                }
                return(new PutAccountResponse
                {
                    ImageUrl = account.ImageUrl,
                    Active = account.Active,
                    BrandId = account.BrandId,
                    BrandName = account.Brand?.Name,
                    CreateDate = account.CreateDate,
                    Email = account.Email,
                    FcmToken = account.FcmToken,

                    Fullname = account.Fullname,
                    Id = account.Id,
                    PhoneNumber = account.PhoneNumber,
                    Role = account.Role,
                    Jwt = id == currentAccountId?GenerateJwtToken(account) : null
                });
            }
            else
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Update Account Error!!!", "");
            }
        }
        public async Task <ActionResult <PutAccountResponse> > UpdateAccount(Guid id, [FromBody] PutAccountRequest model)
        {
            try
            {
                Guid CurentAccountId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
                var  rs = await _accountService.PutAccount(id, model, CurentAccountId);

                return(Ok(rs));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Beispiel #7
0
        public async Task <ActionResult <PutAccountResponse> > Put(long playerId, PutAccountRequest request)
        {
            var result = await _accountService.PutAccount(playerId, request);

            return(BuildResponse(result));
        }