示例#1
0
 public RouteClimbModel(TblRouteClimb row)
 {
     Id          = row.Id;
     Number      = row.Number;
     PointsBonus = row.PointsBonus;
     PointsTop   = row.PointsTop;
     PointsFlash = row.PointsFlash;
     CompId      = row.CompetitionId;
     Type        = row.Type;
 }
        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()));
        }