示例#1
0
        public bool CreateSpace(SpaceCreate model, string userID)
        {
            var newSpace = new Space {
                CategoryId   = model.CategoryId,
                OwnerId      = userID,
                CreatedAt    = DateTimeOffset.Now,
                Legal        = model.Legal,
                Status       = "vacant",
                MaxOccupancy = model.MaxOccupancy,
                Address      = model.Address,
                Name         = model.Name
            };

            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    ctx.Spaces.Add(newSpace);
                    return(ctx.SaveChanges() == 1);
                }
            }
            catch (Exception e)
            {
                SentrySdk.CaptureException(e);
                return(false);
            }
        }
        public async Task <Guid> CreateSpace(SpaceCreate spaceCreate)
        {
            SetupHttpClient();
            _logger.Information($"Creating Space: {JsonConvert.SerializeObject(spaceCreate, Formatting.Indented)}");
            var content  = JsonConvert.SerializeObject(spaceCreate);
            var response = await _httpClient.PostAsync("spaces", new StringContent(content, Encoding.UTF8, "application/json"));

            return(await GetIdFromResponse(response, _logger));
        }
示例#3
0
        public IHttpActionResult Post([FromBody] SpaceCreate model)
        {
            var user = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (_service.CreateSpace(model, user))
            {
                return(Ok());
            }
            return(InternalServerError());
        }
示例#4
0
        /// <summary>
        /// Create Creates the entity with the given properties.
        /// </summary>
        /// <exception cref="TrustPayments.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="entity">The space object with the properties which should be created.</param>
        /// <returns>ApiResponse of Space</returns>
        public ApiResponse <Space> CreateWithHttpInfo(SpaceCreate entity)
        {
            // verify the required parameter 'entity' is set
            if (entity == null)
            {
                throw new ApiException(400, "Missing required parameter 'entity' when calling SpaceService->Create");
            }

            var    localVarPath         = "/space/create";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json;charset=utf-8"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json;charset=utf-8"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (entity != null && entity.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(entity); // http body (model) parameter
            }
            else
            {
                localVarPostBody = entity; // byte array
            }


            this.Configuration.ApiClient.ResetTimeout();
            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)this.Configuration.ApiClient.CallApi(localVarPath,
                                                                                                 Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                 localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("Create", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Space>(localVarStatusCode,
                                           localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                           (Space)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Space))));
        }
示例#5
0
        /// <summary>
        /// Create Creates the entity with the given properties.
        /// </summary>
        /// <exception cref="TrustPayments.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="entity">The space object with the properties which should be created.</param>
        /// <returns>Space</returns>
        public Space Create(SpaceCreate entity)
        {
            ApiResponse <Space> localVarResponse = CreateWithHttpInfo(entity);

            return(localVarResponse.Data);
        }
示例#6
0
 public SpaceCreateCommand(SpaceCreate data, User user) : base(user)
 {
     Data = data;
 }