public CompetitionClimbModel(TblCompetition row) : base(row) { /* Id = row.Id; * Name = row.Name; * Date = row.Date; * OrgId = row.OrgId; * MainJudgeId = row.MainJudgeId; * MainRouteCreatorId = row.MainRouteCreatorId; * Type = row.Type;*/ }
public CompetitionModel(TblCompetition row) { Id = row.Id; Name = row.Name; Date = row.Date; OrgId = row.OrgId; MainJudgeId = row.MainJudgeId; MainRouteCreatorId = row.MainRouteCreatorId; Type = row.Type; Open = row.Open; Update = row.Update; ClimbType = row.ClimbType; if (Date.ToString().Length == 22) { Date2 = Date.ToString().Substring(0, 10); } else if (Date.ToString().Length == 20) { Date2 = Date.ToString().Substring(0, 8); } else { Date2 = Date.ToString().Substring(0, 9); } String[] datearray = Date2.Split('/'); Date2 = datearray[2] + "-"; if (datearray[0].Length == 1) { Date2 += "0" + datearray[0] + "-"; } else { Date2 += datearray[0] + "-"; } if (datearray[1].Length == 1) { Date2 += "0" + datearray[1]; } else { Date2 += datearray[1]; } }
public HttpResponseMessage Put(int id, [FromBody] TblCompetition value) { CompetitionDB.Entry(value).State = EntityState.Modified; return(ToJsonOK(CompetitionDB.SaveChanges())); }
public HttpResponseMessage Post(string userName, [FromBody] TblCompetition value) { string accountId = CompetitionDB.Users.FirstOrDefault(x => x.UserName == userName).Id; int id = CompetitionDB.TblUsers.FirstOrDefault(x => x.UserId == accountId).Id; value.OrgId = id; value.Open = true; value.Update = true; CompetitionDB.TblCompetitions.Add(value); /** Sukuriamos trasos LAIPIOJIMO VARŽYBOMS*/ if (value.Type) { CompetitionDB.SaveChanges(); int compId = CompetitionDB.TblCompetitions.First(x => x.Name == value.Name && x.Date == value.Date).Id; TblRouteClimb route = new TblRouteClimb(); if (value.ClimbType == 1) { int i; int p = 2; for (i = 0; i < 6; i++) { route.Number = i + 1; route.PointsFlash = p + (p / 2); route.PointsTop = p; route.PointsBonus = p / 2; route.Type = "ATRANKA"; route.CompetitionId = compId; p += 2; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } } else if (value.ClimbType == 2) { int i; for (i = 0; i < 6; i++) { route.Number = i + 1; route.PointsFlash = 1; route.PointsTop = 1; route.PointsBonus = 1; route.Type = "ATRANKA"; route.CompetitionId = compId; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } } else { int i; for (i = 0; i < 4; i++) { route.Number = i + 1; route.PointsFlash = 1; route.PointsTop = 1; route.PointsBonus = 1; route.Type = "JAUNIMAS"; route.CompetitionId = compId; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } for (i = 0; i < 4; i++) { route.Number = i + 1; route.PointsFlash = 1; route.PointsTop = 1; route.PointsBonus = 1; route.Type = "JAUNIAI"; route.CompetitionId = compId; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } for (i = 0; i < 4; i++) { route.Number = i + 1; route.PointsFlash = 1; route.PointsTop = 1; route.PointsBonus = 1; route.Type = "JAUNUČIAI"; route.CompetitionId = compId; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } for (i = 0; i < 4; i++) { route.Number = i + 1; route.PointsFlash = 1; route.PointsTop = 1; route.PointsBonus = 1; route.Type = "JAUNUOLIAI"; route.CompetitionId = compId; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } for (i = 0; i < 4; i++) { route.Number = i + 1; route.PointsFlash = 1; route.PointsTop = 1; route.PointsBonus = 1; route.Type = "VAIKAI"; route.CompetitionId = compId; CompetitionDB.TblRoutesClim.Add(route); CompetitionDB.SaveChanges(); } } } return(ToJsonCreated(CompetitionDB.SaveChanges())); }