public async Task <IActionResult> Edit(int id, [Bind("Id,Idguide,Idpattern,Price")] ExcurionGuide excurionGuide)
        {
            if (id != excurionGuide.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(excurionGuide);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExcurionGuideExists(excurionGuide.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idguide"]   = new SelectList(_context.Guide, "Id", "FullName", excurionGuide.Idguide);
            ViewData["Idpattern"] = new SelectList(_context.Pattern, "Id", "Description", excurionGuide.Idpattern);
            return(View(excurionGuide));
        }
        public async Task <IActionResult> Create([Bind("Id,Idguide,Idpattern,Price")] ExcurionGuide excurionGuide)
        {
            if (ModelState.IsValid)
            {
                _context.Add(excurionGuide);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idguide"]   = new SelectList(_context.Guide, "Id", "FullName", excurionGuide.Idguide);
            ViewData["Idpattern"] = new SelectList(_context.Pattern, "Id", "Description", excurionGuide.Idpattern);
            return(View(excurionGuide));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,FullName,CategoryId")] Guide guide)
        {
            System.Diagnostics.Debug.WriteLine(Request.Form["FullName"].ToString());
            if (ModelState.IsValid)
            {
                _context.Add(guide);
                await _context.SaveChangesAsync();

                foreach (var i in _context.Pattern)
                {
                    string selected = Request.Form[i.Id.ToString()];
                    string price    = Request.Form[i.Id.ToString() + "-price"];
                    System.Diagnostics.Debug.WriteLine(i.Name + " " + selected + " " + price);

                    if (selected != "on")
                    {
                        continue;
                    }

                    ExcurionGuide add = new ExcurionGuide
                    {
                        Price     = Convert.ToDecimal(price),
                        Idguide   = guide.Id,
                        Idpattern = i.Id,
                    };
                    if ((from e_g in _context.ExcurionGuide
                         where e_g.Idguide == add.Idguide && e_g.Idpattern == add.Idpattern && e_g.Price == add.Price
                         select e_g).ToList().Count() == 0)
                    {
                        _context.Add(add);
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", guide.CategoryId);
            return(View(guide));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,CategoryId")] Guide guide)
        {
            if (id != guide.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(guide);
                    await _context.SaveChangesAsync();

                    foreach (var i in _context.Pattern)
                    {
                        string selected = Request.Form[i.Id.ToString()];
                        string price    = Request.Form[i.Id.ToString() + "-price"];
                        System.Diagnostics.Debug.WriteLine(i.Name + " " + selected + " " + price);

                        if (selected != "on")
                        {
                            var ep = (from eg in _context.ExcurionGuide
                                      where eg.Idguide == id && eg.Idpattern == i.Id
                                      select eg).ToList();
                            if (ep.Count > 0)
                            {
                                foreach (var e in ep)
                                {
                                    _context.Remove(e);
                                }
                            }
                            continue;
                        }

                        ExcurionGuide add = new ExcurionGuide
                        {
                            Price     = Convert.ToDecimal(price),
                            Idguide   = guide.Id,
                            Idpattern = i.Id,
                        };

                        _context.Add(add);
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuideExists(guide.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", guide.CategoryId);
            return(View(guide));
        }