Example #1
0
        public async Task <IActionResult> OnPostDeleteAsync(int id)
        {
            if (id == 0)
            {
                TempData.Danger("Resource ID can't be empty");
                return(RedirectToPage("Index"));
            }

            var entity = await _resManager.GetResourceAsync <XDbResource>(x => x.ID == id);

            if (entity == null)
            {
                TempData.Danger("Resource not found!");
                return(RedirectToPage("Index"));
            }

            if (await _resManager.DeleteResourceAsync <XDbResource>(x => x.Key == entity.Key))
            {
                TempData.Success("Deleted!");
            }
            else
            {
                TempData.Danger("Unknown error occord!");
            }

            return(RedirectToPage("Index"));
        }
Example #2
0
        public async Task <JsonResult> OnPostDeleteTranslationAsync()
        {
            if (Resource.ID == 0)
            {
                return(new JsonResult(new CRUDAjaxReponse {
                    StatusCode = HttpStatusCode.BadRequest, Target = Resource.CultureID
                }));
            }

            if (string.IsNullOrWhiteSpace(Resource.CultureID))
            {
                return(new JsonResult(new CRUDAjaxReponse {
                    StatusCode = HttpStatusCode.BadRequest, Target = Resource.CultureID
                }));
            }

            var entity = await _resManager.GetResourceAsync <XDbResource>(x => x.ID == Resource.ID && x.CultureID == Resource.CultureID);

            if (entity == null)
            {
                return(new JsonResult(new CRUDAjaxReponse {
                    StatusCode = HttpStatusCode.NotFound, Target = Resource.CultureID
                }));
            }

            return(await _resManager.DeleteResourceAsync <XDbResource>(x => x.ID == entity.ID)
                ? new JsonResult(new CRUDAjaxReponse {
                StatusCode = HttpStatusCode.OK, Target = Resource.CultureID
            })
                : new JsonResult(new CRUDAjaxReponse {
                StatusCode = HttpStatusCode.InternalServerError, Target = Resource.CultureID
            }));
        }