public string GetNotes(string accessToken, int orderID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { PONote[] poNotes = getPONotesByOrderID(orderID, db); if (poNotes == null) { return(null); } else { NoteInfo[] notes = ConversionUtils.ToNoteInfoArray(poNotes, db); return(NoteInfo.BuildNotesXml(notes)); } } } catch (Exception ex) { logException(ex); return(null); } }
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 string GetPhotos(string accessToken, int orderID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { POPhoto[] poPhotos = getPOPhotosByOrderID(orderID, db); if (poPhotos == null) { return(null); } else { PhotoInfo[] photos = ConversionUtils.ToPhotoInfoArray(poPhotos, db); return(PhotoInfo.BuildPhotosXml(photos)); } } } catch (Exception ex) { logException(ex); return(null); } }
public bool AddPhoto(string accessToken, int orderID, PhotoInfo photo, string fileExtension, string uploadedFileClaimToken) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { Order order = getOrderByID(orderID, db); // the file name will depend on the po number and how many other photos may have already been added string fileName = getPhotoFileName(order.OrderID, fileExtension); photo.FilePath = fileName; // claim the uploaded file and name it and store it in the proper location byte[] photoBytes = Globals.FileTransferManager.Uploader.ClaimFile(uploadedFileClaimToken); savePhoto(order.OrderID, fileName, photoBytes); POPhoto poPhoto = ConversionUtils.ToPOPhoto(photo, orderID); order.POPhotos.Add(poPhoto); db.SaveChanges(); } return(true); } catch (Exception ex) { logException(ex); return(false); } }
public PhotoInfo GetPhoto(string accessToken, int photoID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { POPhoto poPhoto = getPOPhotoByID(photoID, db); if (poPhoto == null) { return(null); } else { return(ConversionUtils.ToPhotoInfo(poPhoto, db)); } } } catch (Exception ex) { logException(ex); 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); } }
private POPhoto getPOPhotoByID(int poPhotoID, CFIEntities db) { var query = from p in db.POPhotos where p.ID == poPhotoID select p; POPhoto[] poPhotos = query.ToArray <POPhoto>(); if (poPhotos.Length == 0) { return(null); } else { POPhoto poPhoto = poPhotos[0]; if (poPhoto.Deleted == false) { return(poPhoto); } else { return(null); } } }
public OrderInfo GetOrderByID(string accessToken, int ID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { Order order = getOrderByID(ID, db); if (order == null) { return(null); } else { return(ConversionUtils.ToOrderInfo(order, db)); } } } catch (Exception ex) { logException(ex); return(null); } }
public int[] GetOrderIDsByDateRange(string accessToken, DateRange range, bool scheduledOnly, bool activeOnly, int maxOrders) { logMethodInvocation(); checkAccessToken(accessToken); try { if (range.Start > range.End) { DateTime temp = range.Start; range.Start = range.End; range.End = temp; } using (CFIEntities db = new CFIEntities()) { var query = from o in db.Orders where ( (o.ScheduleStartDate.Value >= range.Start) && (o.ScheduleStartDate.Value <= range.End) && (!scheduledOnly || o.Scheduled) && (!activeOnly || (!o.Cancelled && !o.Deleted && !o.Billed)) ) orderby o.ScheduleStartDate select o.OrderID; return(query.Take(maxOrders).ToArray <int>()); } } catch (Exception ex) { logException(ex); return(null); } }
public static OrderInfo[] ToOrderInfoArray(IEnumerable <Order> entityOrders, CFIEntities db) { List <OrderInfo> orders = new List <OrderInfo>(); foreach (Order entityOrder in entityOrders) { orders.Add(ToOrderInfo(entityOrder, db)); } return(orders.ToArray()); }
private static UserInfo[] getAllUsersInternal() { using (CFIEntities db = new CFIEntities()) { var query = from employee in db.Employees where employee.Active == true select employee; UserInfo[] users = ConversionUtils.ToUserInfoArray(query.ToList <Employee>()); return(users); } }
public static NoteInfo[] ToNoteInfoArray(PONote[] poNotes, CFIEntities db) { List <NoteInfo> notes = new List <NoteInfo>(); foreach (PONote poNote in poNotes) { if (poNote.Deleted == false) { notes.Add(ToNoteInfo(poNote, db)); } } return(notes.ToArray()); }
public static PhotoInfo[] ToPhotoInfoArray(POPhoto[] poPhotos, CFIEntities db) { List <PhotoInfo> photos = new List <PhotoInfo>(); foreach (POPhoto poPhoto in poPhotos) { if (poPhoto.Deleted == false) { photos.Add(ToPhotoInfo(poPhoto, db)); } } return(photos.ToArray()); }
private static void buildNoteTypeTable(CFIEntities db) { noteTypeTable = new Dictionary <int, string>(); var query = from n in db.NoteTypes select n; foreach (NoteType noteType in query.ToArray <NoteType>()) { noteTypeTable.Add(noteType.ID, noteType.NoteTypeDescription); } }
private string queueDiagramDownloadInternal(string diagramFilename, CFIEntities db) { LogAPI.WebServiceLog.DebugFormat("Queueing diagram file {0} for download", diagramFilename); if (string.IsNullOrEmpty(diagramFilename) == false) { byte[] bytes = getDiagramFile(diagramFilename); // queue file into downloader return(Globals.FileTransferManager.Downloader.QueueFile(bytes)); } else { return(null); } }
public string QueuePhotoDownload(string accessToken, int photoID) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { return(queuePhotoDownloadInternal(photoID, db)); } } catch (Exception ex) { logException(ex); return(null); } }
public string QueueDiagramDownload(string accessToken, string diagramFilename) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { return(queueDiagramDownloadInternal(diagramFilename, db)); } } catch (Exception ex) { logException(ex); return(null); } }
private Order getOrderByID(int orderID, CFIEntities db) { var query = from o in db.Orders where (o.OrderID == orderID) select o; Order[] orders = query.ToArray <Order>(); if (orders.Length == 0) { return(null); } else { return(orders[0]); } }
private POPhoto[] getPOPhotosByOrderID(int orderID, CFIEntities db) { var query = from o in db.Orders where o.OrderID == orderID select o.POPhotos; List <POPhoto> poPhotos = new List <POPhoto>(query.Single <ICollection <POPhoto> >()); if (poPhotos.Count == 0) { return(null); } else { return(poPhotos.ToArray()); } }
private static void buildDivisionTable(CFIEntities db) { divisionTable = new Dictionary <int, string>(); var query = from m in db.MaterialTypes select m; foreach (MaterialType materialType in query.ToArray <MaterialType>()) { string division = materialType.Division.Division1; if (string.IsNullOrEmpty(division) == false) { division = division.Trim(); } divisionTable.Add(materialType.MaterialTypeID, division); } }
private string queuePhotoDownloadInternal(int photoID, CFIEntities db) { var query = from p in db.POPhotos where p.ID == photoID select p; POPhoto poPhoto = query.Single <POPhoto>(); string targetDir = getTargetPhotoDirectory(poPhoto.Order.OrderID); string fullPath = Path.Combine(targetDir, poPhoto.FilePath); if (File.Exists(fullPath) == false) { return(null); } byte[] bytes = File.ReadAllBytes(fullPath); // queue file into downloader return(Globals.FileTransferManager.Downloader.QueueFile(bytes)); }
private static string getSetting(string settingName) { using (CFIEntities db = new CFIEntities()) { var query = from setting in db.Settings where setting.Name == settingName select setting; Setting[] settings = query.ToArray <Setting>(); if (settings.Length == 1) { return(settings[0].Value); } else { return(null); } } }
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 int[] GetOrdersByPONumber(string accessToken, string poNumber, bool scheduledOnly, bool activeOnly, int maxOrders) { logMethodInvocation(); checkAccessToken(accessToken); try { using (CFIEntities db = new CFIEntities()) { var query = from o in db.Orders where (o.PurchaseOrderNumber == poNumber) && (!scheduledOnly || o.Scheduled) && (!activeOnly || (!o.Cancelled && !o.Deleted && !o.Billed)) select o.OrderID; return(query.Take(maxOrders).ToArray <int>()); } } catch (Exception ex) { logException(ex); return(null); } }
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); } }
private static void buildUserIDTable(CFIEntities db) { userIDTable = new Dictionary <int, string>(); var query = from e in db.Employees select e; foreach (Employee employee in query.ToArray <Employee>()) { string fullName; if (string.IsNullOrEmpty(employee.FirstName) == true) { fullName = employee.LastName; } else { fullName = string.Format("{0}, {1}", employee.LastName, employee.FirstName); } userIDTable.Add(employee.ID, fullName); } }
private static string getUserName(int userID, CFIEntities db) { lock (userIDTableDataLock) { // the table can be updated out of band to this application so check for the presence of the ID. If the ID key // is missing then rebuild the table. if ((userIDTable == null) || (userIDTable.ContainsKey(userID) == false)) { buildUserIDTable(db); } try { return(userIDTable[userID]); } catch { LogAPI.WebServiceLog.ErrorFormat("Unexpected UserID {0} encountered during User Name lookup", userID); return("UNKNOWN user ID"); } } }
private static string getNoteTypeDescription(int noteTypeID, CFIEntities db) { lock (noteTypeTableDataLock) { // the table can be updated out of band to this application so check for the presence of the ID. If the ID key // is missing then rebuild the table. if ((noteTypeTable == null) || (noteTypeTable.ContainsKey(noteTypeID) == false)) { buildNoteTypeTable(db); } try { return(noteTypeTable[noteTypeID]); } catch { LogAPI.WebServiceLog.ErrorFormat("Unexpected noteTypeID {0} encountered during noteType lookup", noteTypeID); return("UNKNOWN Note Type"); } } }
private static string getDivision(int materialID, CFIEntities db) { lock (divisionTableDataLock) { // the table can be updated out of band to this application so check for the presence of the ID. If the ID key // is missing then rebuild the table. if ((divisionTable == null) || (divisionTable.ContainsKey(materialID) == false)) { buildDivisionTable(db); } try { return(divisionTable[materialID]); } catch { LogAPI.WebServiceLog.ErrorFormat("Unexpected MaterialID {0} encountered during Division lookup", materialID); return("UNKNOWN DIVISION"); } } }
public static PhotoInfo ToPhotoInfo(POPhoto poPhoto, CFIEntities db) { PhotoInfo photo = new PhotoInfo(); photo.ID = poPhoto.ID; photo.FilePath = poPhoto.FilePath; photo.DateTimeEntered = poPhoto.DateTimeEntered; photo.Title = poPhoto.Title; if (poPhoto.EnteredByUserID != null) { photo.EnteredByUserID = poPhoto.EnteredByUserID.Value; photo.EnteredByUser = getUserName(poPhoto.EnteredByUserID.Value, db); } else { photo.EnteredByUserID = -1; photo.EnteredByUser = null; } return(photo); }