Beispiel #1
0
        public async Task <ActionResult> Delete(string id)
        {
            try
            {
                //delete from db and cache if exists
                if (await _vehicleService.DeleteById(id))
                {
                    _cache.Remove(id);

                    //accepted response code, also 200 (OK) code be used too
                    Response.StatusCode = 202;
                    return(Json(new { success = true, message = "Deleted Successfully" }));
                }
                else
                {
                    Response.StatusCode = 500;
                    return(Json(new
                    {
                        success = false,
                        message = "Error occured while deleting vehicle, plz try again later "
                    }));
                }
            }
            catch (KeyNotFoundException)
            {
                Response.StatusCode = 404;
                return(Json(new { success = false, message = "Not Found!" }));
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return(Json(new { success = false, message = "Error!" + ex.Message }));
            }
        }
Beispiel #2
0
 public Task <bool> DeleteById(string id)
 {
     return(_vehicle.DeleteById(id));
 }