public IActionResult SetTariff(TariffModel model) { if (!CommonMethods.GetTenant(model, out Tenant tenant)) { Log.Error("Model without tenant"); return(BadRequest(new { error = "portalNameEmpty", message = "PortalName is required" })); } if (tenant == null) { Log.Error("Tenant not found"); return(BadRequest(new { error = "portalNameNotFound", message = "Portal not found" })); } var quota = new TenantQuota(tenant.TenantId) { ActiveUsers = 10000, Features = model.Features ?? "", MaxFileSize = 1024 * 1024 * 1024, MaxTotalSize = 1024L * 1024 * 1024 * 1024 - 1, Name = "api", }; if (model.ActiveUsers != default) { quota.ActiveUsers = model.ActiveUsers; } if (model.MaxTotalSize != default) { quota.MaxTotalSize = model.MaxTotalSize; } if (model.MaxFileSize != default) { quota.MaxFileSize = model.MaxFileSize; } HostedSolution.SaveTenantQuota(quota); var tariff = new Tariff { QuotaId = quota.Id, DueDate = model.DueDate != default ? model.DueDate : DateTime.MaxValue, }; HostedSolution.SetTariff(tenant.TenantId, tariff); return(GetTariff(tenant)); }
public IActionResult SetTariff(TariffModel model) { if (model == null) { return(BadRequest(new { errors = "PortalName is required." })); } if (!ModelState.IsValid) { var errors = new JArray(); foreach (var k in ModelState.Keys) { errors.Add(ModelState[k].Errors.FirstOrDefault().ErrorMessage); } return(BadRequest(new { errors })); } var tenant = HostedSolution.GetTenant((model.PortalName ?? "").Trim()); if (tenant == null) { return(BadRequest(new { errors = "Tenant not found." })); } var quota = new TenantQuota(tenant.TenantId) { ActiveUsers = 10000, Features = model.Features ?? "", MaxFileSize = 1024 * 1024 * 1024, MaxTotalSize = 1024L * 1024 * 1024 * 1024 - 1, Name = "api", }; if (model.ActiveUsers != default) { quota.ActiveUsers = model.ActiveUsers; } if (model.MaxTotalSize != default) { quota.MaxTotalSize = model.MaxTotalSize; } if (model.MaxFileSize != default) { quota.MaxFileSize = model.MaxFileSize; } HostedSolution.SaveTenantQuota(quota); var tariff = new Tariff { QuotaId = quota.Id, DueDate = model.DueDate != default ? model.DueDate : DateTime.MaxValue, }; HostedSolution.SetTariff(tenant.TenantId, tariff); tariff = HostedSolution.GetTariff(tenant.TenantId, false); quota = HostedSolution.GetTenantQuota(tenant.TenantId); return(Ok(new { errors = "", tenant = ToTenantWrapper(tenant), tariff = ToTariffWrapper(tariff, quota) })); }