コード例 #1
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));
        }
コード例 #2
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));
        }
コード例 #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));
        }
コード例 #4
0
        public ActionResult AjaxMethod(DTParameters param)
        {
            var comModelList = new List <ComModel>();

            using (var context = new AnimalEntities())
            {
                IQueryable <ComModel> ListData = context.T_COM.AsNoTracking()
                                                 .Where(x => x.del_flag == 0)
                                                 .Select(x =>
                                                         new ComModel
                {
                    Com_Id    = x.com_id,
                    ComName   = x.com_name,
                    ComDetail = x.com_detail,
                });                 // return type to be IQueryable

                //take and skip record according to pagination
                var takeData = ListData.OrderBy(q => q.Com_Id).Skip(param.Start).Take(param.Length).ToList();

                if (!string.IsNullOrEmpty(param.Search.Value))
                {
                    var sendData = takeData.Where(p => p.Com_Id.ToString().ToLower().Contains(param.Search.Value.ToLower()) ||
                                                  p.ComName != null && p.ComName.ToLower().Contains(param.Search.Value.ToLower()) ||
                                                  p.ComDetail != null && p.ComDetail.ToLower().Contains(param.Search.Value.ToLower())).ToList();

                    DTResult <ComModel> result = new DTResult <ComModel>
                    {
                        draw            = param.Draw,
                        data            = sendData.ToList(),
                        recordsFiltered = ListData.Count(),
                        recordsTotal    = ListData.Count(),
                    };
                    return(Json(result));
                }
                else
                {
                    var sendData = takeData;
                    DTResult <ComModel> result = new DTResult <ComModel>
                    {
                        draw            = param.Draw,
                        data            = sendData.ToList(),
                        recordsFiltered = ListData.Count(),
                        recordsTotal    = ListData.Count(),
                    };
                    return(Json(result));
                }
            }
        }
コード例 #5
0
        public ActionResult Login(AuthModel model)
        {
            bool hasUser = false;

            using (var context = new AnimalEntities())
            {
                hasUser = context.M_USER.AsNoTracking().Where(x => x.user_id == model.Id &&
                                                              x.password == model.Password &&
                                                              x.del_flag == 0).Any();
            }
            //if (model.Id == "test" && model.Password == "passwd")
            if (hasUser)
            {
                // ユーザー認証 成功
                FormsAuthentication.SetAuthCookie(model.Id, true);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                // ユーザー認証 失敗
                this.ModelState.AddModelError(string.Empty, "指定されたユーザー名またはパスワードが正しくありません。");
                return(this.View(model));
            }
        }
コード例 #6
0
 public HomeController()
 {
     // a better way is passing context via parameter
     _dbcontext = new AnimalEntities();
 }