public string Delete(int id) { SessionFactory sessionsFactory = new SessionFactory(); SessionsTable <Session> instance = (SessionsTable <Session>)sessionsFactory.GetSessionInstance(); var list = Request.Headers.ToList(); var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty); if (token == null) { return("NOT LOGED"); } var dispatcher = instance.SelectDispatcherSession(token); var driver = instance.SelectDriverSession(token); var manager = instance.SelectManagerSession(token); if (dispatcher == null && driver == null && manager == null) { return("NOT EXISTING USER"); } MessageFactory messageFactory = new MessageFactory(); MessageTable <Message> instanceMessage = (MessageTable <Message>)messageFactory.GetMessageInstance(); instanceMessage.Delete(id); return("OK"); }