Exemplo n.º 1
0
        public async Task <IActionResult> EditService(ServiceEditViewModel webModel)
        {
            if (ModelState.IsValid)
            {
                bool flag;
                if (string.IsNullOrEmpty(webModel.Id))
                {
                    //Add Data
                    flag = await _service.InsertServiceAsync(webModel, _context);
                }
                else
                {
                    //Update Data
                    flag = await _service.UpdateServiceAsync(webModel, _context);
                }

                return(Json(new
                {
                    success = flag,
                    msg = flag ? "迎新服务信息编辑成功" : "迎新服务信息编辑失败"
                }));
            }

            return(Json(new
            {
                success = false,
                msg = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors).FirstOrDefault().ErrorMessage
            }));
        }