public int AddTopping(ATopping topping) { var mapped = mapper.Map(topping); context.Add(mapped); context.SaveChanges(); return(mapped.ToppingId); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body"> (optional)</param> /// <returns>ApiResponse of Object(void)</returns> public ApiResponse <Object> ApiToppingPostWithHttpInfo(ATopping body = null) { var localVarPath = "/api/Topping"; 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-patch+json", "application/json", "text/json", "application/_*+json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (body != null && body.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // 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("ApiToppingPost", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)), null)); }
public Topping Map(ATopping topping) { return(new Topping { ToppingId = topping.ToppingId, ToppingName = topping.ToppingName, ToppingPrice = topping.ToppingPrice }); }
public void UpdateTopping(ATopping newItem) { var oldItem = context.Toppings.Find(newItem.ToppingId); if (oldItem != null) { oldItem.ToppingName = newItem.ToppingName; oldItem.ToppingPrice = newItem.ToppingPrice; context.SaveChanges(); } }
public IActionResult Put([FromBody] ATopping x) { try { if (x == null) { return(BadRequest("Data is invalid or null")); } _repository.UpdateTopping(x); return(NoContent()); } catch (Exception e) { return(StatusCode(400, e.Message)); } }
public IActionResult Post([FromBody] ATopping topping) { if (topping == null) { return(BadRequest("The topping you are trying to add is empty")); } else { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { repository.Add(topping); return(CreatedAtAction(nameof(Get), new { id = topping.ID }, topping)); } } }
public IActionResult Put(int id, [FromBody] ATopping topping) { if (topping == null) { return(NoContent()); } else { if (!ModelState.IsValid) { return(NoContent()); } else { topping.ID = id; repository.Update(topping); return(CreatedAtAction(nameof(Get), new { id = topping.ID }, topping)); } } }
public static ATopping[] pickToppings() { string toppingDec; ATopping[] toppings = new ATopping[5]; Console.WriteLine("press 0 to exit the toppings menu."); for (int i = 0; i < 5; i++) { printList(_toppingSingleton.toppings); toppingDec = Console.ReadLine(); toppingDec = inputCheck(toppingDec, 0, _toppingSingleton.toppings.Count); if (toppingDec == "0") { break; } toppings[i] = _toppingSingleton.toppings[int.Parse(toppingDec) - 1]; Console.WriteLine("if that is enough toppings, press 0 to exit."); } return(toppings); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body"> (optional)</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task ApiToppingPostAsync(ATopping body = null) { await ApiToppingPostAsyncWithHttpInfo(body); }
public void AddTopping(ATopping topping) { context.Add(mapper.Map(topping)); context.SaveChanges(); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body"> (optional)</param> /// <returns></returns> public void ApiToppingPost(ATopping body = null) { ApiToppingPostWithHttpInfo(body); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="body"> (optional)</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <ApiResponse <Object> > ApiToppingIdPutAsyncWithHttpInfo(int?id, ATopping body = null) { // verify the required parameter 'id' is set if (id == null) { throw new ApiException(400, "Missing required parameter 'id' when calling ToppingApi->ApiToppingIdPut"); } var localVarPath = "/api/Topping/{id}"; 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-patch+json", "application/json", "text/json", "application/_*+json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (id != null) { localVarPathParams.Add("id", this.Configuration.ApiClient.ParameterToString(id)); // path parameter } if (body != null && body.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath, Method.PUT, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ApiToppingIdPut", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)), null)); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="body"> (optional)</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task ApiToppingIdPutAsync(int?id, ATopping body = null) { await ApiToppingIdPutAsyncWithHttpInfo(id, body); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="body"> (optional)</param> /// <returns></returns> public void ApiToppingIdPut(int?id, ATopping body = null) { ApiToppingIdPutWithHttpInfo(id, body); }
public void Test_ToppingName(ATopping Topping) { Assert.NotNull(Topping.Name); Assert.Equal(Topping.Name, Topping.ToString()); }
public void Put(int id, [FromBody] ATopping value) { value.ID = id; repo.Update(value); }
public void Post([FromBody] ATopping value) { repo.Add(value); }