Esempio n. 1
0
 public static UpdateWorkRecord CreateUpdateWorkRecord(WorkRecord workRecord)
 {
     var updateWorkRecord = new UpdateWorkRecord();
     updateWorkRecord.ID = workRecord.ID;
     updateWorkRecord.Journal = workRecord.Journal;
     updateWorkRecord.Summary = workRecord.Summary;
     updateWorkRecord.Plan = workRecord.Plan;
     return updateWorkRecord;
 }
 // GET: WorkContent/TodayWork/Create
 public ActionResult Create(Guid? id)
 {
     var userId = new Guid(User.Identity.Name);
     var workRecordServices = ServiceLocator.Instance.GetService<IWorkRecordServices>();
     var updateWorkRecord = new UpdateWorkRecord();
     if (id.HasValue)
     {
         updateWorkRecord = workRecordServices.Get(userId, id.Value);
     }
     ViewBag.UpdateWorkRecord = new HtmlString(updateWorkRecord.ToJson());
     return PartialView();
 }
 public ActionResult Edit(UpdateWorkRecord updateWorkRecord)
 {
     try
     {
         var userId = new Guid(User.Identity.Name);
         // TODO: Add update logic here
         var workRecordServices = ServiceLocator.Instance.GetService<IWorkRecordServices>();
         workRecordServices.Update(updateWorkRecord, userId);
         var result = workRecordServices.GetResult();
         return Json(result);
     }
     catch
     {
         return View();
     }
 }
 public void Delete(UpdateWorkRecord updateWorkRecord)
 {
     using (var workContext = new DefaultContext())
     {
         var workRecord = workContext.WorkRecords.FirstOrDefault(x => x.ID == updateWorkRecord.ID);
         workContext.WorkRecords.Remove(workRecord);
         workContext.SaveChanges();
         Flag = true;
     }
 }
        public UpdateWorkRecord Get(Guid accountId, Guid recordId)
        {
            var updateWorkRecord = new UpdateWorkRecord();

            using (var workContext = new DefaultContext())
            {
                var workRecords =
                    workContext.WorkRecords.AsNoTracking().FirstOrDefault(x => x.AccountId == accountId && x.ID == recordId);

                updateWorkRecord = UpdateWorkRecord.CreateUpdateWorkRecord(workRecords);

            }
            return updateWorkRecord;
        }
 private void Edit(UpdateWorkRecord updateWorkRecord)
 {
     using (var workContext = new DefaultContext())
     {
         var workRecord = workContext.WorkRecords.FirstOrDefault(x => x.ID == updateWorkRecord.ID);
         if (workRecord.Null())
         {
             Message = "被修改日志不存在!";
             return;
         }
         if (workRecord.CreateTime.Date.AddHours(27) < DateTime.Now)
         {
             Message = "日志已经被锁定无法修改!";
             return;
         }
         workRecord = updateWorkRecord.Update(workRecord);
         workContext.ModifiedModel(workRecord);
         workContext.SaveChanges();
         Flag = true;
     }
 }
 private void Add(UpdateWorkRecord updateWorkRecord, Guid accountId)
 {
     using (var workContext = new DefaultContext())
     {
         var account = workContext.Accounts.FirstOrDefault(x => x.ID == accountId);
         if (account.Null())
         {
             Message = "登录过期,清重新登陆";
             return;
         }
         var workRecord = updateWorkRecord.CreateWorkRecord(account.ID);
         workContext.WorkRecords.Add(workRecord);
         workContext.SaveChanges();
         Flag = true;
     }
 }
 public void Update(UpdateWorkRecord updateWorkRecord, Guid accountId)
 {
     if (updateWorkRecord.ID.Null())
     {
         Add(updateWorkRecord, accountId);
     }
     else
     {
         Edit(updateWorkRecord);
     }
 }