public async Task <ActionResult> Create(BillboardViewModel billboardViewModel) { if (ModelState.IsValid) { await Add(billboardViewModel); } return(View(billboardViewModel)); }
private async Task Add(BillboardViewModel billboardViewModel) { byte[] array = new byte[billboardViewModel.File.InputStream.Length]; var r1 = await billboardViewModel.File.InputStream.ReadAsync(array, 0, array.Length); var billboard = new Billboards.Common.Models.Billboard() { Description = billboardViewModel.Description, Stream = array }; _billboardsService.Add(billboard); }
public IActionResult CreateBillBoard([FromBody] BillboardViewModel model) { string Email = User.FindFirstValue(ClaimTypes.Email); if (Email is null) { return(BadRequest()); } User user = dbHandler.Users.FirstOrDefault(x => x.Email == Email); if (user is null) { return(BadRequest()); } try { Billboard billboard = new Billboard { Name = model.Name, BeginDate = model.BeginDate, EndDate = model.EndDate, Owner = user }; dbHandler.Billboards.Add(billboard); if (model.Movies.Count > 0) { foreach (Movie movie in model.Movies) { Movie movie_db = dbHandler.Movies.FirstOrDefault(x => x.Id == movie.Id); if (movie_db is null) { continue; } BillboardMovieRegister billboardMovieRegister = new BillboardMovieRegister { Movie = movie_db, Billboard = billboard }; dbHandler.BillboardMovieRegisters.Add(billboardMovieRegister); } } dbHandler.SaveChanges(); } catch (Exception) { return(BadRequest(Message.GetMessage("Error al intentar crear una cartellera"))); } return(Ok()); }