public async Task <IActionResult> PostRewardForRedeem(RewardModel model) { try { if (!ModelState.IsValid) { return(Ok(new ApiBadRequestResponse(ModelState, MessagesConstants.BadRequest))); //400 } var userIdClaimPostRewards = Convert.ToInt32(User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "userId".ToLower(CultureInfo.InvariantCulture).Trim()).Value); var sessionIdClaimPostRewards = User.Claims.FirstOrDefault(x => x.Type.ToLower(CultureInfo.InvariantCulture).Trim() == "sessionMobileId".ToLower(CultureInfo.InvariantCulture).Trim()).Value; /* Checks the session of the user against its Id. */ if (string.IsNullOrEmpty(await _userRepository.CheckSessionId(userIdClaimPostRewards, sessionIdClaimPostRewards))) { return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, false, MessagesConstants.NoSessionMatchExist, null, 0, "", true))); } var oModelPostRewards = await _userRewardsProgressLinking.GetDataByIdAsync(new { Id = model.RewardProgressId }); if (oModelPostRewards != null) { oModelPostRewards.isRedeemed = true; } var prmDetailsPostRewards = await _userRewardsProgressLinking.UpdateAsync(oModelPostRewards, new { Id = model.RewardProgressId }); if (prmDetailsPostRewards <= 0) { return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, false, MessagesConstants.DataNotSuccessfullyReturned))); } return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, true, MessagesConstants.DataSuccessfullyReturned, prmDetailsPostRewards, 1))); } catch (Exception ex) { HttpContext.RiseError(new Exception(string.Concat("API := (Rewards := GetAllRewardsForUser)", ex.Message, " Stack Trace : ", ex.StackTrace, " Inner Exception : ", ex.InnerException))); return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, false, MessagesConstants.SomeIssueInProcessing))); } }
public ActionResult Detail(string id) { var earnedReward = Database.UserEarnedRewardStore.Get(id); if (earnedReward == null) { return(HttpNotFound()); } var rewardModel = new RewardModel { IconUri = GetDynamicResourceUri(earnedReward.Reward), SponsorIcon = earnedReward.Reward.RewardSponsor == null ? null : GetDynamicResourceUri(earnedReward.Reward), SponsorName = earnedReward.Reward.RewardSponsor == null ? null : earnedReward.Reward.RewardSponsor.Name, TriggerDistanceCentimeters = (long)earnedReward.Reward.DistanceTrigger, UnlockDate = earnedReward.CreationDate, Title = earnedReward.Reward.GetGlobalization().Title, Text = earnedReward.Reward.GetGlobalization().Text }; return(View(rewardModel)); }
private async void DrillDown(RewardModel reward, UICollectionView collectionView) { if (reward != null) { UIStoryboard board = UIStoryboard.FromName("Rewards", null); MonthRewardsViewController ctrl = board.InstantiateViewController("RewardsViewController") as MonthRewardsViewController; ctrl.CurrentPage = RewardCollectionViewController.CurrentPage; ctrl.HeaderTitle = reward.Name; if (reward.ChildList != null) { ctrl.RewardList = reward.ChildList; } else { ctrl.CategoryID = reward.ID; } var navbarHeight = RewardCollectionViewController.NavigationController.NavigationBar.Frame.Height; var overlayRect = new CoreGraphics.CGRect(0, 0, RewardCollectionViewController.View.Frame.Width, UIScreen.MainScreen.Bounds.Height - navbarHeight); UIView overlay = Platform.AddOverlay(overlayRect, UIColor.White, true, true); await SL.Manager.GetRewardsDrilldownAsync(reward.ID, null); overlay.RemoveFromSuperview(); RewardCollectionViewController.NavigationController.PushViewController(ctrl, true); } }
private decimal CalculateRewards(long height) { if (insightConfiguration.Rewards == null || insightConfiguration.Rewards.Count == 0) { return(-1); } // Remove all future reward heights. RewardModel[] filteredRewards = insightConfiguration.Rewards.Where(r => r.Height < height).ToArray(); int filteredRewardsCount = filteredRewards.Length; long totalReward = 0; for (int i = 0; i < filteredRewardsCount; i++) { RewardModel reward = filteredRewards[i]; long calculateTip; // This is the last configuration. if (i < (filteredRewardsCount - 1)) { calculateTip = filteredRewards[i + 1].Height - reward.Height; } else { calculateTip = height; } long rewardCalculation = calculateTip * reward.Reward; totalReward += rewardCalculation; } return(totalReward); }
public List <RewardModel> GetRewardsByUserId(int id) { List <RewardModel> rewards = new List <RewardModel>(); using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command = connection.CreateCommand()) { command.Parameters.AddWithValue("Id", id); command.CommandText = "SELECT Id,Title,Description FROM Rewards LEFT JOIN UsersAndRewards ON Rewards.Id = UsersAndRewards.RewardId WHERE UserId = @Id"; connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { RewardModel reward = new RewardModel { Id = reader.GetInt32(0), Title = reader[1].ToString(), Description = reader[2].ToString() }; rewards.Add(reward); } } } } return(rewards); }
public static void SetItem(RewardModel item) { SQLData.Database db = new SQLData.Database(WebInfo.Conn); SQLData.TableObject tableObj = db.GetTableObject("Reward"); object objSort = db.GetFirstValue(" SELECT TOP 1 Sort FROM Reward ORDER BY Sort DESC "); int maxSort = (objSort == null || objSort == DBNull.Value)? 1: (int)objSort; tableObj.GetDataFromObject(item); string sql = "Select 1 From Reward Where ID = " + item.ID; bool isNew = db.GetFirstValue(sql) == null; if (isNew) { tableObj["Creator"] = Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id; tableObj["CreateTime"] = DateTime.Now; tableObj["Sort"] = 1;//wei 20180726 拿掉 maxSort + tableObj.Insert(); } else { tableObj.Remove("ID"); tableObj.Remove("SiteID"); tableObj.Remove("Creator"); tableObj.Remove("CreateTime"); tableObj.Remove("Sort"); tableObj["Modifier"] = Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id; tableObj["ModifyTime"] = DateTime.Now; tableObj.Update(item.ID); } }
public List <RewardModel> GetRewardsList() { List <RewardModel> rewards = new List <RewardModel>(); using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = "SELECT Id,Title,Description from Rewards"; connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { RewardModel reward = new RewardModel { Id = reader.GetInt32(0), Title = reader[1].ToString(), Description = reader[2].ToString() }; rewards.Add(reward); } } } } return(rewards); }
private void Reward_Menu_Detail_Tap(object sender, System.Windows.Input.GestureEventArgs e) { if (e.OriginalSource is Image) { page.Storyboard2.Begin(); page.rb_Reward.IsChecked = true; Image image = e.OriginalSource as Image; //RewardModel model = image.DataContext as RewardModel; //Image pin = new Image() { Source = new BitmapImage(new Uri("/Image_Recycle/bubble.png", UriKind.Relative)) }; //pin.Width = 40; //pin.Height = 40; //pin.Tag = model.Id; //pin.DataContext = model; //page.layer.AddChild(pin, new GeoCoordinate(model.Latitude, model.Longitude)); RewardModel reward = image.DataContext as RewardModel; Reward_Menu_1 menu = new Reward_Menu_1(); menu.tbk_UserName.Text = reward.StoreName; menu.tbk_Phone.Text = reward.Phone; menu.tbk_Address.Text = reward.Address; menu.tbk_Describe.Text = reward.Describe; menu.Width = 350; menu.Height = 250; page.layer.AddChild(menu, new GeoCoordinate(reward.Latitude, reward.Longitude)); page.map.SetView(new GeoCoordinate(reward.Latitude, reward.Longitude), 16); } }
void pin_Tap(object sender, System.Windows.Input.GestureEventArgs e) { Image pin = sender as Image; if (pin.DataContext is AcquirerModel) { AcquirerModel acquirer = pin.DataContext as AcquirerModel; Recycle_Menu_1 menu = new Recycle_Menu_1(); menu.tbl_BinName.Text = acquirer.BinName; menu.tbk_UserName.Text = acquirer.AcquirerName; menu.tbk_Phone.Text = acquirer.Phone; menu.tbk_Address.Text = acquirer.Address; menu.Tag = acquirer.Id; menu.Width = 300; menu.Height = 250; layer.AddChild(menu, new GeoCoordinate(acquirer.Latitude, acquirer.Longitude)); } else { RewardModel reward = pin.DataContext as RewardModel; Reward_Menu_1 menu = new Reward_Menu_1(); menu.tbk_UserName.Text = reward.StoreName; menu.tbk_Phone.Text = reward.Phone; menu.tbk_Address.Text = reward.Address; menu.tbk_Describe.Text = reward.Describe; menu.image_Item.Source = new BitmapImage(new Uri(reward.AvatarUri, UriKind.Relative)); menu.Width = 350; menu.Height = 250; layer.AddChild(menu, new GeoCoordinate(reward.Latitude, reward.Longitude)); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Price,Description,ImagePath")] RewardModel rewardModel) { if (id != rewardModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(rewardModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RewardModelExists(rewardModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(rewardModel)); }
public bool UpdateReward(RewardModel reward) { using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command = connection.CreateCommand()) { command.Parameters.AddWithValue("@Id", reward.Id); command.Parameters.AddWithValue("@Title", reward.Title); command.Parameters.AddWithValue("@Description", reward.Description); command.CommandText = "UPDATE Rewards SET Title=@Title,Description=@Description WHERE Id=@Id"; try { connection.Open(); int result = (int)command.ExecuteNonQuery(); if (result != 0) { return(true); } return(false); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } } } }
public int AddReward(RewardModel reward) { int index = rewards.Any() ? rewards.Max(m => m.Id) + 1 : 0; reward.Id = index; rewards.Add(reward); return(index); }
public static RewardViewModel ConvertToViewModelR(this RewardModel domainModel) { return(new RewardViewModel() { Id = domainModel.Id, Title = domainModel.Title, Description = domainModel.Description }); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { var list = SL.RewardList; RewardModel reward = list != null ? list[indexPath.Row] : null; var cell = (MonthRewardsTableCell)tableView.DequeueReusableCell(nameof(MonthRewardsTableCell)) as MonthRewardsTableCell; cell?.Update(reward); return(cell); }
public void Update(RewardModel model) { RewardCategoryName.Text = model.Name; RewardItemBackground.Image = UIImage.FromBundle("rewardsDetails-placeholder"); ImageService.Instance.LoadUrl(model.MainImageURL).Into(RewardItemBackground); RewardsCountLabel.Text = model.ChildList?.Count.ToString(); RewardIcon.Image = UIImage.FromBundle("reward-icon_white"); SetFonts(); }
public void UpdateCellData(RewardModel item) { RewardName.Text = item.Name; RewardsCountLabel.Text = (item.NumChildren ?? item.ChildList?.Count ?? 0).ToString(); ImageService.Instance.LoadUrl(item.MainImageURL).Into(RewardImage); RewardImage.Layer.CornerRadius = RewardImageOverlay.Layer.CornerRadius = UIScreen.MainScreen.Bounds.Width / 100 * 0.48f; SetFonts(); }
public int AddReward(RewardModel reward) { if (reward == null) { throw new ArgumentNullException(); } reward.Id = _rewards.Any() ? _rewards.Max(task => task.Id) + 1 : 0; _rewards.Add(reward); return(reward.Id); }
public bool RemoveRewardById(int id) { RewardModel rewardRemove = _rewards.FirstOrDefault(re => re.Id == id); if (rewardRemove == null) { return(false); } return(_rewards.Remove(rewardRemove)); }
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { var list = SL.RewardList; RewardModel rewardCategory = list != null ? list[indexPath.Row] : null; if (rewardCategory != null) { DrillDown(rewardCategory); } }
public async Task <IActionResult> Create([Bind("Id,Title,Price,Description,ImagePath")] RewardModel rewardModel) { if (ModelState.IsValid) { _context.Add(rewardModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(rewardModel)); }
public void UpdateCellData(RewardModel reward) { CategoryName.Text = reward.Name; CategoryCountLabel.Text = (reward.NumChildren ?? reward.ChildList?.Count ?? 0).ToString(); ImageService.Instance.LoadUrl(reward.MainImageURL).Into(CategoryImage); CategoryImage.Layer.CornerRadius = CategoryImageOverlay.Layer.CornerRadius = UIScreen.MainScreen.Bounds.Width / 100 * 0.48f; SetFonts(); }
public override bool IsValid(object value) { RewardModel app = value as RewardModel; if (app.IsReward && app.Reward == 0) { ErrorMessage = "please enter Reward"; return(false); } return(true); }
public void ShouldBeAbleToThrowArgumentExeptionWhenUpdatingReward() { InMemoryStorage storage = new InMemoryStorage(); RewardModel illegalReward = new RewardModel { Id = -1, Title = "1", Description = "1" }; Assert.Throws <ArgumentException>(() => storage.UpdateReward(illegalReward)); }
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { var list = SL.RewardList; RewardModel reward = list?[indexPath.Row] ?? null; var cell = (RewardCollectionViewCell)collectionView.DequeueReusableCell(RewardCollectionViewCell.ClassName, indexPath); if (reward != null) { cell.UpdateCellData(reward); } return(cell); }
public static RewardViewModel ConvertToRewardViewModel(this RewardModel domainRewardModel) { if (domainRewardModel == null) { return(null); } return(new RewardViewModel { Id = domainRewardModel.Id, Title = domainRewardModel.Title, Description = domainRewardModel.Description }); }
private static void BindReward(RewardItem cmp, RewardModel model) { cmp.gameObject.SetActive(true); switch (model.Type) { case 1: cmp.normalIcon.SetActive(true); if (model.Id == "1") { cmp.itemName.text = string.Empty; cmp.normalIcon.spriteName = "public_ui_02"; } else if (model.Id == "2") { cmp.itemName.text = string.Empty; cmp.normalIcon.spriteName = "public_ui_03"; } cmp.itemCount.text = "X" + model.Count.ToString(); cmp.normalIcon.SetActive(true); cmp.specialIcon.SetActive(false); break; case 2: cmp.normalIcon.SetActive(true); cmp.itemName.text = "经验"; cmp.normalIcon.spriteName = string.Empty; cmp.itemCount.text = model.Count.ToString(); break; case 3: cmp.normalIcon.SetActive(true); cmp.itemName.text = "体力"; cmp.normalIcon.spriteName = string.Empty; cmp.itemCount.text = model.Count.ToString(); break; case 4: { cmp.normalIcon.SetActive(false); SysGameItemsVo dataById = BaseDataMgr.instance.GetDataById <SysGameItemsVo>(model.Id); cmp.specialIcon.mainTexture = ResourceManager.Load <Texture>(dataById.icon, true, true, null, 0, false); cmp.itemBorder.spriteName = CharacterDataMgr.instance.GetFrame_EquipIcon(dataById.quality); cmp.itemName.text = dataById.name; cmp.itemCount.text = model.Count.ToString(); cmp.normalIcon.SetActive(false); cmp.specialIcon.SetActive(true); break; } } }
public void ShouldBeAbleToReturnIdWhenAddingReward() { RewardModel testReward = new RewardModel { Title = "1", Description = "1" }; InMemoryStorage storage = new InMemoryStorage(); int expectedId = 6; int actualId = storage.AddReward(testReward); Assert.Equal(expectedId, actualId); }
public static RewardStrategy CreateStrategy(RewardType strategyType, RewardModel model) { switch (strategyType) { case RewardType.SingleWinner: return new SingleWinner(); case RewardType.TopNWinners: // ReSharper disable once PossibleInvalidOperationException byte winnersCount = (byte)model.WinnersCount; return new TopNWinners(winnersCount); default: throw new ArgumentException(); } }
public bool UpdateReward(RewardModel reward) { RewardModel editedReward = rewards.FirstOrDefault(er => er.Id == reward.Id); if (editedReward is null) { return(false); } else { editedReward.Title = reward.Title; editedReward.Description = reward.Description; return(true); } }
public bool UpdateReward(RewardModel reward) { if (reward == null) { throw new ArgumentNullException(); } var rewardUpdate = _rewards.FirstOrDefault(re => re.Id == reward.Id); if (rewardUpdate == null) { throw new ArgumentException(); } rewardUpdate.Title = reward.Title; rewardUpdate.Description = reward.Description; return(true); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { RewardsTableView rewardsTable = tableView as RewardsTableView; if (rewardsTable != null) { var list = SL.RewardList; RewardModel rewardCategory = list != null ? list[indexPath.Row] : null; if (rewardCategory != null) { DrillDown(rewardCategory); } //DrillDown(rewardCategory); //SL.Manager.GetRewardsDrilldownAsync(rewardCategory.ID, DrillDown); } }
public ActionResult FinalizePost(int id) { var contest = this.IsContestClosable(id); if (contest == null) { this.AddToastMessage("Error", "Error with closing this contest!", ToastType.Error); return this.RedirectToAction("Details", "Users", routeValues: new { id = this.UserProfile.Id, area = "" }); } RewardModel model = new RewardModel { WinnersCount = contest.WinnersCount }; RewardStrategy strategy = RewardFactory.CreateStrategy(contest.RewardType, model); strategy.DetermineWinners(contest); this.ContestsData.SaveChanges(); this.SendParticipantsNotification(contest); this.AddToastMessage("Success", "You finalized this contest successfully!", ToastType.Success); return this.RedirectToAction("Details", "Users", routeValues: new { id = this.UserProfile.Id, area = "" }); }