Beispiel #1
0
        public ActionResult Create([Bind(Include = "Id,Title,ImageUrl,LinkUrl")] Section section)
        {
            if (ModelState.IsValid)
            {
                db.Sections.Add(section);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(section));
        }
 public bool createSectionInfo(String sectionName, String name, String city, String location)
 {
     if (db.Sections.FirstOrDefault(e => e.SectionName == sectionName) == null)
     {
         db.Sections.Add(new Section {
             SectionName = sectionName, Name = name, City = city, Location = location
         });
         db.SaveChanges();
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public IActionResult PostNewSection(string registerSection, string registerName, string registerCity, string registerLocation)
        {
            var hasSection = false;

            foreach (var s in _context.Sections)
            {
                if (!hasSection && s.SectionName == registerSection)
                {
                    hasSection = true;
                }
            }

            if (!hasSection)
            {
                _context.Sections.Add(new SectionItem {
                    SectionName = registerSection,
                    Name        = registerName,
                    City        = registerCity,
                    Location    = registerLocation
                });
                _context.SaveChanges();
            }

            return(View("~/Views/Home/Index.cshtml", _context.Sections.ToList()));
        }
        public IActionResult AddSectionInfo(string context, SectionItem item)
        {
            foreach (var s in _context.Sections)
            {
                if (s.SectionName == context)
                {
                    return(BadRequest(context));
                }
            }

            _context.Sections.Add(new SectionItem {
                SectionName = context,
                Name        = item.Name,
                City        = item.City,
                Location    = item.Location
            });
            _context.SaveChanges();
            return(Ok());
        }
        public HomeController(SectionContext context)
        {
            _context = context;

            if (_context.Sections.Count() == 0)
            {
                _context.Sections.Add(new SectionItem {
                    SectionName = "GIS",
                    Name        = "Geoinformation Systems",
                    City        = "Tomsk",
                    Location    = "Lenina 2, 404"
                });
                _context.Sections.Add(new SectionItem {
                    SectionName = "CS",
                    Name        = "Computer Science",
                    City        = "Tomsk",
                    Location    = "Lenina 30, 206"
                });
                _context.SaveChanges();
            }
        }