public static UpdateWeekSummary CreateSummary(Guid? weekId, WeekSummary weekSummary)
 {
     var updateWeekSummary = new UpdateWeekSummary();
     updateWeekSummary.ID = weekId.GetValueOrDefault();
     if (!weekSummary.Null())
     {
         updateWeekSummary.Description = weekSummary.Description;
         updateWeekSummary.DepartmentId = weekSummary.DepartmentId;
     }
     return updateWeekSummary;
 }
        //private void AddTarget(UpdateWeeklyTarget updateWeeklyTarget)
        //{
        //    var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Today);
        //    using (var workContext = new DefaultContext())
        //    {
        //        var weekTarget = workContext.WeekTargets.FirstOrDefault(x => x.WeekNum == weekNum && x.DepartmentId == updateWeeklyTarget.DepartmentId);
        //        if (!weekTarget.Null())
        //        {
        //            Message = "本周已经有日志";
        //            return;
        //        }
        //        weekTarget = updateWeeklyTarget.CreateWeekTarget(weekNum);
        //        workContext.WeekTargets.Add(weekTarget);
        //        Flag = true;
        //    }
        //}

        //private void EditTarget(UpdateWeeklyTarget updateWeeklyTarget)
        //{
        //    var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Today);


        //    using (var workContext = new DefaultContext())
        //    {
        //    }
        //}


        public void UpdateSummary(UpdateWeekSummary updateWeekSummary)
        {
            using (var workContext = new DefaultContext())
            {
                var weekTarget = workContext.WeekTargets.FirstOrDefault(x => x.ID == updateWeekSummary.ID);
                if (weekTarget.Null())
                {
                    Message = "总结周记不存在";
                    return;
                }
                var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Now);
                if (weekNum > weekTarget.WeekNum + 1)
                {
                    if (DateTime.Now.Hour > 2 || DateTime.Today.DayOfWeek > DayOfWeek.Monday)
                    {
                        Message = "周记已经被锁定无法总结!";
                        return;
                    }
                }
                var weekSummary = workContext.WeekSummaries.FirstOrDefault(x => x.ID == updateWeekSummary.ID);
                if (weekSummary.Null())
                {
                    weekSummary = new WeekSummary();
                    weekSummary.ID = updateWeekSummary.ID;
                    weekSummary.CreateTime = DateTime.Now;
                    weekSummary.DepartmentId = updateWeekSummary.DepartmentId;
                    weekSummary.WeekNum = weekTarget.WeekNum;
                    weekSummary.DepartmentId = weekTarget.DepartmentId;
                    workContext.WeekSummaries.Add(weekSummary);
                }
                else
                {
                    workContext.ModifiedModel(weekSummary);
                }

                weekSummary.Description = updateWeekSummary.Description;
                workContext.SaveChanges();
                Flag = true;
            }
        }
 public ActionResult EditSummary(UpdateWeekSummary updateWeekSummary)
 {
     try
     {
         // TODO: Add update logic here
         var userId = new Guid(User.Identity.Name);
         var weeklyPlanServices = ServiceLocator.Instance.GetService<IWeeklyPlanServices>();
         weeklyPlanServices.UpdateSummary(updateWeekSummary);
         var result = weeklyPlanServices.GetResult();
         return Json(result);
     }
     catch
     {
         return Content("1");
     }
 }
        public UpdateWeekSummary GetWeekSummary(Guid accountId)
        {
            var weekNum = DateTimeUtility.GetWeekOfYear(DateTime.Now);
            var updateWeekSummary = new UpdateWeekSummary();
            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 updateWeekSummary;
                }
                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();
                updateWeekSummary = UpdateWeekSummary.CreateSummary(weeklyPaln?.target.ID, weeklyPaln?.summ);

                return updateWeekSummary;
            }
        }
        public ActionResult GetSummary()
        {
            var userId = new Guid(User.Identity.Name);
            var weeklyPlanServices = ServiceLocator.Instance.GetService<IWeeklyPlanServices>();
            var updateWeeklyTarget = new UpdateWeekSummary();

            updateWeeklyTarget = weeklyPlanServices.GetWeekSummary(userId);

            ViewBag.UpdateWeekSummarie = new HtmlString(updateWeeklyTarget.ToJson());
            return PartialView();
        }