public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.UserID)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutPlaylist(int id, Playlist playlist)
        {
            if (id != playlist.PlaylistID)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaylistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> AddTutorial([FromBody] Tutorial tutorial)
        {
            _context.Tutorials.Add(tutorial);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("AddTutorial", new { id = tutorial.TutorialID }, tutorial));
        }
        public async Task <IActionResult> AddSubject([FromBody] Subject subject)
        {
            _context.Subjects.Add(subject);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("AddSubject", new { id = subject.SubjectID }, subject));
        }
Esempio n. 5
0
        public async Task <IActionResult> AddAssignment([FromBody] Assignment assignment)
        {
            _context.Assignments.Add(assignment);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("AddAssignment", new { id = assignment.AssignmentlID }, assignment));
        }
        public async Task <IActionResult> AddChapter([FromBody] Chapter chapter)
        {
            _context.Chapters.Add(chapter);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("AddChapter", new { id = chapter.ChapterID }, chapter));
        }
Esempio n. 7
0
        public async Task <IActionResult> AddStudent([FromBody] Student student)
        {
            _context.Students.Add(student);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("AddStudent", new { id = student.StudentID }, student));
        }
Esempio n. 8
0
        public async Task <IActionResult> AddTeacher([FromBody] Teacher teacher)
        {
            _context.Teachers.Add(teacher);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("AddTeacher", new { id = teacher.TeacherID }, teacher));
        }
 public async Task <bool> AddNodeAsync(string url)
 {
     if (_applicationDatabase.Nodes.Where(n => n.Url == url).ToList().Count() > 0)
     {
         return(false);
     }
     _applicationDatabase.Nodes.Add(new Database.Node()
     {
         Url = url.EndsWith("/") ? url : url + "/"
     });
     return(await _applicationDatabase.SaveChangesAsync() > 0);
 }
Esempio n. 10
0
        public async Task <IActionResult> UpdateCell([FromBody] UpdateCellModel data)
        {
            var tableRow = _context.Canvas
                           .Include(c => c.ColorData)
                           .OrderByDescending(c => c.CanvasID)
                           .FirstOrDefault()
                           .ColorData
                           .First(row => row.RowIndex == data.Row && row.ColumnIndex == data.Column);

            tableRow.Hex = data.Hex;

            await _context.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 11
0
        public async Task <ActionResult <Account> > DeleteAccount(int id)
        {
            var account = await _context.Account.FindAsync(id);

            if (account == null)
            {
                return(NotFound());
            }

            _context.Account.Remove(account);

            await _context.SaveChangesAsync();

            return(account);
        }
Esempio n. 12
0
        public async Task <ActionResult <Customer> > DeleteCustomer(int id)
        {
            var customer = await _context.Customer.FindAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }

            _context.Customer.Remove(customer);

            await _context.SaveChangesAsync();

            return(customer);
        }
        public bool Handle(MarkMainChainQuery query)
        {
            if (query.IsLongRunning)
            {
                _applicationDatabase.Database.SetCommandTimeout(new TimeSpan(0, 10, 0));
            }
            using (var transaction = _applicationDatabase.Database.BeginTransaction()) {
                try
                {
                    _applicationDatabase.BlockChain
                    .Where(b => b.IsInMainChain && b.BlockHash != BlockchainConsensus.GenesisBlock.BlockHash)
                    .ToList()
                    .ForEach(b => b.IsInMainChain = false);
                    _applicationDatabase.SaveChangesAsync();

                    var headBlock = _queryHandlerGetHeadBlock.Handle(new GetHeadBlockQuery()
                    {
                    });
                    if (headBlock.IsInMainChain == false)
                    {
                        _applicationDatabase.BlockChain.Update(headBlock);
                        headBlock.IsInMainChain = true;
                        _applicationDatabase.SaveChanges();
                    }
                    string blockHashPrevious = headBlock.BlockHashPrevious;
                    while (!string.IsNullOrEmpty(blockHashPrevious) && blockHashPrevious != BlockchainConsensus.GenesisBlock.BlockHash)
                    {
                        var block = _applicationDatabase.BlockChain.Single(b => b.BlockHash == blockHashPrevious);
                        blockHashPrevious   = block.BlockHashPrevious;
                        block.IsInMainChain = true;
                        _applicationDatabase.SaveChanges();
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(false);
                }
            }
        }
Esempio n. 14
0
        public async Task <bool> TryAddAsync(EncryptedMessage message)
        {
            var id = message.Id;

            if (!_messageValidator.Validate(message))
            {
                return(false);
            }
            if (GetMessageById(message.Id) != null)
            {
                return(false);
            }

            try
            {
                var messageDb = new EncryptedMessageStore(message);
                _applicationDatabase.Messages.Add(messageDb);
                return(await _applicationDatabase.SaveChangesAsync() > 0);
            }
            catch (DbException)
            {
                return(false);
            }
        }
Esempio n. 15
0
 public async Task SaveSalesData(SaleDataModel[] sales)
 {
     _database.Sales.AddRange(sales);
     await _database.SaveChangesAsync();
 }