Beispiel #1
0
        public async Task <IActionResult> Patch(long id, [FromBody] OrganizationApi item)
        {
            ModelState.ClearValidationState("");

            // id is ignored. Insted CurrentPartitionId is used.

            var organization = await DbContext.Organizations.Where(o => o.Id == CurrentPartitionId).SingleOrDefaultAsync();

            if (organization == null)
            {
                return(new NotFoundResult());
            }

            if (!string.IsNullOrEmpty(item.Culture))
            {
                var culture = CultureInfo.GetCultureInfo(item.Culture);
                if (!SortingtimeCultures.IsSupported(culture.Name))
                {
                    ModelState.AddModelError("item.Culture", "Culture not supported.");
                    return(new BadRequestObjectResult(ModelState));
                }
            }

            await MapDeltaValuesAndCleanWhiteSpace(item, organization);

            if (!ModelState.IsValidUpdated())
            {
                return(new BadRequestObjectResult(ModelState));
            }

            await DbContext.SaveChangesAsync();

            return(Json(item));
        }
        private long CreateNewPartitionAndOrganizationForUser(ApplicationUser user, Plans plan, string demoOrganizationName = null, string demoOrganizationAddress = null)
        {
            var partition = Partition.CreateNew(plan);

            partition.CreatedByUserId = user.Id;
            dbContext.Partitions.Add(partition);
            var organization = new Organization {
                Partition = partition, Culture = SortingtimeCultures.CultureToFullCultureName()
            };

            if (organization.Culture.Equals("da-DK", StringComparison.OrdinalIgnoreCase))
            {
                organization.VatPercentage = 25;
            }
            if (plan == Plans.Demo)
            {
                organization.Name               = demoOrganizationName;
                organization.Address            = demoOrganizationAddress;
                organization.FirstInvoiceNumber = 1040;
            }
            dbContext.Organizations.Add(organization);
            dbContext.SaveChanges();
            return(partition.Id);
        }