/// <summary> /// Loads the UI. /// </summary> private void LoadUI() { InitializeUI(); if (this.DisplayMode == LinkDisplayMode.Add) { popupAttachLinks.Title = "Add new Hyperlink"; btnOK.Text = "Ok"; imgbtnRemoveLink.Visible = false; txtHyperlink.Text = ""; txtName.Text = ""; cancelButton.Visible = true; } else { cancelButton.Visible = false; btnOK.Text = "Done"; popupAttachLinks.Title = "Edit/ Delete Hyperlink"; imgbtnRemoveLink.Visible = true; UtilityBL utilityBL = new UtilityBL(DataContext); DocumentMedia media = utilityBL.GetDocumentMedia(DocumentMediaId); if (media != null) { txtHyperlink.Text = media.Description; txtName.Text = media.Name; } else { linkAlreadyDeleted.ShowPopup(); } } }
public MobileImageDetails GetImageDetailsForItem(MobileItemImageRequestDetails mobileItemImageRequestDetails) { string message = string.Empty; string status = string.Empty; bool isValidVersion = true; MobileImageDetails mobileImageDetails = new MobileImageDetails(); try { using (StageBitzDB dataContext = new StageBitzDB()) { isValidVersion = Helper.IsValidAppVersion(mobileItemImageRequestDetails.Version, out status); if (isValidVersion) { //Check the user security int userId = int.Parse(Utils.DecryptStringAES(mobileItemImageRequestDetails.Token)); if (Utils.CanAccessInventory(mobileItemImageRequestDetails.CompanyId, userId)) { UtilityBL utilityBL = new UtilityBL(dataContext); var dm = utilityBL.GetDocumentMedia(mobileItemImageRequestDetails.DocumentMediaId); if (dm != null) { mobileImageDetails.DocumentMediaId = dm.DocumentMediaId; mobileImageDetails.Image = Convert.ToBase64String(dm.Thumbnail); mobileImageDetails.Status = "OK"; } else { mobileImageDetails.Status = "ERROR"; mobileImageDetails.Message = "Oops! Unkown error. Sorry..."; } } else { mobileImageDetails.Status = "NOTOK"; mobileImageDetails.Message = "Check settings with Company Administrator."; } } else { mobileImageDetails.Status = "NOTOK"; mobileImageDetails.Message = "Please update App."; } } } catch (Exception ex) { AgentErrorLog.HandleException(ex); mobileImageDetails.Status = "ERROR"; mobileImageDetails.Message = "Oops! Unkown error. Sorry..."; } return(mobileImageDetails); }
/// <summary> /// Saves the document media. /// </summary> /// <param name="filePrefix">The file prefix.</param> /// <param name="documentMediaId">The document media identifier.</param> /// <param name="attachmentPath">The attachment path.</param> /// <returns></returns> private async Task SaveDocumentMedia(string filePrefix, int documentMediaId, string attachmentPath) { using (StageBitzDB dataContext = new StageBitzDB()) { UtilityBL utilityBL = new UtilityBL(dataContext); Data.DocumentMedia documentMedia = utilityBL.GetDocumentMedia(documentMediaId); if (documentMedia != null) { string documentMediaFileName = string.Format("{0} {1} - {2}.{3}", filePrefix, documentMedia.DocumentMediaId, Utils.Ellipsize(documentMedia.Name, 50), documentMedia.FileExtension); await FileHandler.SaveFileToDisk(documentMedia.DocumentMediaContent, FileHandler.GetSafeFileName(documentMediaFileName), attachmentPath); } } }
/// <summary> /// Handles the Click event of the btnOK control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnOK_Click(object sender, EventArgs e)//If you are generting notifications, you should genetate them based on RelatedTableName { if (Page.IsValid) { string name = txtName.Text; UriBuilder uriBuilder = new UriBuilder(txtHyperlink.Text); string url = new UriBuilder(txtHyperlink.Text).Uri.AbsoluteUri; //if the uploaded url is an url to a file we change the url format to UNC if (uriBuilder.Uri.Scheme.Equals("file")) { url = url.Insert(5, "///"); } UtilityBL utilityBL = new UtilityBL(DataContext); if (DisplayMode == LinkDisplayMode.Add) { int createdBy = UserID; DocumentMedia media = utilityBL.InsertHyperlinkToDocumentMedia(name, RelatedTableName, RelatedId, url, createdBy, Utils.Today); if (media != null && (RelatedTableName == "Project" || RelatedTableName == "ItemBrief")) { this.GetBL <NotificationBL>().GenerateNotificationsForMedia(media, UserID, ProjectId, NotificationBL.OperationMode.Add); } UpdateParent(); } else { int lastUpdatedBy = UserID; DateTime lastUpdatedDate = DateTime.Now; DocumentMedia media = utilityBL.GetDocumentMedia(DocumentMediaId); if (media == null) { linkAlreadyDeleted.ShowPopup(); } else { if ((media.Name != name || media.Description != url) && (RelatedTableName == "Project" || RelatedTableName == "ItemBrief")) { this.GetBL <NotificationBL>().GenerateNotificationsForMedia(media, UserID, ProjectId, NotificationBL.OperationMode.Edit, name, url); } utilityBL.UpdateHyperlinkDocumentMedia(media, name, url, lastUpdatedBy, lastUpdatedDate); UpdateParent(); } } popupAttachLinks.HidePopup(); } }
public ItemResult SyncImage(MobileDocumentMedia mobileDocumentMedia) { ItemResult itemResult = new ItemResult(); string message = string.Empty; string status = string.Empty; bool isValidVersion = true; int documentMediaId = 0; try { using (StageBitzDB dataContext = new StageBitzDB()) { if (mobileDocumentMedia != null) { isValidVersion = Helper.IsValidAppVersion(mobileDocumentMedia.Version, out status); if (isValidVersion) { if (mobileDocumentMedia != null) { //Check if the Item is already being synced if (dataContext.InventoryMobileDocumentMedias.Where(imdm => imdm.MobileDocumentMediaId == mobileDocumentMedia.MobileImageId && imdm.RelatedTable == mobileDocumentMedia.RelatedTable && imdm.RelatedId == mobileDocumentMedia.RelatedId).FirstOrDefault() == null) { //Check if the Item is exist Data.Item item = dataContext.Items.Where(i => i.ItemId == mobileDocumentMedia.RelatedId).FirstOrDefault(); if (item != null && item.IsActive) { int userId = int.Parse(Utils.DecryptStringAES(mobileDocumentMedia.Token)); InventoryBL inventoryBL = new InventoryBL(dataContext); if (!inventoryBL.GetItemStatusInformationForUser(item, mobileDocumentMedia.CompanyId, userId).IsReadOnly) { //Images can be either deleted or added. if (mobileDocumentMedia.DocumentMediaId == 0) { DocumentMedia documentMedia = new DocumentMedia(); documentMedia.DocumentMediaContent = Helper.LoadImage(mobileDocumentMedia.Image, false, mobileDocumentMedia.FileExtension); documentMedia.Thumbnail = Helper.LoadImage(mobileDocumentMedia.Image, true, mobileDocumentMedia.FileExtension); documentMedia.RelatedId = mobileDocumentMedia.RelatedId; documentMedia.RelatedTableName = mobileDocumentMedia.RelatedTable; documentMedia.SortOrder = inventoryBL.HasDefaultImageSet(mobileDocumentMedia.RelatedId, mobileDocumentMedia.RelatedTable) ? 0 : 1; documentMedia.IsImageFile = true; documentMedia.FileExtension = mobileDocumentMedia.FileExtension; documentMedia.Name = mobileDocumentMedia.Name; documentMedia.CreatedBy = documentMedia.LastUpdatedBy = userId; documentMedia.CreatedDate = documentMedia.LastUpdatedDate = Utils.Today; dataContext.DocumentMedias.AddObject(documentMedia); InventoryMobileDocumentMedia inventoryMobileDocumentMedia = new InventoryMobileDocumentMedia(); inventoryMobileDocumentMedia.MobileDocumentMediaId = mobileDocumentMedia.MobileImageId; inventoryMobileDocumentMedia.DocumentMediaId = documentMedia.DocumentMediaId; inventoryMobileDocumentMedia.RelatedTable = mobileDocumentMedia.RelatedTable; inventoryMobileDocumentMedia.RelatedId = mobileDocumentMedia.RelatedId; inventoryMobileDocumentMedia.CreatedBy = userId; inventoryMobileDocumentMedia.CreatedDate = inventoryMobileDocumentMedia.LastUpdateDate = Utils.Today; dataContext.InventoryMobileDocumentMedias.AddObject(inventoryMobileDocumentMedia); dataContext.SaveChanges(); status = "OK"; documentMediaId = documentMedia.DocumentMediaId; } else { UtilityBL utilityBL = new UtilityBL(dataContext); DocumentMedia documentMedia = utilityBL.GetDocumentMedia(mobileDocumentMedia.DocumentMediaId); if (documentMedia != null) { dataContext.DeleteDocumentMedia(mobileDocumentMedia.DocumentMediaId); status = "OK"; } else { status = "OK"; message = "Image no longer exists."; } } } else { status = "NORIGHTS"; message = "Check settings with Company Administrator."; } } else { status = "ITEMDELETED"; message = "Item no longer exists."; } } else { status = "EXIST"; message = "Image already synced."; } } } else { status = "INVALIDAPP"; message = "Please update App."; } } else { status = "ERROR"; message = "Oops! Unkown error. Sorry..."; } } } catch (Exception ex) { AgentErrorLog.HandleException(ex); status = "ERROR"; message = "Oops! Unkown error. Sorry..."; } itemResult.Id = documentMediaId; itemResult.MobileId = mobileDocumentMedia != null ? mobileDocumentMedia.MobileImageId : "0"; itemResult.Status = status; itemResult.Message = message; return(itemResult); }