public HttpResponseMessage Put(int id, [FromBody] TblJudgesPaperKKT value) { value.Date = DateTime.Now; CompetitionDB.Entry(value).State = EntityState.Modified; return(ToJsonOK(CompetitionDB.SaveChanges())); }
public HttpResponseMessage Post(int compId, string userName, [FromBody] TblCompetitorsKKT value) { value.Paid = false; value.CompetitionId = compId; string accountId = CompetitionDB.Users.FirstOrDefault(x => x.UserName == userName).Id; int Id = CompetitionDB.TblUsers.FirstOrDefault(x => x.UserId == accountId).Id; value.TeamId = CompetitionDB.TblUsers.FirstOrDefault(x => x.UserId == accountId).TeamId; value.Paid = false; CompetitionDB.TblCompetitorsKKT.Add(value); CompetitionDB.SaveChanges(); List <RouteKKTModel> routes = CompetitionDB.TblRoutesKKT.ToArray().Where(x => x.CompetitionId == compId && x.Type == value.Group).Select(x => new RouteKKTModel(x)).ToList(); TblJudgesPaperKKT paper = new TblJudgesPaperKKT(); foreach (RouteKKTModel r in routes) { paper.JudgeId = 0; paper.RouteId = r.Id; paper.Time = "00:00:00"; paper.Comment = ""; paper.Date = DateTime.Now; paper.TypeId = 0; paper.UserId = value.TeamId; CompetitionDB.TblJudgesPapersKKT.Add(paper); CompetitionDB.SaveChanges(); } return(ToJsonCreated(CompetitionDB.SaveChanges())); }
public JudgesPaperKKTModel(TblJudgesPaperKKT row) { Id = row.Id; RouteId = row.RouteId; TeamId = row.TeamId; Time = row.Time; TypeId = row.TypeId; }
public HttpResponseMessage Post(int compId, int id) { TblCompetitorsKKT value = new TblCompetitorsKKT(); value.Paid = false; value.CompetitionId = compId; value.TeamId = id; int dateYear = 0; int dateNow = 0; if (CompetitionDB.TblUsers.First(x => x.TeamId == id).BirthYear.ToString().Length == 22) { dateYear = Convert.ToInt32(CompetitionDB.TblUsers.Find(id).BirthYear.ToString().Substring(6, 4)); } else if (CompetitionDB.TblUsers.Find(id).BirthYear.ToString().Length == 20) { dateYear = Convert.ToInt32(CompetitionDB.TblUsers.Find(id).BirthYear.ToString().Substring(4, 4)); } else { dateYear = Convert.ToInt32(CompetitionDB.TblUsers.Find(id).BirthYear.ToString().Substring(5, 4)); } if (DateTime.Now.ToString().Length == 22) { dateNow = Convert.ToInt32(DateTime.Now.ToString().Substring(6, 4)); } else if (DateTime.Now.ToString().Length == 20) { dateNow = Convert.ToInt32(DateTime.Now.ToString().Substring(5, 4)); } else { dateNow = Convert.ToInt32(DateTime.Now.ToString().Substring(4, 4)); } if ((dateNow - dateYear) > 16) { value.Group = "JAUNIAI"; } else { value.Group = "JAUNUČIAI"; } CompetitionDB.TblCompetitorsKKT.Add(value); List <RouteKKTModel> routes = CompetitionDB.TblRoutesKKT.ToArray().Where(x => x.CompetitionId == compId && x.Type == value.Group).Select(x => new RouteKKTModel(x)).ToList(); TblJudgesPaperKKT paper = new TblJudgesPaperKKT(); foreach (RouteKKTModel r in routes) { paper.JudgeId = 0; paper.RouteId = r.Id; paper.Time = "00:00:00"; paper.Comment = ""; paper.Date = DateTime.Now; paper.TypeId = 0; paper.UserId = value.TeamId; CompetitionDB.TblJudgesPapersKKT.Add(paper); CompetitionDB.SaveChanges(); } return(ToJsonCreated(CompetitionDB.SaveChanges())); }