public async Task <ActionResult> Edit(Friend friend) { try { if (ModelState.IsValid) { using (var context = new S2GamesContext()) { context.Friends.AddOrUpdate(friend); await context.SaveChangesAsync(); context.Dispose(); return(RedirectToAction("Index")); } } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); TransportData(); } return(View()); }
public async Task <ActionResult> DeleteConfirmed(int id = 0) { try { using (var context = new S2GamesContext()) { var repository = new GameRepository(context); var game = await repository.GetByIdAsync(id, ConnectedId); if (game == null) { return(HttpNotFound()); } context.Games.Remove(game); await context.SaveChangesAsync(); context.Dispose(); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); TransportData(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(int id = 0) { try { using (var context = new S2GamesContext()) { var repository = new FriendRepository(context); await repository.DeleteAsync(id, ConnectedId); await context.SaveChangesAsync(); context.Dispose(); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); TransportData(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> ReturnGame(int gameId) { try { using (var context = new S2GamesContext()) { var repository = new GameRepository(context); await repository.LendOrReturn(null, gameId, ConnectedId); await context.SaveChangesAsync(); context.Dispose(); Response.StatusCode = (int)HttpStatusCode.OK; return(Json("Devolvido com sucesso", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } }