public Notification TryGenerateNotification <T>(ncelsEntities dbContext, NotificationTypeKey notificationTypeKey, T sourceObject) where T : class
        {
            var contractRemarkDoc = sourceObject as Document;

            if (contractRemarkDoc == null)
            {
                return(null);
            }
            Guid contractDocId;

            if (contractRemarkDoc.DocumentType == 4 && contractRemarkDoc.StateType == 9 &&
                Guid.TryParse(contractRemarkDoc.AnswersId, out contractDocId))
            {
                var query = from d in dbContext.Documents
                            join c in dbContext.Contracts on d.Id equals c.Id
                            where c.Id == contractDocId
                            select d;
                if (!query.Any())
                {
                    return(null);
                }
                var contractDoc =
                    dbContext.Documents.FirstOrDefault(e => e.Id == contractDocId);
                if (string.IsNullOrEmpty(contractDoc.CorrespondentsId))
                {
                    return(null);
                }

                var  ids = contractDoc.CorrespondentsId.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                Guid correspondentId;
                if (ids.Length > 0 && Guid.TryParse(ids[0], out correspondentId))
                {
                    var correspondentEmail =
                        dbContext.Employees.Where(e => e.Id == correspondentId).Select(e => e.Email).FirstOrDefault();
                    return(new Notification()
                    {
                        CreatedDate = DateTime.Now,
                        ModifiedDate = DateTime.Now,
                        EmployeesId = correspondentId.ToString(),
                        TableName = notificationTypeKey.ObjectType.GetDescription(),
                        ObjectId = contractDocId.ToString(),
                        Email = correspondentEmail,
                        Note = "Ваш договор отклонен с замечанием от юрисконсульта ЦОЗ",
                        StateType = contractDoc.StateType,
                        ModifiedUser = UserHelper.GetCurrentEmployee().DisplayName
                    });
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public Notification TryGenerateNotification <T>(ncelsEntities dbContext, NotificationTypeKey notificationTypeKey, T sourceObject) where T : class
        {
            var contract = sourceObject as Contract;

            return(new Notification()
            {
                CreatedDate = DateTime.Now,
                ModifiedDate = DateTime.Now,
                EmployeesId = Guid.NewGuid().ToString(),
                ObjectId = contract.Id.ToString(),
                TableName = notificationTypeKey.ObjectType.GetDescription(),
                Note = "testNotification"
            });
        }
        public Notification TryGenerateNotification <T>(ncelsEntities dbContext, NotificationTypeKey notificationTypeKey, T sourceObject) where T : class
        {
            var priceAppComment = sourceObject as Document;

            if (priceAppComment == null)
            {
                return(null);
            }
            Guid priceAppDocId;

            if (priceAppComment.DocumentType == 1 &&
                Guid.TryParse(priceAppComment.AnswersId, out priceAppDocId))
            {
                var query = from d in dbContext.Documents
                            join c in dbContext.PriceProjects on d.Id equals c.Id
                            where c.Id == priceAppDocId
                            select d;
                if (!query.Any())
                {
                    return(null);
                }
                var priceDoc = dbContext.Documents.FirstOrDefault(e => e.Id == priceAppDocId);
                if (string.IsNullOrEmpty(priceDoc.CorrespondentsId))
                {
                    return(null);
                }

                var  ids = priceDoc.CorrespondentsId.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                Guid correspondentId;
                if (ids.Length > 0 && Guid.TryParse(ids[0], out correspondentId))
                {
                    var correspondentEmail =
                        dbContext.Employees.Where(e => e.Id == correspondentId).Select(e => e.Email).FirstOrDefault();
                    return(new Notification()
                    {
                        CreatedDate = DateTime.Now,
                        ModifiedDate = DateTime.Now,
                        EmployeesId = correspondentId.ToString(),
                        TableName = notificationTypeKey.ObjectType.GetDescription(),
                        ObjectId = priceAppDocId.ToString(),
                        Email = correspondentEmail,
                        Note = string.Format("Имеется замечание на заявку №{0}", priceDoc.Number),
                        StateType = priceDoc.StateType,
                        ModifiedUser = UserHelper.GetCurrentEmployee().DisplayName
                    });
                }
            }
            return(null);
        }