Example #1
0
        public async Task <IActionResult> Edit(AdminCourseCategoryDto model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_EditPartial", model));
            }

            //主键初始Id大于0表示是编辑,反之则是新增
            if (model.Id > 0)
            {
                var result = await _service.Update(model);

                return(Json(result));
            }
            else
            {
                var result = await _service.Add(model);

                return(Json(result));
            }
        }
Example #2
0
        public JsonResult Action(CourseCategoryActionModel model)
        {
            bool result;

            if (model.ID > 0)
            {
                CourseCategory objectFirst = service.GetByID(model.ID);
                objectFirst.ID         = model.ID;
                objectFirst.Name       = model.Name;
                objectFirst.UserID     = UserHelperInfo.GetUserId();
                objectFirst.ModifiedOn = DateTime.Now;
                objectFirst.IP         = UserInfo.IP();
                objectFirst.Agent      = UserInfo.Agent();
                objectFirst.Location   = UserInfo.Location();
                result = service.Update(objectFirst);
            }
            else
            {
                CourseCategory objectFirst = new CourseCategory
                {
                    Name       = model.Name,
                    UserID     = UserHelperInfo.GetUserId(),
                    ModifiedOn = DateTime.Now,
                    IP         = UserInfo.IP(),
                    Agent      = UserInfo.Agent(),
                    Location   = UserInfo.Location()
                };

                result = service.Save(objectFirst);
            }

            JsonResult jsonResult = new JsonResult
            {
                Data = result ? (new { Success = true, Msg = "" }) : (new { Success = false, Msg = "Unable to Save Course" })
            };

            return(jsonResult);
        }