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)); } }
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()); }
public Create() { _userBonus = new UserBonus(_validUserId, _validServiceId); }