Exemplo n.º 1
0
        public IActionResult CreateOrEdit(int id, [Bind("Id,PolicyContent")] Policy policy)
        {
            if (ModelState.IsValid)
            {
                //insert
                if (id == 0)
                {
                    _services.Create(policy);
                }

                //update
                else
                {
                    try
                    {
                        _services.UpdatePolicy(policy);
                    }
                    catch (Exception)
                    {
                        if (!_services.IsExist(policy.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAllPolicies", _services.GetListPolicies()) }));
            }
            return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "CreateOrEdit", policy) }));
        }