Beispiel #1
0
        public bool CreateLeague(LeagueCreate model)
        {
            var entity = new LeagueEntity
            {
                LeagueName = model.LeagueName,
                OwnerID    = _userID
            };

            int changeCount = 1;

            if (model.Teams != null)
            {
                entity.Teams = new List <TeamEntity>();
                foreach (LeagueTeamCreate team in model.Teams)
                {
                    entity.Teams.Add(
                        new TeamEntity
                    {
                        OwnerID   = _userID,
                        TeamName  = team.TeamName,
                        ImageData = team.ImageData
                    });
                }
                changeCount += entity.Teams.Count;
            }

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Leagues.Add(entity);
                return(ctx.SaveChanges() == changeCount);
            }
        }
Beispiel #2
0
        public bool CreateLeague(LeagueCreate model)
        {
            var entity =
                new League()
            {
                LeagueName = model.LeagueName,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Leagues.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #3
0
        public IHttpActionResult Post(LeagueCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            LeagueService service = CreateLeagueService();

            if (service.CreateLeague(model))
            {
                return(Ok());
            }

            return(InternalServerError());
        }
Beispiel #4
0
        public ActionResult Create(LeagueCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateLeagueService();

            if (service.CreateLeague(model))
            {
                TempData["SaveResult"] = "New visitor added.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "League could not be added.");
            return(View(model));
        }
Beispiel #5
0
        public bool CreateLeague(LeagueCreate model)
        {
            var entity =
                new League()
            {
                OwnerId         = _userId,
                LeagueName      = model.LeagueName,
                ZipCode         = model.LeagueZipCode,
                PrivateOrPublic = model.IsPrivate,
                LeaguePassword  = model.LeaguePassword,
                LeagueCreated   = DateTimeOffset.UtcNow,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Leagues.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }