// PUT api/organization/5/locations public HttpResponseMessage Put(int id, ICollection<LocationVm> value) { this.OrganizationId = id; if (!this.UserIsAdminOfOrganization) { Request.CreateResponse(HttpStatusCode.Unauthorized); } var model = new Organization(); ICollection<Location> locationsModel = new List<Location>(); foreach (LocationVm vm in value) { locationsModel.Add(vm.ToModel()); } try { this.organizationService.SaveLocations(id, locationsModel); List<LocationVm> responseModel = new List<LocationVm>(); foreach (Location m in locationsModel) { responseModel.Add(LocationVm.FromModel(m)); } return Request.CreateResponse(HttpStatusCode.Accepted, responseModel); } catch(Exception e) { emailHelper.SendErrorEmail(e); } return Request.CreateResponse(HttpStatusCode.BadRequest); }
// PUT api/organization/additionalinformation/5 public HttpResponseMessage Put(AdditionalInformationOrganizationVm value) { var userId = webSecurityService.CurrentUserId; bool isAdmin = organizationService.IsAdminOfOrganization(userId, value.Id); if (!isAdmin) { return Request.CreateResponse(HttpStatusCode.Unauthorized); } var model = new Organization(); try { model.Id = value.Id; model.MissionStatement = value.MissionStatement; model.DonationDescription = value.DonationDescription; model.Pickup = value.Pickup; this.organizationService.SaveAdditionalInformation(model); return Request.CreateResponse(HttpStatusCode.Accepted); } catch (Exception e) { emailHelper.SendErrorEmail(e); } return Request.CreateResponse(HttpStatusCode.BadRequest); }
void IOrganizationService.SaveLogo(Organization organization) { //try find current user as admin int userGuid = this.userService.CurrentUserId; var admin = this.personService.GetUserAsAdmin(userGuid); if (admin != null) { this.organizationRepository.SaveLogo(organization); unitOfWork.Commit(); } }
void IOrganizationService.Save(Organization organization) { var end = DateTime.Now; var start = DateTime.Now; Debug.WriteLine("###Entering save service:: " + start); //try find current user as admin int userGuid = this.userService.CurrentUserId; var admin = this.personService.GetUserAsAdmin(userGuid); if (organization.Id == 0) { start = DateTime.Now; Debug.WriteLine("Insert org begin: " + start); //if not already admin, create a new one if (admin == null) { organization.Admin = new Admin(); organization.Admin.Person = this.personService.Get(userGuid); } //else, associated existing to the org else { organization.Admin = admin; } //if not already a subscription, create a new one if (organization.Subscription == null) { organization.Subscription = new Subscription(); OrganizationBudget priceTier = subscriptionService.GetPriceTier(organization.EIN); //TODO: Change this to zero whenever paid features are added organization.Subscription.Status = SubscriptionStatus.ACTIVE; organization.Subscription.PriceTier = priceTier; } this.organizationRepository.Insert(organization); //add user to administrator role (if new administrator) //this.userService.AddUserToRoles(user.UserName, "OrganizationAdmin"); end = DateTime.Now; Debug.WriteLine("Insert org toal: " + end.Subtract(start)); start = DateTime.Now; Debug.WriteLine("Email begin: " + start); this.emailHelper.SendOrganizationAdminWelcomeMail(organization.Admin.Person.FirstName, organization.Admin.Person.ContactInformation.Email1); end = DateTime.Now; Debug.WriteLine("Email toal: " + end.Subtract(start)); } else { if (admin != null) { this.organizationRepository.Update(organization); } } unitOfWork.Commit(); end = DateTime.Now; Debug.WriteLine("###Complete save time: " + end.Subtract(start)); }
public void testInvoiceSucceeds() { emailHelper.Setup(e => e.SendStripeInvoice(It.IsAny<StripeInvoice>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())); List<Organization> list = new List<Organization>(); var org = new Organization { Admin = new Admin { Id = 1, Person = new DomainModel.Core.Person { Id = 1, FirstName = "Ian", UserId = 1, ContactInformation = new DomainModel.Core.ContactInformation { Email1 = "*****@*****.**" } } }, Subscription = new DomainModel.Core.Organization.Subscription.Subscription { Last4Digits = "1234" } }; list.Add(org); subscriptionService.Setup(s => s.GetCustomerSubscription(It.IsAny<string>())).Returns(new DomainModel.Core.Organization.Subscription.SubscriptionDetails { CustomerId = "asd" }); organizationService.Setup(o=>o.Get(It.IsAny<Expression<Func<Organization, bool>>>(),null,null)).Returns(list.AsQueryable()); var eventController = new EventController(emailHelper.Object, subscriptionService.Object, organizationService.Object); HttpRequestMessage msg = new HttpRequestMessage(); eventController.Request = msg; eventController.Post(invoiceJson); }
private static OrganizationBudget FetchPriceTier(Organization organization) { //Your Annual Budget Is: Your Fee Is: //$0-200,000 $55 //$200,001 - 400,000 $110 //$400,001 - 700,000 $165 //$700,001 - 1,000,000 $220 //$1,000,001 - 2,000,000 //$330 $2,000,001 - 3,000,000 $440 //$3,000,001+ $600 return FindPriceTier(organization.Budget); }
OrganizationBudget ISubscriptionService.GetPriceTier(Organization organization) { return FetchPriceTier(organization); }
void ISubscriptionService.SaveSubscription(Organization organization) { organization.Subscription.PriceTier = FetchPriceTier(organization); this.organizationRepository.Update(organization); this.unitOfWork.Commit(); }
private static StripeCustomerUpdateSubscriptionOptions InitializeUpdateSubscriptionOptions(ApplicationModel.Billing.CustomerPayment payment, Organization organization) { var myCustomer = new StripeCustomerUpdateSubscriptionOptions(); // set these properties if using a card myCustomer.CardNumber = payment.CardNumber; //how is this coming in? myCustomer.CardExpirationYear = payment.CardExpirationYear; myCustomer.CardExpirationMonth = payment.CardExpirationMonth; myCustomer.CardAddressCountry = payment.CardAddressCountry; // optional myCustomer.CardAddressLine1 = payment.CardAddressLine1; // optional myCustomer.CardAddressLine2 = payment.CardAddressLine2; // optional myCustomer.CardAddressCity = payment.CardAddressCity; // optional myCustomer.CardAddressState = payment.CardAddressState; // optional myCustomer.CardAddressZip = payment.CardAddressZip; // optional myCustomer.CardName = payment.CardName; // optional myCustomer.CardCvc = payment.CardCvc; // optional // set this property if using a token myCustomer.PlanId = payment.PlanId; // only if you have a plan myCustomer.CouponId = (payment.CouponId != null && payment.CouponId != String.Empty) ? payment.CouponId : null; myCustomer.Prorate = true; if (organization.Subscription.HasTrialed) { // when the customers trial ends (overrides the plan if applicable) // Calculate what day of the week is 36 days from this instant. //System.DateTime today = DateTime.Now.ToUniversalTime(); //Add 3 hours to let Stripe update / account for timezone //System.TimeSpan duration = new System.TimeSpan(0, 2, 0, 0); //Set time in future //System.DateTime threeMinutesFromNow = today.Add(duration); //myCustomer.TrialEnd = threeMinutesFromNow; myCustomer.TrialEnd = null; } return myCustomer; }
internal static OrganizationVm FromModel(Organization organization) { if (organization.Admin == null) organization.Admin = new Admin(); List<NeededSubCategoryVm> subCategoriesForModel = new List<NeededSubCategoryVm>(); if (organization.NeededSubCategories != null) { foreach (var type in organization.NeededSubCategories) { subCategoriesForModel.Add(NeededSubCategoryVm.FromModel(type)); } } List<LocationVm> locationsForModel = new List<LocationVm>(); if (organization.Locations != null) { foreach (var type in organization.Locations) { locationsForModel.Add(LocationVm.FromModel(type)); } } return new OrganizationVm { Id = organization.Id, Admin = AdminVm.FromModel(organization.Admin), ContactInformation = ContactInformationVm.FromModel(organization.HeadquartersContactInformation), EIN = organization.EIN, Name = organization.Name, NeededSubCategories = subCategoriesForModel, Subscription = organization.Subscription, Locations = locationsForModel, Budget = organization.Budget, DonationDescription = organization.DonationDescription, MissionStatement = organization.MissionStatement, Pickup = organization.Pickup, PathToLogo = organization.PathToLogo }; }