Esempio n. 1
0
 /// <summary>
 /// 获取成员签到数据
 /// </summary>
 /// <returns></returns>
 public JsonResult GetAttendance(string Name)
 {
     using (var db = new SHBTONLINEContext())
     {
         AttendModel model = new AttendModel();
         //查询人员以及签到日期(条件为签到人员名字与登录名相同)
         var query = db.AttendanceInfos.Where(p => p.AD_LoginName == Name).Where(p => p.AD_AttendTime.Value.Month == DateTime.Now.Month).Select(p => new
         {
             AttendTime = p.AD_AttendTime,//个人签到时间集合
         }).ToList();
         //返回给签到记录
         return(Json(query));
     }
 }
        public async Task <Object> Attend(AttendModel modelAttended)
        {
            try
            {
                var activity = _dataContext.Activities.FirstOrDefault(a => a.Id == modelAttended.Id);

                if (activity == null)
                {
                    return(BadRequest(null));
                }

                var studentfound = _dataContext.Students.FirstOrDefault(a => a.Id == modelAttended.userConnected.Id);

                if (studentfound == null)
                {
                    return(BadRequest(null));
                }

                // var isRegistered = studentfound.Activities.FirstOrDefault(a => a.Id == activity.Id);

                //if (isRegistered != null)
                //    return BadRequest(null);

                activity.Attenders++;
                ////if (studentfound.Activities == null)
                ////    studentfound.Activities = new DbSet<Activity>();

                await _dataContext.SaveChangesAsync();

                return(Ok(studentfound));
            }
            catch (Exception)
            {
                return(BadRequest(null));
            }
        }