Esempio n. 1
0
        /// <summary>
        /// Handles the Click event of the btnSubmit 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 btnSubmit_Click(object sender, EventArgs e)
        {
            if (!StopProcessing)
            {
                if (!IsValid)
                {
                    return;
                }

                ucCompanyDetails.SaveCompanyDetails(true);

                if (CompanyId == 0)
                {
                    CompanyId = ucCompanyDetails.Company.CompanyId;
                    //Add media content.
                    DocumentMedia media = CompanyHeaderDetails.GetMedia();

                    if (media != null)
                    {
                        media.RelatedId = CompanyId;
                        DataContext.SaveChanges();
                    }

                    //Notification email to StageBitzAdmins.Get the [email protected]
                    StageBitz.Common.EmailSender.SendCompanyRegistrationMailToStageBitzAdmin(Support.GetSystemValue("AdminEmail"),
                                                                                             Support.GetAdminPortalCompanyDetailsLink(CompanyId), ucCompanyDetails.Company.CompanyName, Support.UserFullName);
                }
                Response.Redirect(string.Format("~/Company/CompanyDashboard.aspx?CompanyId={0}", CompanyId));
            }
        }
Esempio n. 2
0
 /// <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();
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// This will populate the server controls and show the image preview popup.
        /// </summary>
        protected void btnDocumentPreviewLaunch_Click(object sender, EventArgs e)
        {
            if (!PageBase.StopProcessing)
            {
                //This hidden field contains the value populated from the client side.
                int documentMediaId = 0;
                int.TryParse(hdnDocumentMediaId.Value, out documentMediaId);

                if (documentMediaId > 0)
                {
                    DocumentMedia media = GetBL <UtilityBL>().GetDocumentMedia(documentMediaId);

                    if (media != null && Support.CanAccessMedia(media, DataContext))
                    {
                        DocumentMediaId = documentMediaId;

                        var itemBriefItemDocumentMedia = DataContext.ItemBriefItemDocumentMedias.Where(ibi => ibi.ItemBriefDocumentMediaId == DocumentMediaId).FirstOrDefault();

                        imgPreview.Src   = ResolveUrl(Support.GetImageFilePreviewUrl(documentMediaId, PREVIEW_SIZE));
                        lnkDownload.HRef = ResolveUrl(Support.GetImageFileDownloadUrl(documentMediaId));

                        txtName.Text = media.Name;
                        string fileType = "image";
                        if (ImageHelper.IsImageFileType(media.FileExtension))
                        {
                            lblDocumentExtension.Visible = false;
                            popupDocumentPreview.Title   = "Preview Image";
                            lnkDownload.Title            = "Download full size image";
                            popupDocumentPreviewRemoveConfirmation.Title = "Remove Image";
                            documentLabelWatermark.WatermarkText         = "Click to set image label";
                        }
                        else
                        {
                            lblDocumentExtension.Visible = true;
                            lblDocumentExtension.Text    = media.FileExtension;
                            popupDocumentPreview.Title   = "File Properties";
                            lnkDownload.Title            = "Download File";
                            fileType = "file";
                            popupDocumentPreviewRemoveConfirmation.Title = "Remove File";
                            documentLabelWatermark.WatermarkText         = "Click to set file label";
                        }
                        if (itemBriefItemDocumentMedia != null)
                        {
                            ltrlRemoveConfirmText.Text = string.Format("Deleting this {0} will also remove it from the Complete Item tab. <br /> Are you sure you want to remove this {0}?", fileType);
                        }
                        else
                        {
                            ltrlRemoveConfirmText.Text = string.Format("Are you sure you want to remove this {0}?", fileType);
                        }

                        popupDocumentPreview.ShowPopup();
                    }
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Updates the hyperlink document media.
 /// </summary>
 /// <param name="media">The media.</param>
 /// <param name="name">The name.</param>
 /// <param name="url">The URL.</param>
 /// <param name="lastUpdatedBy">The last updated by.</param>
 /// <param name="lastUpdatedDate">The last updated date.</param>
 public void UpdateHyperlinkDocumentMedia(DocumentMedia media, string name, string url, int lastUpdatedBy, DateTime lastUpdatedDate)
 {
     if (media != null)
     {
         media.Name            = name;
         media.Description     = url;
         media.LastUpdatedBy   = lastUpdatedBy;
         media.LastUpdatedDate = lastUpdatedDate;
         DataContext.SaveChanges();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Handles the Click event of the btnRemoveConfirm 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 btnRemoveConfirm_Click(object sender, EventArgs e)
        {
            //logic to remove link
            UtilityBL     utilityBL = new UtilityBL(DataContext);
            DocumentMedia media     = utilityBL.RemoveHyperlinkDocumentMedia(DocumentMediaId);

            if (media != null && (RelatedTableName == "Project" || RelatedTableName == "ItemBrief"))
            {
                this.GetBL <NotificationBL>().GenerateNotificationsForMedia(media, UserID, ProjectId, NotificationBL.OperationMode.Delete);
            }

            UpdateParent();
            popupAttachLinks.HidePopup();
            popupLinkRemoveConfirmation.HidePopup();
        }
Esempio n. 6
0
        /// <summary>
        /// Inserts the hyperlink to document media.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="RelatedTableName">Name of the related table.</param>
        /// <param name="RelatedId">The related identifier.</param>
        /// <param name="url">The URL.</param>
        /// <param name="createdBy">The created by.</param>
        /// <param name="createdDate">The created date.</param>
        /// <returns></returns>
        public DocumentMedia InsertHyperlinkToDocumentMedia(string name, string RelatedTableName, int RelatedId, string url, int createdBy, DateTime createdDate)
        {
            DocumentMedia media = new DocumentMedia();

            media.Name             = string.IsNullOrEmpty(name) ? null : name;
            media.RelatedTableName = RelatedTableName;
            media.RelatedId        = RelatedId;
            media.FileExtension    = "Hyperlink";
            media.CreatedBy        = media.LastUpdatedBy = createdBy;
            media.CreatedDate      = media.LastUpdatedDate = createdDate;
            media.Description      = url;
            DataContext.DocumentMedias.AddObject(media);
            DataContext.SaveChanges();
            return(media);
        }
Esempio n. 7
0
        /// <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();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Sets the media sort order.
        /// </summary>
        /// <param name="media">The media.</param>
        private void SetMediaSortOrder(DocumentMedia media)
        {
            if (media.IsImageFile)
            {
                //Check if this item brief already has images.
                //If not set the sort order of the new image to 1.
                int existingImageCount = (from m in DataContext.DocumentMedias
                                          where m.RelatedTableName == RelatedTableName && m.RelatedId == RelatedId && m.IsImageFile == true
                                          select m).Count();

                if (existingImageCount == 0)
                {
                    //This image will be the default image.
                    media.SortOrder = 1;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the content for edit hyperlink.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <param name="newName">The new name.</param>
        /// <param name="newURL">The new URL.</param>
        /// <returns>The notification text for edit hyperlink.</returns>
        private string GetContentForEditHyperlink(DocumentMedia media, string newName, string newURL)
        {
            string editLinkText  = "Hyperlink url '{0}'";
            string editLabelText = "Hyperlink label {0}";
            string editBoth      = "Hyprlink url '{0}' and label {1}";

            if (media.Name != newName && media.Description != newURL)
            {
                return(string.Format(editBoth, newURL, newName != string.Empty ? string.Concat("'", newName, "'") : newName));
            }
            else if (media.Name != newName)
            {
                return(string.Format(editLabelText, newName != string.Empty ? string.Concat("'", newName, "'") : newName));
            }
            else
            {
                return(string.Format(editLinkText, newURL));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Handles the FileUploaded event of the radUploader control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="FileUploadedEventArgs"/> instance containing the event data.</param>
        protected void radUploader_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            if (!PageBase.StopProcessing)
            {
                //This event will be fired for any postback from the page after the file have been asynchronosly uploaded.
                //So we should verify whether we should accept files, using a hidden field value which is set only for OK button click.

                //Only OK button will set the hidden field value to '1' from client side
                if (hdnAcceptStatus.Value == "1" && e.IsValid)
                {
                    //Reset the accept status value.
                    hdnAcceptStatus.Value = string.Empty;

                    DocumentMedia media = new DocumentMedia();

                    //File extension
                    string extension = e.File.GetExtension();
                    if (extension.Length > 0 && extension[0] == '.')
                    {
                        extension = (extension.Length > 1) ? extension.Substring(1, extension.Length - 1) : string.Empty;
                    }

                    media.IsImageFile = ImageHelper.IsImageFileType(extension);

                    switch (RelatedTableName)
                    {
                    case "ItemBrief":
                        SetMediaSortOrder(media);
                        break;

                    case "Item":
                        if (this.GetBL <InventoryBL>().IsItemDeleted(RelatedId))
                        {
                            int companyId = (int)this.GetBL <InventoryBL>().GetItem(RelatedId).CompanyId;
                            popupItemDeletedWarning.ShowItemDeleteMessagePopup(RelatedId, companyId);
                            return;
                        }

                        SetMediaSortOrder(media);
                        break;

                    case "User":
                    case "Company":
                        //User and Company can only have images via AllowedFileExtensions.
                        //But we are performing the isImageFile check just to be safe.
                        if (media.IsImageFile)
                        {
                            //Check for existing images and delete them.
                            //(Only one image can exist)
                            int[] documentMediaIds = (from m in DataContext.DocumentMedias
                                                      where m.RelatedTableName == RelatedTableName && m.RelatedId == RelatedId
                                                      select m.DocumentMediaId).ToArray();

                            foreach (int mediaId in documentMediaIds)
                            {
                                DataContext.DeleteDocumentMedia(mediaId);
                            }

                            //Set the uploaded image as the default profile image
                            media.SortOrder = 1;
                        }
                        break;

                    default:
                        break;
                    }

                    media.RelatedTableName = RelatedTableName;
                    media.RelatedId        = RelatedId;
                    media.FileExtension    = extension;
                    media.CreatedBy        = media.LastUpdatedBy = UserID;
                    media.CreatedDate      = media.LastUpdatedDate = Now;

                    if (RelatedTableName == "ItemBrief" || RelatedTableName == "Item" || RelatedTableName == "Project")
                    {
                        string label = txtName.Text.Trim();
                        if (label.Length > 0)
                        {
                            media.Name = label;
                        }
                    }

                    if (media.IsImageFile)
                    {
                        //Set image contents
                        media.DocumentMediaContent = ImageHelper.GetResizedImage(e.File.InputStream, false, extension);
                        media.Thumbnail            = ImageHelper.GetResizedImage(e.File.InputStream, true, extension);
                    }
                    else
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            e.File.InputStream.CopyTo(memoryStream);
                            media.DocumentMediaContent = memoryStream.ToArray();
                            media.Thumbnail            = null;
                        }
                    }

                    DataContext.DocumentMedias.AddObject(media);
                    DataContext.SaveChanges();
                    DocumentMediaId = media.DocumentMediaId;

                    //Geneate notifications for projcts and item briefs. If u need notifications for different types, add them here.
                    if (RelatedTableName == "Project" || RelatedTableName == "ItemBrief")
                    {
                        this.GetBL <NotificationBL>().GenerateNotificationsForMedia(media, UserID, ProjectId, NotificationBL.OperationMode.Add);
                    }

                    //Make a Copy to the Item if available. This needs to be done at the end
                    if (RelatedTableName == "ItemBrief" && GetBL <InventoryBL>().CanEditIteminItemBrief(RelatedId))
                    {
                        ItemBooking ItemBooking = this.GetBL <InventoryBL>().GetInUseOrCompleteItemBooking(RelatedId);
                        if (ItemBooking != null && this.GetBL <InventoryBL>().CanEditIteminItemBrief(RelatedId, ItemBooking.ItemId))
                        {
                            //Since we are going to generate an Item file, we need to pass "Item" as the Releted table. Only if it is being "INUSECOMPLETE,INUSE" state.
                            DataContext.CopyMediaFiles(DocumentMediaId, "Item", ItemBooking.ItemId, UserID);
                        }
                    }

                    //Fire the file uploaded event
                    if (FileUploaded != null)
                    {
                        FileUploaded(this, EventArgs.Empty);
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Loads the file data specified by the 'documentMediaId' and sends it to the browser.
        /// </summary>
        private void SendMediaFromDB()
        {
            try
            {
                DocumentMedia media = GetBL <UtilityBL>().GetDocumentMedia(DocumentMediaId);
                if (Support.CanAccessMedia(media, DataContext))
                {
                    //If a media name has not been specified, use the media ID as the file name.
                    string fileName = (media.Name == null) ? media.DocumentMediaId.ToString() : media.Name;
                    fileName = fileName.Replace("\"", string.Empty);

                    if (media.IsImageFile)
                    {
                        byte[] bytes = null;

                        #region Get image bytes

                        //If a specific size has not been specified, get the thumbnail or full content.
                        //Otherwise send the resized image.
                        if (Size == 0)
                        {
                            bytes = IsThumbnail ? media.Thumbnail : media.DocumentMediaContent;
                        }
                        else
                        {
                            using (MemoryStream ms = new MemoryStream(media.DocumentMediaContent))
                            {
                                bytes = ImageHelper.GetResizedImage(ms, Size, ImageHelper.GetImageFormat(media.FileExtension));
                            }
                        }

                        #endregion Get image bytes

                        if (bytes != null)
                        {
                            using (MemoryStream ms = new MemoryStream(bytes))
                                using (Image image = Image.FromStream(ms))
                                {
                                    WriteImageResponse(image, fileName, media.FileExtension);
                                    return;
                                }
                        }
                    }
                    else
                    {
                        if (IsDownload)
                        {
                            WriteBinaryResponse(media.DocumentMediaContent, fileName, media.FileExtension);
                            return;
                        }
                        else
                        {
                            using (Image image = Image.FromFile(GetDocumentIconUrl(media.FileExtension)))
                            {
                                WriteImageResponse(image, "icon", "png");
                                return;
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            //If any error occurs, or permission is denied, send the palceholder image to the browser.
            using (Image image = Image.FromFile(Server.MapPath(placeholderThumbUrl)))
            {
                WriteImageResponse(image, "noimage", "png");
                return;
            }
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        /// <summary>
        /// Generates the notifications for media.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <param name="userID">The user ID.</param>
        /// <param name="projectId">The project id.</param>
        /// <param name="operationMode">The operation mode.</param>
        /// <param name="newName">The new name.</param>
        /// <param name="newURL">The new URL.</param>
        public void GenerateNotificationsForMedia(DocumentMedia media, int userID, int projectId, OperationMode operationMode, string newName = "", string newURL = "")
        {
            string     hyperlinkExtension = "Hyperlink";
            PersonalBL personalBL         = new PersonalBL(DataContext);
            User       user     = personalBL.GetUser(userID);
            string     userName = string.Concat(user.FirstName + " " + user.LastName).Trim();

            StageBitz.Data.Notification nf = new StageBitz.Data.Notification();
            nf.CreatedByUserId = nf.LastUpdatedByUserId = userID;
            nf.CreatedDate     = nf.LastUpdatedDate = Utils.Now;
            nf.RelatedId       = media.RelatedId;
            nf.ProjectId       = projectId;

            string message  = string.Empty;
            string fileName = string.Empty;

            if (media.FileExtension.ToUpper() != hyperlinkExtension.ToUpper())
            {
                if (operationMode == OperationMode.Edit)
                {
                    fileName = string.Format("file '{0}'", string.Concat(newName, ".", media.FileExtension != null ? media.FileExtension : string.Empty));
                }
                else
                {
                    fileName = string.Format("file '{0}'", string.Concat(media.Name, ".", media.FileExtension != null ? media.FileExtension : string.Empty));
                }
            }
            else
            {
                if (operationMode == OperationMode.Edit)
                {
                    fileName = this.GetContentForEditHyperlink(media, newName, newURL);
                }
                else
                {
                    fileName = string.Format("Hyperlink '{0}'", (media.Name != null && media.Name != string.Empty) ? media.Name : media.Description);
                }
            }

            switch (operationMode)
            {
            case OperationMode.Add:
                message = "{0} added the {1}.";
                nf.OperationTypeCodeId = Utils.GetCodeIdByCodeValue("OperationType", "ADD");
                break;

            case OperationMode.Edit:
                message = "{0} edited the {1}.";
                nf.OperationTypeCodeId = Utils.GetCodeIdByCodeValue("OperationType", "EDIT");
                break;

            case OperationMode.Delete:
                message = "{0} deleted the {1}.";
                nf.OperationTypeCodeId = Utils.GetCodeIdByCodeValue("OperationType", "DELETE");
                break;
            }

            // Set module type/ops type based on the related table.
            switch (media.RelatedTableName)
            {
            case "Project":
                nf.ModuleTypeCodeId = Utils.GetCodeIdByCodeValue("ModuleType", "PROJECT");
                break;

            case "ItemBrief":
                nf.ModuleTypeCodeId = Utils.GetCodeIdByCodeValue("ModuleType", "ITEMBRIEFMEDIA");
                break;
            }

            nf.Message = string.Format(message, userName, fileName);
            this.AddNotification(nf);
        }