Esempio n. 1
0
 public static ShowWeeklyPlan CreateShowWeeklyPlan(WeekSummary weekSummary, WeekTarget weekTarget, Department department)
 {
     var showWeeklyPlan = new ShowWeeklyPlan();
     if (!weekSummary.Null())
     {
         showWeeklyPlan.ID = weekSummary.ID;
         showWeeklyPlan.Description = weekSummary.Description;
         showWeeklyPlan.CreateTime = weekSummary.CreateTime.ToString("yy-MM-dd HH:mm");
         showWeeklyPlan.TargetTime = weekSummary.WeekNum;
     }
     if (!weekTarget.Null())
     {
         showWeeklyPlan.Target = weekTarget.Target ?? " ";
         showWeeklyPlan.Progress = weekTarget.Progress;
         showWeeklyPlan.TargetTime = weekTarget.WeekNum;
     }
     if (!department.Null())
     {
         showWeeklyPlan.DepartmentName = department.Name;
     }
     DateTime beginTime;
     DateTime endTime;
     DateTimeUtility.GetWeekDays(showWeeklyPlan.TargetTime, out beginTime, out endTime);
     showWeeklyPlan.BeginTime = beginTime.ToString("yy-MM-dd");
     showWeeklyPlan.EndTime = endTime.ToString("yy-MM-dd");
     return showWeeklyPlan;
 }
        public ShowWeeklyPlan GetLastWeekPlan(Guid accountId)
        {
            var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Now);
            using (var workContext = new DefaultContext())
            {
                var workCard = (
                    from card in workContext.WorkCards
                    join department in workContext.Departments on card.DepartmentId equals department.ID
                    where card.AccountId == accountId
                    select new
                    {
                        card,
                        department
                    }).FirstOrDefault();

                if (workCard.Null())
                {
                    return new ShowWeeklyPlan();
                }
                var weeklyPaln = (
                    from target in workContext.WeekTargets
                    let summ = workContext.WeekSummaries.FirstOrDefault(x => x.ID == target.ID)
                    where target.DepartmentId == workCard.card.DepartmentId && target.WeekNum == weekNum
                    select new
                    {
                        target,
                        summ
                    }).FirstOrDefault();
                if (weeklyPaln.Null())
                {
                    var target = new WeekTarget();
                    target.ID = Guid.NewGuid();
                    target.CreateTime = DateTime.Now;
                    target.DepartmentId = (Guid)workCard?.department.ID;
                    target.WeekNum = weekNum;
                    target.Target = "本周日志还没写!!!";
                    target.Progress = 100;
                    workContext.WeekTargets.Add(target);
                    workContext.SaveChanges();
                }
                return ShowWeeklyPlan.CreateShowWeeklyPlan(weeklyPaln?.summ, weeklyPaln?.target,
                    workCard?.department);
            }
        }