public async Task <IActionResult> PutVideo(Guid id, Video video) { if (id != video.uuid) { return(BadRequest()); } _context.Entry(video).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VideoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutGame(int id, VideoGame game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != game.p_GameId) { return(BadRequest()); } db.Entry(game).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutVideo([FromRoute] int id, [FromBody] Video video) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != video.ID) { return(BadRequest()); } _context.Entry(video).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VideoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create(Video video, List <int> Tags) { if (ModelState.IsValid) { using (var transaction = await _context.Database.BeginTransactionAsync()) { try { await _context.Videos.AddAsync(VideoHelper.getVideoWithIdParsed(video)); await _context.SaveChangesAsync(); foreach (var tag in Tags) { await _context.VideoTag.AddAsync(new VideoTag { VideoId = video.Id, TagId = tag }); await _context.SaveChangesAsync(); } transaction.Commit(); } catch (Exception ex) { throw ex; } } return(RedirectToAction("Index")); } ViewBag.Tags = await _context.Tags.Where(t => t.EsVisible).ToListAsync(); return(View(video)); }
//writes the log Entry for a admin action //use with await private async Task LogAction(string action, int editedId, string editedName) { string editor = User.Identity.Name; ModeratorHistory newActivity = new ModeratorHistory(); newActivity.ModeratorId = database.Moderator.FirstOrDefault(x => x.Login == editor).Id; newActivity.Activity = String.Format("Admin {0} " + action + " with Id '{1}' and name '{2}' on {3} .", editor, editedId, editedName, DateTime.Now); newActivity.Date = DateTime.Now; database.ModeratorHistory.Add(newActivity); await database.SaveChangesAsync(); }
public async Task <bool> AddAsync <TEntity>(TEntity item) where TEntity : class { await _db.AddAsync <TEntity>(item); return(await _db.SaveChangesAsync() >= 0); }