/// <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); }