Пример #1
0
        public ActionResult Create([Bind(Include = "Id,Name")] Sex sex)
        {
            if (ModelState.IsValid)
            {
                db.Sexes.Add(sex);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sex));
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "Id,Name,SexId,Email")] Parent parent)
        {
            if (ModelState.IsValid)
            {
                db.Parents.Add(parent);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SexId = new SelectList(db.Sexes, "Id", "Name", parent.SexId);
            return(View(parent));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "Id,Name,SexId,Birthday,ParentId")] Child child)
        {
            if (ModelState.IsValid)
            {
                db.Children.Add(child);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ParentId = new SelectList(db.Parents, "Id", "Name", child.ParentId);
            ViewBag.SexId    = new SelectList(db.Sexes, "Id", "Name", child.SexId);
            return(View(child));
        }
        public ActionResult Import(CsvFile file)
        {
            // ファイルチェック
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // ファイル読み込み
            CsvImportService csvImportService = new CsvImportService(file.UploadFile.InputStream);

            // バリデーション
            if (!csvImportService.IsValid)
            {
                ViewBag.ErrorMessageList = csvImportService.ErrorMessageList;
                return(View());
            }

            // モデル取得
            List <Parent> parentList = csvImportService.ParentList;

            // DB 登録
            parentList.ForEach(p => db.Parents.Add(p));
            db.SaveChanges();

            ViewBag.SuccessMessage = "インポートに成功しました。";
            return(View());
        }