public async Task <HttpResponseMessage> PostAllGame(AllGame allGame) { try { if (ModelState.IsValid) { if (await _allGame.CheckExistGameAsync(allGame.GameName)) { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.Conflict }; return(response); } else { var userId = this.User.FindFirstValue(ClaimTypes.Name); allGame.CreatedBy = Convert.ToInt32(userId); allGame.CreatedDateTime = DateTime.Now; //var temprole = _mapper.Map<Role>(roleViewModel); if (await _allGame.InsertGameAsync(allGame)) { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; return(response); } else { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }; return(response); } } } else { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }; return(response); } } catch (Exception ex) { throw; } }
public async Task <bool> InsertGameAsync(AllGame allGame) { await context.AllGames.AddAsync(allGame); if (await context.SaveChangesAsync() > 0) { return(true); } else { return(false); } }
public async Task <bool> UpdateGameAsync(AllGame allGame) { context.Entry(allGame).Property(ee => ee.GameName).IsModified = true; context.Entry(allGame).Property(ee => ee.SchemeID).IsModified = true; context.Entry(allGame).Property(ee => ee.StartTime).IsModified = true; context.Entry(allGame).Property(ee => ee.EndTime).IsModified = true; context.Entry(allGame).Property(ee => ee.IsActive).IsModified = true; if (await context.SaveChangesAsync() > 0) { return(true); } else { return(false); } }
public async Task <HttpResponseMessage> PutAllGame(long id, AllGame allGame) { if (id != allGame.GameId) { return(new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }); } allGame.CreatedBy = 0; allGame.CreatedDateTime = DateTime.Now; try { if (await _allGame.UpdateGameAsync(allGame)) { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; return(response); } else { var response = new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest }; return(response); } } catch (Exception) { throw; } }