Exemplo n.º 1
0
        public async Task <IActionResult> Put(Guid id, BonusActivationRequest request)
        {
            try
            {
                // Check if service is still available.
                Service service = await _repository.GetByIdAsync(id);

                if (service == null)
                {
                    return(StatusCode(StatusCodes.Status204NoContent));
                }

                UserBonus userBonus = _userBonusMapper.Map(request);

                await _userBonusRepository.AddAsync(userBonus);

                return(Ok());
            }

            catch (Exception e)
            {
                _logger.LogError(e.Message, id, request);
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Exemplo n.º 2
0
        public IActionResult Back(int value, string campName, bool withBonus, int bonusId)
        {
            var findCampaign = from p in db.Campaigns
                               where p.Name == campName
                               select p;
            Campaign campaign = findCampaign.First();

            db.Entry(campaign).Collection(b => b.Backs).Load();
            if (ModelState.IsValid)
            {
                var user = from u in db.Users
                           where u.UserName == User.Identity.Name
                           select u;

                Back back = new Back
                {
                    Campaign = campaign,
                    Value    = value,
                    User     = user.First()
                };
                db.Backs.Add(back);

                int currSum = 0;
                foreach (Back b in campaign.Backs)
                {
                    currSum += b.Value;
                }
                campaign.CurrentSum = currSum;
                if (withBonus == true)
                {
                    var findBonus = from b in db.Bonuses
                                    where b.Id == bonusId
                                    select b;
                    Bonus     bonus     = findBonus.First();
                    UserBonus userBonus = new UserBonus
                    {
                        User  = user.First(),
                        Bonus = bonus
                    };
                    db.UserBonuses.Add(userBonus);
                }
                db.SaveChanges();
                return(RedirectToAction("ShowProjectInfo", "Project", new { campaignName = campName }));
            }
            return(View());
        }
Exemplo n.º 3
0
 public Create()
 {
     _userBonus = new UserBonus(_validUserId, _validServiceId);
 }