public async Task <IActionResult> Create(Film film, IFormFile poster, int page) { ViewBag.Page = page; var userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); FileSuccess result = null; if (poster != null) { result = await SaveFile(poster, film); } else { film.PosterFileNameOnDisk = @"\Files\empty.jpg"; film.PosterFileNameOriginally = null; } if (result != null && !result.Success) { ModelState.AddModelError("", result.Message); return(View(film)); } if (ModelState.IsValid) { film.OwnerId = _userManager.GetUserId(HttpContext.User); _context.Add(film); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["OwnerId"] = new SelectList(_context.Users, "Id", "Id", film.OwnerId); return(View(film)); }
public async Task <ActionResult> Create(FilmCreate filmModel) { if (ModelState.IsValid) { FilmModel filmDomain = new FilmModel { FilmId = Guid.NewGuid(), Title = filmModel.Title, Description = filmModel.Description, ProductionYear = filmModel.ProductionYear, Director = filmModel.Director, PosterUri = filmModel.PosterUri, UserId = User.Identity.GetUserId() }; db.FilmModels.Add(filmDomain); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(filmModel)); }
public async Task <IActionResult> PutFilm(long id, Film film) { if (id != film.Id) { return(BadRequest()); } _context.Entry(film).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilmExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Baslik,Etiket,Yazi,ResimUrl")] Film film) { film.YaziGiris = DateTime.Today; if (ModelState.IsValid) { _context.Add(film); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(film)); }
public async Task <IActionResult> Create([Bind("FilmID,Name,Genre,Director,Available")] Film film) { if (ModelState.IsValid) { _context.Add(film); await _context.SaveChangesAsync(); TempData["Message"] = "Created: " + film.Name + " successfully"; return(RedirectToAction(nameof(Index))); } return(View(film)); }
public async Task <ActionResult> Create(/*[Bind(Include = "Id,Description,Producer,Processor,RAM,HDD,Body,Picture,Price")] Product product*/ FormCollection data) { Film product = new Film(); product.Genre = data["Genre"]; product.Title = data["Title"]; product.Production = data["Production"]; product.Country = data["Country"]; product.Year = data["Year"]; product.Cast = data["Cast"]; product.Price = Convert.ToInt32(data["Price"]); if (Request.Files["Picture"] != null) { using (var binaryReader = new BinaryReader(Request.Files["Picture"].InputStream)) { var Imagefile = binaryReader.ReadBytes(Request.Files["Picture"].ContentLength); product.Picture = Imagefile; } } if (ModelState.IsValid) { db.Products.Add(product); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <ActionResult> Create([DataSourceRequest] DataSourceRequest request, Tasks model) { if (model != null && ModelState.IsValid) { try { _db.Tasks.Add(model); await _db.SaveChangesAsync(); } catch (Exception e) { return(Json("error")); throw e; } } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }
public async Task <IActionResult> AddOrEdit([Bind("MovieId,Category,Title,Year,Director,Rating,Edited,PersonLent,Notes")] Film film) { if (ModelState.IsValid) { if (film.MovieId == 0) { _context.Add(film); } else { _context.Update(film); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(film)); }
private async void Button_Click_Next(object sender, RoutedEventArgs e) { var user = _сontext.Users.Add(new User() { Login = logintext.Text, Number = phonenumbertext.Text, Password = passwordtext.Text }); await _сontext.SaveChangesAsync(); NavigationService.Navigate(new Uri("Pages/StartPage.xaml", UriKind.Relative)); }
public async Task <IActionResult> PutFilmModel(int id, FilmModel filmModel) { if (id != filmModel.FilmId) { return(BadRequest()); } _context.Entry(filmModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(NoContent()); } return(NoContent()); }
private async Task SaveInDatabaseMoviesSync(List <TopRatedMovie> listMoviesToUpdate, int totalToUpdate) { Console.WriteLine("Saving in database... at : " + DateTime.Now.ToString("t")); foreach (TopRatedMovie trFilmDTO in listMoviesToUpdate) { Context.TopRatedMovies.Update(trFilmDTO); await Context.SaveChangesAsync(); } Console.WriteLine($"Updated a total of : {totalToUpdate}"); Console.WriteLine("Checked titles : " + NumberOfTitlesChecked); Console.WriteLine("Checked lines : " + NumberOfLinesChecked); }
private async void Button_Click_Next(object sender, RoutedEventArgs e) { var muvie = new Movie(); muvie.FilmAbout = aboutfilmtext.Text; muvie.FilmActor = actorfilmtext.Text; muvie.FilmCountry = countryfilmtext.Text; muvie.FilmDirector = directorfilmtext.Text; muvie.FilmGenre = genrefilmtext.Text; muvie.FilmImage = imagePath; muvie.FilmPath = pathfilmtext.Text; muvie.FilmTime = timefilmtext.Text; muvie.FilmYear = yearfilmtext.Text; _context.Movies.Add(muvie); await _context.SaveChangesAsync(); NavigationService.Navigate(new Uri("Pages/ViewPage.xaml", UriKind.Relative)); }
private async Task SaveAsync() { await _context.SaveChangesAsync(); }