public ActionResult Save(Reward reward)
        {
            if (reward != null)
            {
                if (string.IsNullOrEmpty(reward.Title))
                {
                    return(new HttpStatusCodeResult(404, "Title can't be empty :("));
                }
                if (reward.Description == null)
                {
                    reward.Description = "";
                }

                if (rewards.GetRewards().Any(c => c.ID == reward.ID))
                {
                    rewards.UpdateReward(reward);
                }
                else
                {
                    rewards.AddReward(reward);
                }
            }

            return(RedirectToAction("Index", "User"));
        }
示例#2
0
        public void UpdateReward(object sender, EventArgs e)
        {
            var rewardDT = new Reward
            {
                ID          = (int)ctlRewardDataGridView.SelectedCells[0].OwningRow.Cells[0].Value,
                Title       = (string)ctlRewardDataGridView.SelectedCells[0].OwningRow.Cells[1].Value,
                Description = (string)ctlRewardDataGridView.SelectedCells[0].OwningRow.Cells[2].Value
            };

            RewardForm form = new RewardForm(rewardDT);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                rewardDT.Title       = form.Title;
                rewardDT.Description = form.Description;
            }

            Rewards.UpdateReward(rewardDT);

            DisplayUsers();
            DisplayRewards();
        }