public async Task <IActionResult> PutUsertracker([FromRoute] int id, [FromBody] Usertracker usertracker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public IEnumerable <Youtubekeys> GetYoutubekeysByUserName([FromRoute] string userName)
        {
            List <Youtubekeys> KeysRowList = new List <Youtubekeys>();

            if (string.IsNullOrEmpty(userName))
            {
                return(null);
            }
            try
            {
                Usertracker user = _context.Usertracker.SingleOrDefault(m => m.Username == userName);
                KeysRowList = _context.Youtubekeys.AsNoTracking().Where(m => m.Id > user.KeysFrom).Take(user.KeysToFetch).ToList();

                if (KeysRowList.Count() > 0)
                {
                    user.ActualKeysProcessed += KeysRowList.Count();
                    user.KeysFrom             = KeysRowList[KeysRowList.Count() - 1].Id;
                    _context.Usertracker.Update(user);
                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
            return(KeysRowList);
        }
        public async Task <IActionResult> PostUsertracker([FromBody] Usertracker usertracker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Usertracker.Add(usertracker);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUsertracker", new { id = usertracker.Id }, usertracker));
        }