/// <summary> /// 更改所有活动的状态 /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void EditActivityStatus(object source, ElapsedEventArgs e) { var activityList = _activityTermExtension.GetAll().Where(x => (x.Status == ActivityStatus.未开始 || x.Status == ActivityStatus.进行中) && x.StartDataTime > DateTime.Now).ToList(); foreach (var activity in activityList) { if (activity.StartDataTime > DateTime.Now && activity.EndDataTime > DateTime.Now) { activity.Status = ActivityStatus.进行中; _activityTermExtension.Edit(activity); } else if (activity.EndDataTime < DateTime.Now) { activity.Status = ActivityStatus.已结束; _activityTermExtension.Edit(activity); } _activityTermExtension.Save(); } }
/// <summary> /// 用于存储或更新活动 /// </summary> /// <param name="anVM"></param> /// <returns></returns> public async Task <IActionResult> Sava([Bind("ID,UserId,Name,SchoolAddress,CreateDataTime,MaxNumber,Description")] AnAssociationVM anVM) { var an = await _anAssociationRepository.GetSingleAsyn(anVM.ID); if (an == null) { an = new AnAssociation(); var userclaims = User.Claims.FirstOrDefault(); var userData = await _userManager.FindByIdAsync(userclaims.Value.ToString()); an.User = userData; var anFounder = new AnAssociationAndUser() { User = userData, AnAssociationId = anVM.ID, AnJurisdictionManager = AnJurisdiction.Founder }; an.IsDisable = true; _anAssociationAndUserExtension.Add(anFounder); } anVM.MapToAn(an); var savaStatus = await _anAssociationRepository.AddOrEditAndSaveAsyn(an); if (an == null) { _anAssociationAndUserExtension.Save(); } if (savaStatus) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "数据保存出现异常,无法创建活动。"); return(View("~/Views/GroupOrganization/AnAssociation/CreateOrEdit.cshtml", anVM)); } }