Example #1
0
        public JsonResult SaveData(string strMenuType)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            MenuType             menuType   = serializer.Deserialize <MenuType>(strMenuType);
            bool   status  = false;
            string action  = string.Empty;
            string message = string.Empty;
            bool   res     = new MenuTypeDao().CheckIDExist(menuType.ID);

            if (res)
            {
                var model = new MenuTypeDao();
                try
                {
                    model.Insert(menuType);
                    status = true;
                    action = "insert";
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            else
            {
                //update existing DB
                //save db
                try
                {
                    var model = new MenuTypeDao().Update(menuType);
                    status = true;
                    action = "update";
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }

            return(Json(new
            {
                status = status,
                message = message,
                action = action
            }));
        }
Example #2
0
        public ActionResult Create(MenuType collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add insert logic here

                    MenuTypeDao bdDao = new MenuTypeDao();
                    if (bdDao.FindByID(collection.ID) == null)
                    {
                        UserLogin us = (UserLogin)Session[SystemConsts.USER_SESSION];
                        collection.CreatedBy    = us.UserName;
                        collection.CreatedDate  = Hepper.GetDateServer();
                        collection.ModifiedBy   = us.UserName;
                        collection.ModifiedDate = Hepper.GetDateServer();
                        //collection.CreateBy = us.UserName;
                        //collection.ModifiedBy = us.UserName;
                        if (bdDao.Insert(collection))
                        {
                            SetAlert("Thêm thành công", "success");
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            SetAlert("Không thêm được", "danger");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Mã nhóm menu đã tồn tại");
                    }
                }
                return(View());
            }
            catch
            {
                SetAlert("Không thêm được", "danger");
                return(View());
            }
        }