Esempio n. 1
0
        public IHttpActionResult Post(
            [FromBody] CreateTenantModel command)
        {
            if (command == null || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("Tenant body parameters missing"));
            }

            var dbProviderConfig = CreateDBProviderConfiguration(command);

            var tenant = Tenant.Create(0, command.Name, command.DefaultTheme, dbProviderConfig);

            _tenantsRepository.Add(tenant);
            _tenantsRepository.SaveChanges();

            return(Ok(_mapper.Map <TenantModel>(tenant)));
        }
Esempio n. 2
0
        public IHttpActionResult Post([FromUri] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!Request.Content.IsMimeMultipartContent())
            {
                return(StatusCode(HttpStatusCode.UnsupportedMediaType));
            }

            var multipartStreamProvider = Request.Content.ReadAsMultipartAsync().Result;
            var sContent = multipartStreamProvider.Contents.SingleOrDefault();

            if (sContent == null)
            {
                return(StatusCode(HttpStatusCode.NotAcceptable));
            }

            var user = _tenantsRepository.GetById(id);

            if (user == null)
            {
                return(NotFound());
            }

            var headers     = sContent.Headers;
            var previewFile = PreviewFile.Create(
                filename: headers.ContentDisposition?.FileName,
                contentType: headers.ContentType.MediaType,
                contentLength: headers.ContentLength,
                location: "tenants");

            using (var contentStream = sContent.ReadAsStreamAsync().Result)
            {
                _tenantsRepository.SetPreviewFile(entityId: id, previewFile, contentStream);
            }
            _tenantsRepository.SaveChanges();
            return(Ok());
        }