public async Task <JsonResult> Delete(int id)
        {
            var result = 0;

            try
            {
                result = await _repository.DeleteEmployee(id);
            }catch (Exception exp)
            {
                throw exp;
            }
            if (result > 0)
            {
                return(Json(new { status = 1, message = " successfully." }));
            }
            return(Json(new { status = 0, message = "Something went wrong, please contact administrator." }));
        }
Beispiel #2
0
        public async Task <ActionResult> Delete(FormCollection formCollection)
        {
            string idStr = formCollection["id"];

            if (!int.TryParse(formCollection["id"], out int id) || id == 0)
            {
                return(Json(new { status = "error", message = "Invalid id." }));
            }

            try
            {
                await repository.DeleteEmployee(id);
            }
            catch (InvalidOperationException e)
            {
                return(Json(new { status = "error", message = e.Message }));
            }

            return(Json(new { status = "success", message = "Employee has been successfully deleted." }));
        }