コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,AppKey,AppValue,IsActive")] ClientSecrets clientSecrets)
        {
            if (ModelState.IsValid)
            {
                clientSecrets.AppKey      = _jwtManager.EncryptText(clientSecrets.Name + clientSecrets.AppKey, clientSecrets.AppKey);
                clientSecrets.AppValue    = _jwtManager.GenerateAppToken(clientSecrets.Name, clientSecrets.AppKey);
                clientSecrets.CreatedDate = DateTime.UtcNow;
                clientSecrets.UpdateDate  = DateTime.UtcNow;
                _context.Add(clientSecrets);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientSecrets));
        }
コード例 #2
0
        public async Task <IActionResult> PutPromoCodes([FromRoute] int id, [FromBody] PromoCodes promoCodes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != promoCodes.Id)
            {
                return(BadRequest());
            }

            _context.Entry(promoCodes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PromoCodesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            var response = new GenericResponse()
            {
                Data           = promoCodes,
                Success        = true,
                HttpStatusCode = HttpStatusCode.OK,
                Message        = MessagesConstants.PromoCodeUpdate
            };

            return(Ok(response));
        }