Пример #1
0
        public async Task <ActionResult> Create(BillboardViewModel billboardViewModel)
        {
            if (ModelState.IsValid)
            {
                await Add(billboardViewModel);
            }

            return(View(billboardViewModel));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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());
        }