/// <summary> /// Allows the REST API to create or update a transaction. /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the transaction ID (bvin) and that this is an update, otherwise it assumes to /// create a new transaction. /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the OrderTransacionDTO object</param> /// <returns>CategoryDTO - Serialized (JSON) version of the transaction</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var bvin = FirstParameter(parameters); var response = new ApiResponse <OrderTransactionDTO>(); OrderTransactionDTO postedItem = null; try { postedItem = Json.ObjectFromJson <OrderTransactionDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } var item = new OrderTransaction(); item.FromDto(postedItem); var existing = HccApp.OrderServices.Transactions.Find(item.Id); if (existing == null || item.Id == Guid.Empty) { item.StoreId = HccApp.CurrentStore.Id; item.Id = Guid.NewGuid(); HccApp.OrderServices.Transactions.Create(item); } else { item.StoreId = HccApp.CurrentStore.Id; HccApp.OrderServices.Transactions.Update(item); } var resultItem = HccApp.OrderServices.Transactions.Find(item.Id); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = Json.ObjectToJson(response); return(data); }
// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string bvin = FirstParameter(parameters); ApiResponse <OrderTransactionDTO> response = new ApiResponse <OrderTransactionDTO>(); OrderTransactionDTO postedItem = null; try { postedItem = MerchantTribe.Web.Json.ObjectFromJson <OrderTransactionDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(MerchantTribe.Web.Json.ObjectToJson(response)); } OrderTransaction item = new OrderTransaction(); item.FromDto(postedItem); OrderTransaction existing = MTApp.OrderServices.Transactions.Find(item.Id); if (existing == null || item.IdAsString == "00000000-0000-0000-0000-000000000000") { item.StoreId = MTApp.CurrentStore.Id; item.Id = System.Guid.NewGuid(); MTApp.OrderServices.Transactions.Create(item); } else { item.StoreId = MTApp.CurrentStore.Id; MTApp.OrderServices.Transactions.Update(item); } OrderTransaction resultItem = MTApp.OrderServices.Transactions.Find(item.Id); if (resultItem != null) { response.Content = resultItem.ToDto(); } data = MerchantTribe.Web.Json.ObjectToJson(response); return(data); }