public MyMessage DataDelete(String param) { MyMessage resultFromDb = null; try { using (var db = new MessageModel()) { resultFromDb = db.MyMessages.First(m => m.Message.Contains(param)); db.MyMessages.Remove(resultFromDb); db.SaveChanges(); resultFromDb.Message = resultFromDb.Message + "...this record removed."; //Will use late for another method. //var resultFromDb2 = db.MyMessages.Where(m => m.Id != null); //db.MyMessages.RemoveRange(resultFromDb2); //db.SaveChanges(); //resultFromDb.Message = resultFromDb.Message + "...this record removed."; } } catch (Exception) { resultFromDb = new MyMessage {Id=0,Message="No record found."}; } return resultFromDb; }
//Exception form debugging on 7/28/2015 //Message = "Login failed for user 'contactmanageradmin'.\r\nThis session has been // assigned a tracing ID of '80b6afc5-897c-4c95-b5b1-7cdaa57cac75'. // Provide this tracing ID to customer support when you need assistance." public String DataUpdate(MyMessage content) { String responseMessage = " "; try { using (var db = new MessageModel()) { db.MyMessages.Add(content); db.SaveChanges(); } responseMessage = "Your message successfully POSTed."; return responseMessage; } catch (Exception) { responseMessage = "Error, your message did not POST."; return responseMessage; } }