/// <summary> /// Applying submit request /// </summary> /// <param name="pageRouteVersion">page route version model</param> /// <param name="userId">logged in user</param> /// <param name="urlParent">parent route version url</param> /// <param name="urlSection">section url</param> /// <returns>true if applying false otherwise</returns> public bool ApplySubmitRequest(PageRouteVersion pageRouteVersion, string userId, string urlParent, string urlSection) { var existPageRouteVer = _db.PageRouteVersions.FirstOrDefault(x => x.Id == pageRouteVersion.Id); //existPageRouteVer.VersionStatusEnum = VersionStatusEnum.Submitted; existPageRouteVer.VersionStatusEnum = VersionStatusEnum.Submitted; var existingNotifications = _db.ApprovalNotifications.Where(d => d.RelatedVersionId == pageRouteVersion.Id && d.RelatedPageEnum == RelatedPageEnum.PageRouteVersion && d.VersionStatusEnum == VersionStatusEnum.Submitted).ToList(); ///check if no notification added for the basic info then add new one if ((pageRouteVersion.PageRouteId == null && !existingNotifications.Any(d => d.ChangeType == ChangeType.BasicInfo))) { ApprovalNotification approval = new ApprovalNotification() { ChangeAction = pageRouteVersion.ChangeActionEnum ?? ChangeActionEnum.New, VersionStatusEnum = VersionStatusEnum.Submitted, ChangesDateTime = DateTime.Now, ChangeType = ChangeType.BasicInfo, PageLink = $"/{urlParent}/{pageRouteVersion.Id}", PageName = pageRouteVersion.EnName, PageType = PageType.Dynamic, ContentManagerId = userId, RelatedVersionId = pageRouteVersion.Id, RelatedPageEnum = RelatedPageEnum.PageRouteVersion }; _approvalNotificationsRepository.Add(approval); } if (!existingNotifications.Any(d => d.ChangeType == ChangeType.PageContent) || pageRouteVersion.ContentVersionStatusEnum == VersionStatusEnum.Draft) { existPageRouteVer.ContentVersionStatusEnum = VersionStatusEnum.Submitted; ApprovalNotification approvalSections = new ApprovalNotification() { ChangeAction = ChangeActionEnum.Update, VersionStatusEnum = VersionStatusEnum.Submitted, ChangesDateTime = DateTime.Now, ChangeType = ChangeType.PageContent, PageLink = $"/{urlSection}?pageRouteVersionId={pageRouteVersion.Id}", PageName = pageRouteVersion.EnName, PageType = PageType.Dynamic, ContentManagerId = userId, RelatedVersionId = pageRouteVersion.Id, RelatedPageEnum = RelatedPageEnum.PageRouteVersion }; _approvalNotificationsRepository.Add(approvalSections); } _db.PageRouteVersions.Attach(existPageRouteVer); _db.Entry(existPageRouteVer).State = EntityState.Modified; _db.SaveChanges(); return(true); }
public static ApprovalNotificationsViewModel MapToApprovalNotificationsViewModel(this ApprovalNotification model) { ApprovalNotificationsViewModel viewModel = new ApprovalNotificationsViewModel() { Id = model.Id, ContentManagerName = model.ContentManager.UserName, ChangesDate = getDate(model.ChangesDateTime), ChangesTime = getTime(model.ChangesDateTime), ChangeAction = model.ChangeAction.ToString(), ChangeType = model.ChangeType.ToString(), PageLink = model.PageLink, PageName = model.PageName, PageType = model.PageType.ToString(), VersionStatusEnum = model.VersionStatusEnum.ToString() }; return(viewModel); }
/// <summary> /// Update a notification by new notification model /// </summary> /// <param name="approvalNotification">Approval notification model</param> /// <returns>return a single notification</returns> public void Update(ApprovalNotification approvalNotification) { _db.ApprovalNotifications.Update(approvalNotification); _db.SaveChanges(); }
/// <summary> /// Add new notification to approval user /// </summary> /// <param name="model">Approval notification model</param> /// <returns>return a single notification</returns> public void Add(ApprovalNotification model) { _db.ApprovalNotifications.Add(model); _db.SaveChanges(); }