From 6ecaaff94d18e0f775751cad6e39f2268ce47318 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 22 Mar 2018 14:29:33 -0400 Subject: [PATCH] edit organization --- .../Controllers/OrganizationsController.cs | 25 + src/Admin/Models/OrganizationEditModel.cs | 127 ++++++ src/Admin/Views/Organizations/Edit.cshtml | 428 ++++++++++++++++++ src/Admin/Views/Organizations/Index.cshtml | 2 +- src/Admin/Views/Shared/_Layout.cshtml | 6 +- 5 files changed, 584 insertions(+), 4 deletions(-) create mode 100644 src/Admin/Models/OrganizationEditModel.cs create mode 100644 src/Admin/Views/Organizations/Edit.cshtml diff --git a/src/Admin/Controllers/OrganizationsController.cs b/src/Admin/Controllers/OrganizationsController.cs index 68e923724d..ac5ae9ac59 100644 --- a/src/Admin/Controllers/OrganizationsController.cs +++ b/src/Admin/Controllers/OrganizationsController.cs @@ -44,5 +44,30 @@ namespace Bit.Admin.Controllers Count = count }); } + + public async Task Edit(Guid id) + { + var organization = await _organizationRepository.GetByIdAsync(id); + if(organization == null) + { + return RedirectToAction("Index"); + } + + return View(new OrganizationEditModel(organization)); + } + + [HttpPost] + public async Task Edit(Guid id, OrganizationEditModel model) + { + var organization = await _organizationRepository.GetByIdAsync(id); + if(organization == null) + { + return RedirectToAction("Index"); + } + + model.ToOrganization(organization); + await _organizationRepository.ReplaceAsync(organization); + return RedirectToAction("Edit", new { id }); + } } } diff --git a/src/Admin/Models/OrganizationEditModel.cs b/src/Admin/Models/OrganizationEditModel.cs new file mode 100644 index 0000000000..b0a5bee9e8 --- /dev/null +++ b/src/Admin/Models/OrganizationEditModel.cs @@ -0,0 +1,127 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Bit.Core.Models.Table; + +namespace Bit.Admin.Models +{ + public class OrganizationEditModel + { + public OrganizationEditModel() { } + + public OrganizationEditModel(Organization org) + { + Organization = org; + Name = org.Name; + BusinessName = org.BusinessName; + BusinessAddress1 = org.BusinessAddress1; + BusinessAddress2 = org.BusinessAddress2; + BusinessAddress3 = org.BusinessAddress3; + BusinessCountry = org.BusinessCountry; + BusinessTaxNumber = org.BusinessTaxNumber; + BillingEmail = org.BillingEmail; + PlanType = org.PlanType; + Plan = org.Plan; + Seats = org.Seats; + MaxCollections = org.MaxCollections; + UseGroups = org.UseGroups; + UseDirectory = org.UseDirectory; + UseEvents = org.UseEvents; + UseTotp = org.UseTotp; + SelfHost = org.SelfHost; + UsersGetPremium = org.UsersGetPremium; + MaxStorageGb = org.MaxStorageGb; + Gateway = org.Gateway; + GatewayCustomerId = org.GatewayCustomerId; + GatewaySubscriptionId = org.GatewaySubscriptionId; + Enabled = org.Enabled; + LicenseKey = org.LicenseKey; + ExpirationDate = org.ExpirationDate; + } + + public Organization Organization { get; set; } + + [Required] + [Display(Name = "Name")] + public string Name { get; set; } + [Display(Name = "Business Name")] + public string BusinessName { get; set; } + [Display(Name = "Business Address 1")] + public string BusinessAddress1 { get; set; } + [Display(Name = "Business Address 2")] + public string BusinessAddress2 { get; set; } + [Display(Name = "Business Address 3")] + public string BusinessAddress3 { get; set; } + [Display(Name = "Business Country")] + public string BusinessCountry { get; set; } + [Display(Name = "Business Tax Number")] + public string BusinessTaxNumber { get; set; } + [Display(Name = "Billing Email")] + public string BillingEmail { get; set; } + [Required] + [Display(Name = "Plan")] + public Core.Enums.PlanType? PlanType { get; set; } + [Required] + [Display(Name = "Plan Name")] + public string Plan { get; set; } + [Display(Name = "Seats")] + public short? Seats { get; set; } + [Display(Name = "Max. Collections")] + public short? MaxCollections { get; set; } + [Display(Name = "Groups")] + public bool UseGroups { get; set; } + [Display(Name = "Directory")] + public bool UseDirectory { get; set; } + [Display(Name = "Events")] + public bool UseEvents { get; set; } + [Display(Name = "TOTP")] + public bool UseTotp { get; set; } + [Display(Name = "Self Host")] + public bool SelfHost { get; set; } + [Display(Name = "Users Get Premium")] + public bool UsersGetPremium { get; set; } + [Display(Name = "Max. Storage GB")] + public short? MaxStorageGb { get; set; } + [Display(Name = "Gateway")] + public Core.Enums.GatewayType? Gateway { get; set; } + [Display(Name = "Gateway Customer Id")] + public string GatewayCustomerId { get; set; } + [Display(Name = "Gateway Subscription Id")] + public string GatewaySubscriptionId { get; set; } + [Display(Name = "Enabled")] + public bool Enabled { get; set; } + [Display(Name = "License Key")] + public string LicenseKey { get; set; } + [Display(Name = "Expiration Date")] + public DateTime? ExpirationDate { get; set; } + + public Organization ToOrganization(Organization existingOrganization) + { + existingOrganization.Name = Name; + existingOrganization.BusinessName = BusinessName; + existingOrganization.BusinessAddress1 = BusinessAddress1; + existingOrganization.BusinessAddress2 = BusinessAddress2; + existingOrganization.BusinessAddress3 = BusinessAddress3; + existingOrganization.BusinessCountry = BusinessCountry; + existingOrganization.BusinessTaxNumber = BusinessTaxNumber; + existingOrganization.BillingEmail = BillingEmail; + existingOrganization.PlanType = PlanType.Value; + existingOrganization.Plan = Plan; + existingOrganization.Seats = Seats; + existingOrganization.MaxCollections = MaxCollections; + existingOrganization.UseGroups = UseGroups; + existingOrganization.UseDirectory = UseDirectory; + existingOrganization.UseEvents = UseEvents; + existingOrganization.UseTotp = UseTotp; + existingOrganization.SelfHost = SelfHost; + existingOrganization.UsersGetPremium = UsersGetPremium; + existingOrganization.MaxStorageGb = MaxStorageGb; + existingOrganization.Gateway = Gateway; + existingOrganization.GatewayCustomerId = GatewayCustomerId; + existingOrganization.GatewaySubscriptionId = GatewaySubscriptionId; + existingOrganization.Enabled = Enabled; + existingOrganization.LicenseKey = LicenseKey; + existingOrganization.ExpirationDate = ExpirationDate; + return existingOrganization; + } + } +} diff --git a/src/Admin/Views/Organizations/Edit.cshtml b/src/Admin/Views/Organizations/Edit.cshtml new file mode 100644 index 0000000000..d8ca67a31c --- /dev/null +++ b/src/Admin/Views/Organizations/Edit.cshtml @@ -0,0 +1,428 @@ +@model OrganizationEditModel +@{ + ViewData["Title"] = "Organization Edit: " + Model.Organization.Name; +} + +

Edit Organization @Model.Organization.Name

+ +
+

General

+
+
+
+ + +
+
+
+
+ + +
+

Business Information

+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+

Plan

+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+

Features

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+

Billing

+
+
+
+ + +
+
+
+
+
+ + +
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+

Licensing

+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
diff --git a/src/Admin/Views/Organizations/Index.cshtml b/src/Admin/Views/Organizations/Index.cshtml index b10c84d52f..e3f0001a44 100644 --- a/src/Admin/Views/Organizations/Index.cshtml +++ b/src/Admin/Views/Organizations/Index.cshtml @@ -43,7 +43,7 @@ { - @org.Name + @org.Name @org.Plan diff --git a/src/Admin/Views/Shared/_Layout.cshtml b/src/Admin/Views/Shared/_Layout.cshtml index 7d668d9e43..d0950f24fe 100644 --- a/src/Admin/Views/Shared/_Layout.cshtml +++ b/src/Admin/Views/Shared/_Layout.cshtml @@ -28,13 +28,13 @@