Пример #1
0
        public async Task <CreationCode> AddCreationCode(CreationCode code)
        {
            var result = await _context.CreationCodes.AddAsync(code);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
Пример #2
0
        public async void GenerateCreationCode()
        {
            Random random = new Random();

            CreationCode = random.Next(101, 989) * random.Next(11, 19);

            CreationCode code = new CreationCode()
            {
                Code   = CreationCode.ToString(),
                Active = 1
            };
            await CreationCodeService.CreateCreationCode(code);
        }
Пример #3
0
        public async Task <CreationCode> UpdateCreationCode(CreationCode code)
        {
            var result = await _context.CreationCodes.FirstOrDefaultAsync(s => s.Id == code.Id);

            if (result != null)
            {
                result.Active = code.Active;
                await _context.SaveChangesAsync();

                return(result);
            }

            return(null);
        }
        public async Task <ActionResult <CreationCode> > CreateCreationCode(CreationCode creationCode)
        {
            try
            {
                if (creationCode == null)
                {
                    return(BadRequest());
                }

                var createdCreationCode = await _creationCodeRepository.AddCreationCode(creationCode);

                return(createdCreationCode);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }
        public async Task <ActionResult <CreationCode> > UpdateCreationCode(int id, CreationCode creationCode)
        {
            try
            {
                if (id != creationCode.Id)
                {
                    return(BadRequest());
                }

                var creationCodeToUpdate = await _creationCodeRepository.GetCreationCode(id);

                if (creationCodeToUpdate == null)
                {
                    return(NotFound($"CreationCode with id = {id} not found"));
                }

                return(await _creationCodeRepository.UpdateCreationCode(creationCode));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }
Пример #6
0
 public async Task UpdateCreationCode(int id, CreationCode creationCode)
 {
     await httpClient.PutAsJsonAsync($"/api/creationCodes/{id}", creationCode);
 }
Пример #7
0
        public async Task <CreationCode> CreateCreationCode(CreationCode creationCode)
        {
            var result = await httpClient.PostAsJsonAsync("/api/creationCodes", creationCode);

            return(await result.Content.ReadAsAsync <CreationCode>());
        }