Example #1
0
        public async Task <ActionResult <Person> > PostPerson(Person person)
        {
            _context.Add <Person>(person);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetPerson), new { person.Id }, person));
        }
        public async Task <ActionResult <string> > PutPerson(int id, PersonDTO Person)
        {
            try
            {
                if (id != Person.Id)
                {
                    return(BadRequest("Wrong id"));
                }
                var oldPerson = await _context.People.FindAsync(id);

                if (oldPerson == null)
                {
                    return(BadRequest($"Could not find data for {Person.Name}"));
                }

                _mapper.Map <PersonDTO, Person>(Person, oldPerson);
                await _context.SaveChangesAsync();

                return($"Successfully updated information about person {Person.FirstName} {Person.LastName}");
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to update data"));
            }
        }
Example #3
0
        public async Task <IActionResult> CreateProjectPost(int key, string secret)
        {
            var credentials = new OpenTokFs.Credentials.AccountCredentials(key, secret);
            var project     = await OpenTokFs.Api.Project.CreateAsync(credentials, ProjectName.NoProjectName);

            _context.VonageVideoAPIProjectCredentials.Add(new VonageVideoAPIProjectCredential {
                ApiKey    = project.Id,
                ApiSecret = project.Secret
            });
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Example #4
0
        public async Task <ActionResult <ExampleEntity> > Add(ExampleEntity entitiy)
        {
            _context.Add(entitiy);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetExampleEntityById), new { id = entitiy.ExampleId }, entitiy));
        }
Example #5
0
        public async Task ExecuteAsync(UpdateClassificationCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            var entity = await _db.Classifications.SingleAsync(e => e.Id == command.Id, cancellationToken);

            entity.Code    = command.Code;
            entity.DescEng = command.DescEng;
            entity.DescFre = command.DescFre;
            await _db.SaveChangesAsync(cancellationToken);
        }
Example #6
0
        public async Task <IActionResult> CreateBlog()
        {
            _dbContext.Blogs.Add(new Blog
            {
                Url = "asdf"
            });
            await _dbContext.SaveChangesAsync();

            return(Json(new { message = "success." }));
        }
Example #7
0
        public async Task ExecuteAsync(RemoveClassificationCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            var entity = new Classification()
            {
                Id = command.Id
            };

            _db.Classifications.Attach(entity);
            _db.Classifications.Remove(entity);
            await _db.SaveChangesAsync(cancellationToken);
        }
Example #8
0
        public async Task ExecuteAsync(AddClassificationCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            await _db.Classifications.AddAsync(new Classification()
            {
                Code    = command.Code,
                DescEng = command.DescEng,
                DescFre = command.DescFre
            }, cancellationToken);

            await _db.SaveChangesAsync(cancellationToken);
        }
Example #9
0
        public async Task UpdateTokenAsync(IDeviantArtRefreshToken value)
        {
            CurrentToken = value;

            var t = await _context.Tokens.FindAsync(_originalToken.Id);

            if (t != null)
            {
                t.AccessToken  = value.AccessToken;
                t.RefreshToken = value.RefreshToken;
                await _context.SaveChangesAsync();
            }
        }
Example #10
0
        public async Task <User> RegisterAsync(User user, string password)
        {
            _hashHelper.CreatePasswordHash(password, out byte[] hash, out byte[] salt);

            user.PasswordHash = hash;
            user.PasswordSalt = salt;

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Example #11
0
        public async Task TestCheckSaveChangesAsyncReturningCount()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();

                //ATTEMPT
                context.Add(new TaxRate(DateTime.UtcNow, 4));
                var numUpdates = await context.SaveChangesAsync();

                //VERIFY
                numUpdates.ShouldEqual(1);
            }
        }
 public async Task OnPostAsync([FromBody] Application value)
 {
     _db.Applications.Add(value);
     await _db.SaveChangesAsync();
 }
Example #13
0
 public async Task SaveAsync()
 {
     await _dbContext.SaveChangesAsync();
 }