public HttpResponseMessage EndorseCampaign(HttpRequestMessage request, int userId, int campaignId) { var campaign = _studentApi.EndorseCampaign(userId, campaignId); var camp = _studentApi.GetSingleCampaign(campaignId); camp.NumberOfUpVotes += 1; _studentApi.SaveCampaign(camp); var user = _studentApi.GetUserInfo(userId); if (user.UserType.Equals("Sponsor", StringComparison.OrdinalIgnoreCase)) { var sponsor = _studentApi.GetSponsor(user.ID); sponsor.BursifyScore += 1; _sponsorApi.SaveSponsor(sponsor); } var campaignVM = new CampaignViewModel(); campaignVM.SingleCampaignMap(campaign); var response = request.CreateResponse(HttpStatusCode.OK, campaignVM); return(response); }
public HttpResponseMessage SaveSponsorship(HttpRequestMessage request, SponsorshipViewModel sponsorship) { var newSponsorship = sponsorship.ReverseMap(); var existing = _studentApi.GetSponsorship(sponsorship.ID); _studentApi.SaveSponsorship(newSponsorship); if (existing == null) { var sponsor = _sponsorApi.GetSponsor(newSponsorship.SponsorId); var points = newSponsorship.Rating * 10; sponsor.BursifyScore += points; _sponsorApi.SaveSponsor(sponsor); } var model = new SponsorshipViewModel(); var sponsorshipVm = model.SingleSponsorshipMap(newSponsorship); var response = request.CreateResponse(HttpStatusCode.OK, sponsorshipVm); return(response); }
public HttpResponseMessage ApplyForSponsorship(HttpRequestMessage request, StudentSponsorshipViewModel application) { var newApplication = new StudentSponsorship() { StudentId = application.StudentId, SponsorshipId = application.SponsorshipId, ApplicationDate = application.ApplicationDate, SponsorshipOffered = application.SponsorshipOffered, Status = application.Status }; _studentApi.ApplyForSponsorship(newApplication); var sponsorship = _studentApi.GetSponsorship(newApplication.SponsorshipId); var sponsor = _sponsorApi.GetSponsor(sponsorship.SponsorId); sponsor.BursifyScore += 2; _sponsorApi.SaveSponsor(sponsor); var model = new StudentSponsorshipViewModel(); var applicationVm = model.MapSIngleStudentSponsorship(newApplication); var response = request.CreateResponse(HttpStatusCode.Created, applicationVm); return(response); }
public HttpResponseMessage SaveSponsor(HttpRequestMessage request, SponsorViewModel sponsor) { if (!ModelState.IsValid) { } _sponsorApi.SaveSponsor(sponsor.ReverseMap()); int userId = sponsor.ID; string[] location = sponsor.Location.Split(','); var address = new UserAddressViewModel(); address.BursifyUserId = userId; address.City = location[1]; address.Province = location[0]; address.AddressType = "Company"; _studentApi.SaveAddress(address.ReverseMap()); var response = request.CreateResponse(HttpStatusCode.Created); return(response); }