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())); }
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)); }
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)); }