Exemplo n.º 1
0
        public async Task <IActionResult> AddImage(ActivityImageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                //se valida lo que envio IFormFile
                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile);
                }

                var activityImage = new ActivityImage
                {
                    ImageUrl = path,
                    Activity = await _dataContext.Activities.FindAsync(model.Id)
                };

                _dataContext.ActivityImages.Add(activityImage);
                await _dataContext.SaveChangesAsync();

                return(RedirectToAction($"{nameof(DetailsActivity)}/{model.Id}"));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        //aqui se recibe el Id de la propiedad que se le va a agregar la image
        public async Task <IActionResult> AddImage(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var activity = await _dataContext.Activities.FindAsync(id.Value);

            if (activity == null)
            {
                return(NotFound());
            }

            var model = new ActivityImageViewModel
            {
                Id = activity.Id
            };

            return(View(model));
        }