Esempio n. 1
0
        //===================================== HELPER METHODS =====================================//

        private async Task <ServiceResponse <UpgradeKey> > UpdateSecureKey(UpdateUpgradeKeyDto keyDto)
        {
            var        response = new ServiceResponse <UpgradeKey>();
            UpgradeKey dalKey   = await _context.UpgradeKeys.FirstOrDefaultAsync(k => k.EMail == keyDto.EMail);

            if (dalKey != null)
            {
                dalKey.Key = keyDto.Key;
            }
            else
            {
                dalKey = await _context.UpgradeKeys.FirstOrDefaultAsync(k => k.Key == keyDto.Key);

                if (dalKey == null)
                {
                    return(response.Failure(NoKeyStr, HttpStatusCode.NotFound));
                }
                dalKey.EMail = keyDto.EMail;
            }

            dalKey.UserType = keyDto.UserType;

            await _context.SaveChangesAsync();

            return(response.Success(dalKey, KeyUpdatedStr));
        }
        public async Task <IActionResult> UpdateUpgradeKey(UpdateUpgradeKeyDto upgradeKey)
        {
            var keysResponse = await _keyService.UpdateUpgradeKey(upgradeKey);

            var response = new Response <UpgradeKey>(keysResponse);

            if (keysResponse.Code == HttpStatusCode.UnprocessableEntity)
            {
                return(UnprocessableEntity(response));
            }
            return(Ok(response));
        }
Esempio n. 3
0
        public async Task <ServiceResponse <UpgradeKey> > UpdateUpgradeKey(UpdateUpgradeKeyDto upgradeKey)
        {
            var response = new ServiceResponse <UpgradeKey>();
            const HttpStatusCode code = HttpStatusCode.UnprocessableEntity;

            if (!Enum.IsDefined(typeof(UserType), upgradeKey.UserType))
            {
                return(response.Failure(KeyTypeFailStr, code));
            }
            if (upgradeKey.Key == null || upgradeKey.Key.Length < 4)
            {
                return(response.Failure(KeyLengthStr, code));
            }
            if (upgradeKey.EMail == null)
            {
                return(response.Failure(KeyMailInvalidStr, code));
            }

            return(await UpdateSecureKey(upgradeKey));
        }