Example #1
0
        public JsonResult DeleteUploadJS(ExtractViewModel extract)
        {
            var ajaxResponse = new AjaxResponse {
                Success = false, Message = string.Format("There was a problem deleting upload, ID: {0}", extract.ExtractId)
            };

            if (extract.ExtractId == 0)     //shouldn't happen
            {
                return(Json(ajaxResponse));
            }

            try
            {
                var existingExCount = _unitOfWork.Audits.GetAll().Where(a => a.ExtractId == extract.ExtractId).Count();

                if (existingExCount > 0)    //can't delete, its is in use
                {
                    ajaxResponse.Message = "Cannot delete an upload used in an audit";
                    return(Json(ajaxResponse));
                }

                int result = ExtractViewModel.DeleteExtract(_unitOfWork, (int)extract.ExtractId);

                if (result < 1)
                {
                    return(Json(ajaxResponse));
                }

                ajaxResponse.Message = "Success";
                ajaxResponse.Success = true;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
            }

            return(Json(ajaxResponse));
        }