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 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));
            }
        }