Beispiel #1
0
        Task <ProjectMonthlyReport> IProjectGrain.GetProjectMonthlyReport(short year, short month)
        {
            if (Kernel == null)
            {
                throw new ProjectNotFoundException();
            }

            ProjectMonthlyReport ultimoReport = null;
            DateTime             ultimo       = new DateTime(year, month, 1).AddMilliseconds(-1);

            foreach (ProjectMonthlyReport item in ProjectMonthlyReportList)
            {
                if (item.Year == year && item.Month == month)
                {
                    return(Task.FromResult(item));
                }
                else if (item.Year == ultimo.Year && item.Month == ultimo.Month)
                {
                    ultimoReport = item;
                }
            }

            return(Task.FromResult(Kernel.NewDetail(ProjectMonthlyReport.
                                                    Set(p => p.Year, year).
                                                    Set(p => p.Month, month).
                                                    Set(p => p.Status, ultimoReport != null ? ultimoReport.Status : null).
                                                    Set(p => p.MonthlyPlan, ultimoReport != null ? ultimoReport.NextMonthlyPlan : "*"))));
        }
Beispiel #2
0
        async Task IProjectGrain.PutProjectMonthlyReport(ProjectMonthlyReport source)
        {
            if (Kernel == null)
            {
                throw new ProjectNotFoundException();
            }

            if (!await IsMyProject())
            {
                throw new SecurityException("非请毋动!");
            }

            if (source.Month < 1 || source.Month > 12)
            {
                throw new ValidationException(String.Format("咱这可没{0}月份唉!", source.Month));
            }

            DateTime today = DateTime.Today;

            if (source.Year > today.Year || source.Year == today.Year && source.Month > today.Month)
            {
                throw new ValidationException("未来不可期~");
            }

            foreach (ProjectMonthlyReport item in ProjectMonthlyReportList)
            {
                if (item.Year == source.Year && item.Month == source.Month)
                {
                    Database.Execute((DbTransaction dbTransaction) =>
                    {
                        item.UpdateSelf(dbTransaction, source);
                        if (today.Year == source.Year && today.Month == source.Month)
                        {
                            Kernel.UpdateSelf(dbTransaction,
                                              NameValue.Set <ProjectInfo>(p => p.CurrentStatus, source.Status));
                        }
                    });
                    return;
                }
            }

            Database.Execute((DbTransaction dbTransaction) =>
            {
                source.InsertSelf(dbTransaction);
                if (today.Year == source.Year && today.Month == source.Month)
                {
                    Kernel.UpdateSelf(dbTransaction,
                                      NameValue.Set <ProjectInfo>(p => p.CurrentStatus, source.Status));
                }
            });
            ProjectMonthlyReportList.Add(source);
        }
        public async Task Put()
        {
            ProjectMonthlyReport projectMonthlyReport = await Request.ReadBodyAsync <ProjectMonthlyReport>();

            await ClusterClient.Default.GetGrain <IProjectGrain>(projectMonthlyReport.PiId).PutProjectMonthlyReport(projectMonthlyReport);
        }