private void CheckAddNormalDailyReward(TestLogModel testLog, bool callSaveChanges) { var quizzTakenSelf = _currentUser.DailyNormalPointsQuizzSelfStrList.Split(','); var quizzTakenOthers = _currentUser.DailyNormalPointsQuizzOthersStrList.Split(','); var quizzIdStr = testLog.QuizzId.ToString(); var canGetPoints = CanGetPoints(testLog.Score, testLog.Total); User user = null; if (_svcContainer.QuizzSvc.IsAuthor(testLog.QuizzId, _currentUser.Id)) { if (quizzTakenSelf.Length < QuizzPointsService.MaxQuizzTakeSelf && quizzTakenSelf.Contains(quizzIdStr) == false) { if (canGetPoints) { user = _svcContainer.QuizzPointsSvc.AddCurrentUserPoints(QuizzPointsEnum.QuizzTakeSelf, callSaveChanges); } else { user = _uow.Users.GetById(_currentUser.Id); } _currentUser.DailyNormalPointsQuizzSelfStrList = user.DailyNormalPointsQuizzSelfStrList = user.DailyNormalPointsQuizzSelfStrList + quizzIdStr + ","; _uow.Users.Update(user); _svcContainer.UserSvc.UpdateCurrentUserInSession(); if (callSaveChanges) { _uow.SaveChanges(); } } } else { if (quizzTakenOthers.Length < QuizzPointsService.MaxQuizzTakeOthers && quizzTakenOthers.Contains(quizzIdStr) == false) { if (canGetPoints) { user = _svcContainer.QuizzPointsSvc.AddCurrentUserPoints(QuizzPointsEnum.QUizzTakeOthers, callSaveChanges); } else { user = _uow.Users.GetById(_currentUser.Id); } _currentUser.DailyNormalPointsQuizzOthersStrList = user.DailyNormalPointsQuizzOthersStrList = user.DailyNormalPointsQuizzOthersStrList + quizzIdStr + ","; _uow.Users.Update(user); _svcContainer.UserSvc.UpdateCurrentUserInSession(); if (callSaveChanges) { _uow.SaveChanges(); } } } }
public void CheckAddDailyRewardPoints(TestLogModel testLog, bool callSaveChanges = true) { var list = GetDailyRewards(); var reward = list.Where(r => r.QuizzId == testLog.QuizzId) .FirstOrDefault(); if (reward != null) { CheckAddSpecialDailyReward(testLog, reward, callSaveChanges); } else { CheckAddNormalDailyReward(testLog, callSaveChanges); } }
public HttpResponseMessage Post([FromBody] TestLogModel model) { try { //if (ModelState.IsValid == false || _testLogSvc.CreateTestLog(model) == false) if (_testLogSvc.CreateTestLog(model) == false) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } return(Request.CreateResponse(HttpStatusCode.Created, model)); } catch (ServiceException ex) { return(Request.CreateResponse(ex.HttpStatusCode, ex.Message)); } }
public void UpdateModel(TestLogModel model) { if (model.IsAuthor) { model.IsAuthor = true; model.IsQuizzmate = true; } model.AuthorName = model.IsQuizzmate ? model.AuthorFullName : model.AuthorUserName; model.DateTaken = model.DateTaken.ToLocalTime(); if (model.AssignmentId != 0) { model.IsPassed = _uow.Assignments.GetAll() .Where(a => a.Id == model.AssignmentId) .Select(a => a.IsCompleted) .FirstOrDefault(); } }
private void CheckAddSpecialDailyReward(TestLogModel testLog, DailyReward reward, bool callSaveChanges) { var rewardIdList = HelperUtil.GetIntArrayFromString(_currentUser.DailySpecialPointsQuizzStrList); User user = null; bool qtRewardListHasId = rewardIdList.Contains(reward.Id); if (qtRewardListHasId == false) { if (rewardIdList.Length < QuizzPointsService.MaxDailySpecialQuizzTake) { var points = ComputRewardPonts(testLog.Score, testLog.Total); if (points != 0) { user = _svcContainer.QuizzPointsSvc.AddCurrentUserPoints(QuizzPointsEnum.DailySpecialQuizz, callSaveChanges); } else { user = _uow.Users.GetById(_currentUser.Id); } user.DailySpecialPointsQuizzStrList = _currentUser.DailySpecialPointsQuizzStrList = user.DailySpecialPointsQuizzStrList + reward.Id.ToString() + ","; _uow.Users.Update(user); _svcContainer.UserSvc.UpdateCurrentUserInSession(); if (callSaveChanges) { _uow.SaveChanges(); } } else { CheckAddNormalDailyReward(testLog, callSaveChanges); } } }
public bool CreateTestLog(TestLogModel model) { try { _notificationSvc.QuizzNotificationSvc.AddQuizzTakeNotification(model.QuizzId, false); var entity = MappingUtil.Map <TestLogModel, TestLog>(model); entity.DateTaken = DateTime.UtcNow; _uow.QuizLogs.Add(entity); _uow.SaveChanges(); MappingUtil.Map(entity, model); _svcContainer.DailyRewardSvc.CheckAddDailyRewardPoints(model, false); _activitySvc.QuizzActivitySvc.AddQuizzTakeActivity(model.QuizzId, entity.Id, false); _uow.SaveChanges(); return(true); } catch (Exception ex) { _svcContainer.LoggingSvc.Log(ex); return(false); } }