Exemplo n.º 1
0
        public async Task <ActionResult> AddChannelToTablau(TvChannel tvChannel)
        {
            /*
             * Fullösningar is da new black!
             * Tar ut en tvChannel från vyn och konverterar den till userTablau som kan skickas till databasen.
             * Model.IsValid funkar inte eftersom det är en tvkanal som kommer från vyn men en usertablau som ska in till databasen
             */
            var        userID     = HttpContext.User.Identity.GetUserId();
            UserTablau userTablau = new UserTablau()
            {
                TvChannelID   = tvChannel.ID,
                AspNetUsersId = HttpContext.User.Identity.GetUserId()
            };

            if (userTablau.AspNetUsersId != null && userTablau.TvChannelID != null)
            {
                dbContext.UserTablaus.Add(userTablau);
                await dbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            var userTablaus = dbContext.UserTablaus.Where(x => x.AspNetUsersId == userID).Include(u => u.TvChannel);


            return(View(await userTablaus.ToListAsync()));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create([Bind(Include = "ID,Name")] TvChannel tvChannel)
        {
            if (ModelState.IsValid)
            {
                dbContext.TvChannels.Add(tvChannel);
                await dbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(tvChannel));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "ID,Title,Details,Broadcasting,Duration,TvChannelID")] TvProgram tvProgram)
        {
            if (ModelState.IsValid)
            {
                dbContext.TvPrograms.Add(tvProgram);
                await dbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.TvChannelID = new SelectList(dbContext.TvChannels, "ID", "Name", tvProgram.TvChannelID);
            return(View(tvProgram));
        }