Ejemplo n.º 1
0
        public ActionResult Delete(ComModel model)
        {
            try
            {
                // 削除処理
                T_COM com = null;
                using (var context = new AnimalEntities())
                {
                    var    now    = DateTime.Now;
                    string userID = User.Identity.Name;

                    com             = context.T_COM.Where(x => x.com_id == model.Com_Id).FirstOrDefault();
                    com.del_flag    = 1;
                    com.update_date = now;
                    com.update_user = userID;

                    context.SaveChanges();
                }
                // 一覧画面にリダイレクト
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "問題が発生しました。");
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Create(ComModel model)
        {
            try
            {
                // 入力チェック
                if (!this.ModelState.IsValid)
                {
                    return(View(model));
                }
                // 登録処理
                using (var context = new AnimalEntities())
                {
                    DateTime now        = DateTime.Now;
                    string   userID     = User.Identity.Name;
                    T_COM    targetData = new T_COM();
                    targetData.com_name    = model.ComName;
                    targetData.com_detail  = model.ComDetail;
                    targetData.create_date = now;
                    targetData.create_user = userID;
                    targetData.update_date = now;
                    targetData.update_user = userID;

                    context.T_COM.Add(targetData);
                    context.SaveChanges();
                }
                // 一覧画面にリダイレクト
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "問題が発生しました。");
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int?id)
        {
            var model = new ComModel();

            if (id == null)
            {
                return(RedirectToAction("Create"));
            }

            T_COM comDetail = null;

            using (var context = new AnimalEntities())
            {
                comDetail = context.T_COM.AsNoTracking().Where(x => x.com_id == id).FirstOrDefault();
            }
            if (comDetail == null)
            {
                return(HttpNotFound());
            }

            model.Com_Id    = comDetail.com_id;
            model.ComName   = comDetail.com_name;
            model.ComDetail = comDetail.com_detail;

            return(View(model));
        }