public ReportCrime SaveReport(long?id, string typeOfCrime, string location, string date, string time, string name, string contactNo, string status) { /* Authenticate(PrivilegeType.ReportCrimeMaintenance);*/ ReportCrime rep = new ReportCrime(); DataTable dt; // Outlook.Folder deletee = new Outlook.Folder(); // Outlook.MailItem info = new Outlook.MailItem(); Outlook._Application _app = new Outlook.Application(); Outlook._NameSpace _ns = _app.GetNamespace("MAPI"); Outlook.MAPIFolder inbox = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); // Outlook.MAPIFolder delete = _ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems); _ns.SendAndReceive(true); dt = new DataTable("Inbox"); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("Sender", typeof(string)); dt.Columns.Add("Body", typeof(string)); dt.Columns.Add("Date", typeof(string)); string subItem = ""; foreach (Outlook.MailItem item in inbox.Items) { if (item.UnRead == true) { subItem = item.Subject; int testChar = subItem.IndexOf("-"); if (subItem.IndexOf("-") > 0) { for (int x = 0; x < subItem.Length; x++) { if (subItem.Substring(x, 1) == "-" && testChar == x) { typeOfCrime = subItem.Substring(0, x); } if (subItem.Substring(x, 1) == "-" && testChar != x) { name = subItem.Substring(typeOfCrime.Length + 1, x - typeOfCrime.Length - 1); contactNo = subItem.Substring(x + 1); } } } else { typeOfCrime = item.Subject; name = "Anonymous"; contactNo = "Anonymous"; } status = "Pending"; location = item.Body; date = item.SentOn.ToLongDateString(); time = item.SentOn.ToLongTimeString(); rep.Status = status; rep.TypeOfCrime = typeOfCrime; rep.Name = name; rep.ContactNo = contactNo; rep.Location = location; rep.Date = date; rep.Time = time; DataContext.ReportCrimeSet.Add(rep); DataContext.SaveChanges(); } if (item.UnRead) { item.UnRead = false; item.Save(); } } // _serialPort.Write("1"); //_serialPort.Close(); //Outlook.ContactItem contact = // _ns.geGetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts). // Items. // Find( // string.Format("[LastName]='{0}' AND [FirstName]='{1}'", // lastName, firstName)) // as Outlook.ContactItem; //if (contact != null) //{ // contact.Delete(); //} return(rep); }
public ActionResult GetReportCrimes(long?id) { if (id == null) { id = 0; } try { SerialPort _serialPort = new SerialPort(); _serialPort.PortName = "COM4"; _serialPort.BaudRate = 9600; _serialPort.Open(); /*if(!_serialPort.IsOpen) * { _serialPort.Open(); }*/ ReportCrime rep = new ReportCrime(); //do some work here on the provider var model = ReportCrimeProvider.getCrimes().Where(a => a.Id == id).Select(a => new ReportCrimeModel() { Id = a.Id, Status = a.Status, Name = a.Name, ContactNo = a.ContactNo, TypeOfCrime = a.TypeOfCrime, Location = a.Location, Date = a.Date, Time = a.Time }).Single(); // _serialPort.Write("1"); //dont forget to substring the location to 32 bit characters string dataList = model.Location + "-" + model.TypeOfCrime; string dataset = ""; if (dataList.Length > 27) { dataset = dataList.Substring(0, 26); } else { dataset = dataList; } _serialPort.Write(dataset + "."); _serialPort.Close(); rep = DataContext.ReportCrimeSet.Where(a => a.Id == model.Id).SingleOrDefault(); rep.Status = "Reported"; DataContext.SaveChanges(); //test(model.TypeOfCrime, model.Location); return(SerializeToAngular(model)); } catch (ReportCrimeException e) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message)); } }