Exemple #1
0
        public async Task <IActionResult> PutFile(int id, File file)
        {
            AspNetUser user = await _context.AspNetUsers.SingleAsync(e => e.UserName == User.Identity.Name);

            if (user.Id != file.OwnerUserId)
            {
                return(BadRequest("You dont have access to the file"));
            }
            if (id != file.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutBookList(int id, BookList bookList)
        {
            if (id != bookList.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #3
0
        public async Task <IActionResult> PutFile(int id, File file)
        {
            AspNetUser user = await _context.AspNetUsers.SingleAsync(e => e.UserName == User.Identity.Name);

            File dfile = await _context.Files.SingleAsync(e => e.Id == id && e.OwnerUserId == user.Id && e.IsDeleted == true);

            //dfile.OwnerUser = null;
            if (dfile == null)
            {
                return(BadRequest());
            }
            dfile.IsDeleted             = false;
            dfile.DeleteDate            = null;
            _context.Entry(dfile).State = EntityState.Modified;

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

            return(NoContent());
        }