コード例 #1
0
        public ActionResult Create(MenuGroup menuGroups)
        {
            if (ModelState.IsValid)
            {
                _menuGroupService.Add(menuGroups);
                return(RedirectToAction("Index"));
            }

            return(View(menuGroups));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("MenuGroupId,MenuTitile,MenuType,IsActive")] MenuGroup menuGroup)
        {
            if (ModelState.IsValid)
            {
                await _menuGroupService.Add(menuGroup);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuGroup));
        }
コード例 #3
0
        public JsonResult Post(string menuGroup)
        {
            string message = string.Empty;
            var    jsonObj = new JavaScriptSerializer();
            var    model   = jsonObj.Deserialize <MenuGroup>(menuGroup);

            _menuGroupService.Add(model);
            _menuGroupService.Save();
            message = ResultState.Add_SUCCESS;
            return(Json(new
            {
                message = message,
                status = true,
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
 public HttpResponseMessage Post(HttpRequestMessage request, MenuGroupViewModel menuGroupVm)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             MenuGroup newMenuGroup = new MenuGroup();
             newMenuGroup.UpdateMenuGroup(menuGroupVm);
             var category = _menuGroupService.Add(newMenuGroup);
             _menuGroupService.SaveChanges();
             response = request.CreateResponse(HttpStatusCode.Created, category);
         }
         return response;
     }));
 }
コード例 #5
0
 public async Task <HttpResponseMessage> Post(HttpRequestMessage request, MenuGroupViewModel menuGroupVm)
 {
     return(await CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             //Khoi tao
             MenuGroup newMenuGroup = new MenuGroup();
             newMenuGroup.UpdateMenuGroup(menuGroupVm); //Gan ViewModel sang Model de Insert DB, this
             //Goi Insert
             var menuGroup = _menuGroupService.Add(newMenuGroup);
             _menuGroupService.SaveAsync();
             response = request.CreateResponse(HttpStatusCode.Created, menuGroup);
         }
         return response;
     }));
 }