public async Task <IActionResult> Post([FromBody] BonusRequests model) { var userId = User.Claims.First(u => u.Type == ClaimTypes.Authentication).Value; var serviceListPromos = await _unitOfWork.ServiceLisPromoRepository.Get(promo => promo.Code == model.Promocode, includeProperties : "ActivatedUsers"); var serviceListPromoItem = serviceListPromos.FirstOrDefault(); if (serviceListPromos.Count() == 0) { return(BadRequest("Invalid Promo Code")); } if (serviceListPromoItem.ActivatedUsers.Any(user => user.UserId == userId)) { return(BadRequest("Promo already Activated")); } else { var promoUsers = new PromoUsers { UserId = userId }; serviceListPromoItem.ActivatedUsers.Add(promoUsers); await _unitOfWork.SaveAsync(); return(Ok()); } }
public async Task <ActionResult> UpdateserviceListItemAsync([FromBody] ServiceListItem serviceListItemToUpdate) { var serviceListItems = await _unitOfWork.ServiceListRepository.Get(i => i.Id == serviceListItemToUpdate.Id); var serviceListItem = serviceListItems.FirstOrDefault(); if (serviceListItem == null) { return(NotFound(new { Message = $"Item with id {serviceListItemToUpdate.Id} not found." })); } serviceListItem = serviceListItemToUpdate; _unitOfWork.ServiceListRepository.Update(serviceListItem); await _unitOfWork.SaveAsync(); return(CreatedAtAction(nameof(GetByIdAsync), new { id = serviceListItemToUpdate.Id }, null)); }