示例#1
0
        public ProjectChangeLog AddChangeLog(ProjectChangeLog log)
        {
            log.Id         = Guid.NewGuid().ToString();
            log.CreateTime = DateTime.Now;

            ProjectChangeLogs.Add(log);
            SaveChanges();

            UpdateLatestNews(log);

            return(log);
        }
示例#2
0
        private void UpdateLatestNews(ProjectChangeLog log)
        {
            ProjectActionType actionType = (ProjectActionType)log.ActionType;

            if (actionType != ProjectActionType.Delete)
            {
                var latestNews = log.CreateTime.ToString("yyyy-MM-dd HH:mm") + " " + log.UserName + log.ActionTypeString;
                latestNews = string.IsNullOrWhiteSpace(log.Message) ? latestNews : latestNews + "," + log.Message;

                switch (actionType)
                {
                case ProjectActionType.EditBudget:
                case ProjectActionType.AddExpenditure:
                case ProjectActionType.DeleteExpenditure:
                    DbContext.Database.ExecuteSqlCommand("Update Projects Set FinanceLatestNews = @p0 Where Id = @p1",
                                                         new SqlParameter {
                        ParameterName = "p0", Value = latestNews
                    },
                                                         new SqlParameter {
                        ParameterName = "p1", Value = log.ProjectId
                    });
                    DbContext.Database.ExecuteSqlCommand("Update ProjectViewStatuses Set FinanceStatus = FinanceStatus + 1, UpdateTime = GETDATE() Where ProjectId = @p0 And UserId <> @p1",
                                                         new SqlParameter {
                        ParameterName = "p0", Value = log.ProjectId
                    },
                                                         new SqlParameter {
                        ParameterName = "p1", Value = log.UserId
                    });
                    break;

                default:
                    DbContext.Database.ExecuteSqlCommand("Update Projects Set LatestNews = @p0, FinanceLatestNews = '' Where Id = @p1",
                                                         new SqlParameter {
                        ParameterName = "p0", Value = latestNews
                    },
                                                         new SqlParameter {
                        ParameterName = "p1", Value = log.ProjectId
                    });

                    DbContext.Database.ExecuteSqlCommand("Update ProjectViewStatuses Set Status = Status + 1, UpdateTime = GETDATE() Where ProjectId = @p0 And UserId <> @p1",
                                                         new SqlParameter {
                        ParameterName = "p0", Value = log.ProjectId
                    },
                                                         new SqlParameter {
                        ParameterName = "p1", Value = log.UserId
                    });
                    break;
                }
            }
        }