public HttpResponseMessage CreateFundingForProject(UserFundingModel funding, int projectId) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new UserFundingRepository()) { //STEP 1 - Create the Project Funding from UserFundingModel coming from the client long newFundingId = s.Insert(funding, projectId, identity); //STEP 2 - Update Project Stats Screen Amount + NoOfBackers using (var sr = new ProjectStatRepository()) { bool statAmountUpdated = sr.IncrementProjectStatMoneyPledged(projectId, funding.AmountPaid); bool statNoOfBackersUpdated = sr.IncrementProjectStatBackersNo(projectId); if (!statAmountUpdated || !statNoOfBackersUpdated) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } return(Request.CreateResponse(HttpStatusCode.Created, newFundingId)); } }
public long Insert(UserFundingModel source, int projectId, ClaimsIdentity identity) { long requestorUserId; try { requestorUserId = uow.UserRepository .SearchFor(e => e.Username == identity.Name) .Select(e => e.Id) .SingleOrDefault(); } catch (InvalidOperationException ex) { throw new InvalidOperationException("User lookup for requestor Id for user funding creation failed", ex); } try { var _userFunding = new UserFunding() { FundingPackageId = source.FundingPackageId, UserId = requestorUserId, WhenDateTime = DateTime.Now, AmountPaid = source.AmountPaid, TransactionId = source.TransactionId }; uow.UserFundingRepository.Insert(_userFunding, true); return(_userFunding.Id); } catch (Exception) { throw; } }