private PONote getPONoteByID(int poNoteID, CFIEntities db) { var query = from p in db.PONotes where p.ID == poNoteID select p; PONote[] poNotes = query.ToArray <PONote>(); if (poNotes.Length == 0) { return(null); } else { PONote poNote = poNotes[0]; if (poNote.Deleted == false) { return(poNote); } else { return(null); } } }
public NoteInfo GetNote(string accessToken, int noteID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { PONote poNote = getPONoteByID(noteID, db); if (poNote == null) { return(null); } else { return(ConversionUtils.ToNoteInfo(poNote, db)); } } } catch (Exception ex) { logException(ex); return(null); } }
public static PONote ToPONote(NoteInfo note, int orderID) { PONote poNote = new PONote(); poNote.OrderID = orderID; poNote.NoteTypeID = note.TypeID; poNote.NoteText = note.Text; poNote.DateTimeEntered = note.DateTimeEntered; poNote.EnteredByUserID = note.EnteredByUserID; poNote.SentViaXML = note.SentToStore; if ((note.DateTimeSentToStore == DateTime.MinValue) || (note.DateTimeSentToStore == DateTime.MaxValue)) { poNote.DateTimeSent = null; } else { poNote.DateTimeSent = note.DateTimeSentToStore; } return(poNote); }
public bool UpdateNoteText(string accessToken, int noteID, string newText) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { PONote poNote = getPONoteByID(noteID, db); poNote.NoteText = newText; db.SaveChanges(); } return(true); } catch (Exception ex) { logException(ex); return(false); } }
public bool AddNote(string accessToken, int orderID, NoteInfo note) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { Order order = getOrderByID(orderID, db); PONote poNote = ConversionUtils.ToPONote(note, orderID); order.PONotes.Add(poNote); db.SaveChanges(); } return(true); } catch (Exception ex) { logException(ex); return(false); } }
public bool DeleteNote(string accessToken, int noteID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { PONote poNote = getPONoteByID(noteID, db); if (poNote != null) { poNote.Deleted = true; db.SaveChanges(); } } return(true); } catch (Exception ex) { logException(ex); return(false); } }
public static NoteInfo ToNoteInfo(PONote poNote, CFIEntities db) { NoteInfo note = new NoteInfo(); note.ID = poNote.ID; if (poNote.NoteText == null) { note.Text = ""; } else { note.Text = poNote.NoteText.Trim(); } note.TypeID = poNote.NoteTypeID; note.NoteTypeDescription = getNoteTypeDescription(poNote.NoteTypeID, db); note.DateTimeEntered = poNote.DateTimeEntered; if (poNote.DateTimeSent != null) { note.DateTimeSentToStore = poNote.DateTimeSent.Value; } else { note.DateTimeSentToStore = DateTime.MaxValue; } if (poNote.EnteredByUserID != null) { note.EnteredByUserID = poNote.EnteredByUserID.Value; note.EnteredByUser = getUserName(poNote.EnteredByUserID.Value, db); } else { note.EnteredByUserID = -1; note.EnteredByUser = null; } note.SentToStore = poNote.SentViaXML; return(note); }