コード例 #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));
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        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()));
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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();
            }
        }