public HttpResponseMessage GetFundingPackageByIdForLoggedInUsersForPaymentView(int projectId, int fundingPackageId) { if (projectId <= 0 || fundingPackageId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } using (var s = new FundingPackageRepository()) { var v = s.GetProjectFundingPackageByIdForPaymentView(projectId, fundingPackageId); return(Request.CreateResponse(HttpStatusCode.OK, v)); } }
public HttpResponseMessage GetProjectFundingPackagesForLoggedOutUsers(int projectId) { if (projectId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } using (var s = new FundingPackageRepository()) { var v = s.GetAllProjectFundingPackages(projectId); return(Request.CreateResponse(HttpStatusCode.OK, v)); } }
public HttpResponseMessage GetFundingPackageByIdForLoggedInUsers(int projectId, int fundingPackageId) { if (projectId <= 0 || fundingPackageId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new FundingPackageRepository()) { var v = s.GetProjectFundingPackageById(projectId, fundingPackageId, identity); return(Request.CreateResponse(HttpStatusCode.OK, v)); } }
public HttpResponseMessage CreateProject(ProjectModel project) { //STEP 1 - Create the Project from Project Model coming from the client if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new ProjectRepository()) { //STEP 1 - Create new Attachment Set and assign it to the model coming from the client using (var attRepo = new AttachmentSetRepository()) { long attachmentSetId = attRepo.CreateAttachmentSet(); project.AttachmentSetId = attachmentSetId; } //STEP 2 - Create the Project and save to Projects table long newProjectId = s.Insert(project, identity); //STEP 3 - Create Project Stats Screen and Save to ProjectStats Table using (var sr = new ProjectStatRepository()) { bool statCreated = sr.CreateProjectStat((int)newProjectId); if (!statCreated) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } //STEP 4 - Create new Project Funding Package for Donations using (var fpRepo = new FundingPackageRepository()) { FundingPackageModel newFundingPackageModel = new FundingPackageModel(); newFundingPackageModel.AttachmentSetId = null; newFundingPackageModel.Title = "Donations Funding Package"; newFundingPackageModel.Description = "Feel free to donate whatever amount you wish!"; fpRepo.CreateFundingPackage(newFundingPackageModel, identity, (int)newProjectId, true); } return(Request.CreateResponse(HttpStatusCode.Created, newProjectId)); } }
public HttpResponseMessage DeleteFundingPackage(int projectId, int fundingPackageId) { if (projectId <= 0 || fundingPackageId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new FundingPackageRepository()) { var httpStatusCode = HttpStatusCode.NoContent; FundingPackageRepository.StatusCodes hasDeleted = s.DeleteFundingPackage(identity, projectId, fundingPackageId); switch (hasDeleted) { //project not found or funding package to delete not found case FundingPackageRepository.StatusCodes.NOT_FOUND: httpStatusCode = HttpStatusCode.NotFound; break; //not authorized to delete this funding package - either you are not the project creator or this is a donations package automatically created by the system case FundingPackageRepository.StatusCodes.NOT_AUTHORIZED: httpStatusCode = HttpStatusCode.MethodNotAllowed; break; //funding package deleted ok case FundingPackageRepository.StatusCodes.OK: httpStatusCode = HttpStatusCode.NoContent; break; } return(Request.CreateResponse(httpStatusCode)); } }
public HttpResponseMessage UpdateFundingPackage(FundingPackageModel fundingPackage, int projectId, int fundingPackageId) { if (!ModelState.IsValid || projectId <= 0 || fundingPackageId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new FundingPackageRepository()) { var httpStatusCode = HttpStatusCode.OK; FundingPackageRepository.StatusCodes hasUpdated = s.EditFundingPackage(fundingPackage, identity, projectId, fundingPackageId); switch (hasUpdated) { //project or funding package not found case FundingPackageRepository.StatusCodes.NOT_FOUND: httpStatusCode = HttpStatusCode.NotFound; break; //not authorized to update this funding package. You are not the project creator that has this specific funding package case FundingPackageRepository.StatusCodes.NOT_AUTHORIZED: httpStatusCode = HttpStatusCode.MethodNotAllowed; break; //funding package updated ok case FundingPackageRepository.StatusCodes.OK: httpStatusCode = HttpStatusCode.OK; break; } return(Request.CreateResponse(httpStatusCode)); } }
public HttpResponseMessage CreateFundingPackage(FundingPackageModel fundingPackage, int projectId) { if (!ModelState.IsValid || projectId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; using (var s = new FundingPackageRepository()) { var httpStatusCode = HttpStatusCode.Created; FundingPackageRepository.StatusCodes hasInserted = s.CreateFundingPackage(fundingPackage, identity, projectId, false); switch (hasInserted) { //project for inserting the funding package not found case FundingPackageRepository.StatusCodes.NOT_FOUND: httpStatusCode = HttpStatusCode.NotFound; break; //not authorized to add this funding package to this specific project case FundingPackageRepository.StatusCodes.NOT_AUTHORIZED: httpStatusCode = HttpStatusCode.MethodNotAllowed; break; //funding package inserted ok case FundingPackageRepository.StatusCodes.OK: httpStatusCode = HttpStatusCode.Created; break; } return(Request.CreateResponse(httpStatusCode)); } }