// GET: Recetas/Create
        public IActionResult Create()
        {
            var model = new RecetaViewModel
            {
                Insumos = _combosHelper.GetComboInsumo(),

                ProductosReales = _combosHelper.GetComboProductosReales(),
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(RecetaViewModel model)
        {
            if (ModelState.IsValid)
            {
                var receta = await _converterHelper.ToRecetaAsync(model);

                await _recetaRepository.CreateAsync(receta);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Beispiel #3
0
        //Receta
        public async Task <Receta> ToRecetaAsync(RecetaViewModel model)
        {
            return(new Receta
            {
                Id = model.Id,

                Insumo = await _dataContext.Insumos.FindAsync(model.InsumoId),

                ProductoReal = await _dataContext.ProductoReal.FindAsync(model.ProductoRealId),

                Porcentaje = model.Porcentaje,
            });
        }
        public async Task <IActionResult> Edit(RecetaViewModel view)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var path = view.ImagenUrl;

                    if (view.ImageFile != null && view.ImageFile.Length > 0)
                    {
                        var guid = Guid.NewGuid().ToString();
                        var file = $"{guid}.jpg";


                        path = Path.Combine(
                            Directory.GetCurrentDirectory(),
                            "wwwroot\\images\\Recetas",
                            file);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await view.ImageFile.CopyToAsync(stream);
                        }

                        path = $"~/images/Recetas/{file}";
                    }

                    var receta = this.ToReceta(view, path);

                    // TODO: Pending to change to: this.User.Identity.Name
                    receta.User = await this._userHelper.GetUserByEmailAsync("*****@*****.**");

                    await this._recetaRepository.UpdateAsync(receta);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await this._recetaRepository.ExistAsync(view.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(view));
        }
        public async Task <IActionResult> Edit(RecetaViewModel model)
        {
            if (ModelState.IsValid)
            {
                //El id de la presentacion tiene que ser igual al id de la etiqueta por la relacion 1-1
                var receta = await _converterHelper.ToRecetaAsync(model);

                await _recetaRepository.UpdateAsync(receta);


                //Dtalles del propietario
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Beispiel #6
0
 private Receta ToReceta(RecetaViewModel view, string path)
 {
     return(new RecetaViewModel
     {
         Id = view.Id,
         ImagenUrl = path,
         Comentarios = view.Comentarios,
         Descripcion = view.Descripcion,
         Dificultad = view.Dificultad,
         Nombre = view.Nombre,
         Raciones = view.Raciones,
         RegionId = view.RegionId,
         Temporada = view.Temporada,
         Tiempo = view.Tiempo,
         User = view.User
     });
 }
        public async Task <IActionResult> Create(RecetaViewModel view)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (view.ImageFile != null && view.ImageFile.Length > 0)
                {
                    var guid = Guid.NewGuid().ToString();
                    var file = $"{guid}.jpg";


                    path = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        "wwwroot\\images\\Recetas",
                        file);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await view.ImageFile.CopyToAsync(stream);
                    }

                    path = $"~/images/Recetas/{file}";
                }

                var receta = this.ToReceta(view, path);



                receta.User = await this._userHelper.GetUserByEmailAsync(this.User.Identity.Name);

                // receta.PasosRecetas.Add(pasosReceta);

                await this._recetaRepository.CreateAsync(receta);


                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(view));
        }
        public IActionResult Receta(string id)
        {
            sweetbakeryContext contexto = new sweetbakeryContext();

            var nombre = id.Replace("-", " ").ToUpper();

            var receta = contexto.Recetas.FirstOrDefault(x => x.Nombre.ToUpper() == nombre);

            if (receta == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                RecetaViewModel vm = new RecetaViewModel();
                vm.Receta = receta;
                Random r = new Random();
                vm.Otras = contexto.Recetas.Where(x => x.Id != receta.Id).ToList().OrderBy(x => r.Next()).Take(3);


                return(View(vm));
            }
        }
 public Recetas()
 {
     InitializeComponent();
     BindingContext = viewModel = new RecetaViewModel();
 }