public int CreateView([FromBody] MediaView mediaView) { int newId = -1; if (ModelState.IsValid) { try { newId = _webDataContext.AddView(ref mediaView); _webDataContext.SaveChanges(); MediaView.Message = "Success"; } catch (System.Data.SqlClient.SqlException databaseException) { MediaView.Message = "Database Exception"; Console.Write(databaseException); } catch (Exception ex) { MediaView.Message = ex.InnerException.ToString(); } } return(newId); }