SQL Transactions for E-Commerce? (Using .Net 3.5 for app) - tsql

I have an application I am working on that will need the use of transactions. I am familiar with how they work, but need some suggestions on a current implementation. Here is the scenario...
A user is working on a project in our system. In order to publish the project on our system, they must first pay some fees so the project can be published. When the user clicks publish they are then taken to a shopping cart. The shopping cart has two line items. The line items represent the costs associated with the publishing. When the payment goes through, I then run my stored procedures to update a porject and insert the order with the details. How I have it currently is not in a transaction. I have 3 separate SPs to handle the flow. First, the project data is updated, then an order is inserted, i then use the ID generated by the order insert to insert the data for the details. I am currently looping through the shopping cart and performing each detail insert separately.
I began to create a stored procedure that would execute all the stored procedures, but I got stumped with what to do about the order line items or details.
What is a good solution to bundle all of these tasks into one transaction?
Thanks
Daniel

System.Transactions are the way to go http://msdn.microsoft.com/en-us/library/ms973865.aspx
You can wrap your operations in a using statement then if anything goes wrong you just dont commit the transaction - very very simple

Related

SAPUI5 multiple users working on one table entry

I'm currently developing an application in the SAP BTP for multiple users. In the application you have one table where all responsibilities of a specific task are written down. These responsibilities may overlap between the users, which means that for one responsibility multiple users are mentioned.
In the application the users should click on either accept or reject if they still are responsible for this task. After they have given their feedback, they can click on a save button to write everything via a batch submit to the hana db. If they are not responsible anymore their name should be removed from the tasks and they should not see this task anymore.
The problem I am facing is that currently everything is stored in one database table and if one user gives feedback to some entries while another user works on the same entries, the user who saves his entries last will override the first one.
I have tried searching for a delta insert into the database or to live update after each user input or to lock the data when another user is currently working. But none of these seem to work fine, because users would still be able to override each others entries or they may lock some entries forever.
My question therefore is, what is the usual approach to manage multiple user inputs on a single table or is using a single table a bad practise at first?
My second question would be if sapui5 supports this approach or if I can handle this in another way?
You need to do server-side validation, before the save action.
UI5 does not support this directly, you can handle it by yourself.
Because we are stateless with ui5 / data you could use the draft concept
https://experience.sap.com/fiori-design-web/draft-handling/
Or something like already said backend logic with checks before safe.

Why am I seeing concurrentUpdateException during login?

Ours is a large ecommerce application built on ATG. On many sessions I'm seeing ConcurrentUpdateException during login itself, even if there was no other activity by the user recently. This is resulting in other exceptions while doing other activities.
Please do Check your transaction properly.
Following are the Best practice steps to update ATG Order
When you update the order Please follow the below steps.
Acquire transaction level lock.
Begin a transaction.
3- Synchronize the order.
Make changes to order.
Update order.
End synchronization.
End transaction.
Release lock.
Note: Avoid update order in commerce pipeline chains. It might lead to nested transaction.
Even Check any modifications on Order Manager component with mergeOrders method.

Getting updates in every blockchain append

I am working on an art project which desplays bitcoin transactions graphically.
Thus i need some way of getting an update when a transaction is filed in the blockchain.
Is there any way to accomplish this without copying the whole blockchain, since i do not need any precise information about the transaction?
If you are really want to get all the transactions that are happening, then you have to parse each new block that comes in. You have to look into the RPC Calls to get each individual block.
If you just want to watch certain addresses for transactions you can look into walletnotify of the bitcoind node.

Symfony2 - How can I limit the number of records an user can store?

I'm building a SaaS project using Symfony2, Doctrine2 and Postgresql. I have three different subscription plans, and for each plan there is a limit of members each user can store.
How can I limit a user to not store more members that the allowed for his subscription plan? Should I use a pre-persist event, counting the number of records belonging to her, and if there is an excess of records cancel the operation? Or this should be in the model or in the controller?
I recently had to build the same type of functionality for shouttag.com, where a user can only register X number of shouttags dependent upon their current billing plan. Granted, I am using Symfony/Doctrine 1.x, but the approach should be identical. Put the logic in the model layer, and whenever a user attempts to link a new member (via form save for example), issue a query for the user's current subscription plan, and how many members they currently have, if the resulting number is >= their allowed limit, then they cannot add more members until they change their subscription plan.
As an over-arching design goal you want to keep your controllers lean, and put most of your logic into your models (skinny controllers, fat models), this way the logic can be shared elsewhere throughout your code-base.

Core Data syncronization procedure with Web service

I'm developing an application that needs to be syncronized with remote database. The database is connected to the a web-based application that user able to modify some records on the web page.(add/remove/modify) User also able to modify the same records in mobile application. So each side (server - client) must be keep the SAME latest records when an user press the sync button in mobile app. Communication between server and client is provided by Web Serives.(SOAP) and i am not able to change it because of it is strict requirements. (i know this is the worst way that can be used). And another requirement is the clients are not able to delete the server records.
I already be familiar with communicating web service (NSURLConnection), receiving data (NSData) and parsing it. But i could not figure out how the syncronization procedure should be. I have already read this answer which about how i can modify server and client sides with some extra attributes (last_updated_date and is_sync)
Then i could imagine to solve the issue like:
As a first step, client keeps try to modify the server records with sending unsyncronized ones. New recoords are directly added into DB but modified records shoud be compared depending on last_updated_date. At the end of this step, server has the latest data.
But the problem is how can manage to modify the records in mobile app. I thought it in a two way:
is the dummiest way that create a new MOC, download all records into this and change with existing one.
is the getting all modified records which are not in client side, import them into a new MOC and combine these two. But in this point i have some concerns like
There could be two items which are replicated (old version - updated version)
Deleted items could be still located in the main MOCs.
I have to connect multiple relationships among the MOCs. (the new record could have more than 4 relationships with old records)
So i guess you guys can help me to have another ideas which is the best ??
Syncing data is a non-trivial task.
There are several levels of synchronization. Based on your question I am guessing you just need to push changes back to a server. In that case I would suggest catching it during the -save: of the NSManagedObjectContext. Just before the -save: you can query the NSManagedObjectContext and ask it for what objects have been created, updated and deleted. From there you can build a query to post back to your web service.
Dealing with merges, however, is far more complicated and I suggest you deal with them on the server.
As for your relationship question; I suggest you open a second question for that so that there is no confusion.
Update
Once the server has finished the merge it pushes the new "truth" to the client. The client should take these updated records and merge them into its own changes. This merge is fairly simple:
Look for an existing record using a uniqueID.
If the record exists then update it.
If the record does not exist then create it.
Ignoring performance for the moment, this is fairly straight forward:
Set up a loop over the new data coming in.
Set up a NSPredicate to identify the record to be updated/created.
Run your fetch request.
If the record exists update it.
If it doesn't then create it.
Once you get this working with a full round trip then you can start looking at performance, etc. Step one is to get it to work :)