RefreshMode.ClientWins or StoreWins - entity-framework

I have a simple windows form application using Entity Framework, and i'm stucked in this situation:
-User opens a windowsform (SearchForm) inside the MDIform, displaying products details and their actual stock qty.
-User opens a second windowsform (POSForm) inside the MDIform (alongside SearchForm), and after selling productos, the stock of that product is updated to the new quantity and saved to the DB, at this moment, the other opened winform (SearchForm) must updates the displayed data with the new data, i'm trying reloading the context, reinstantiating the context, refreshing the form, but the form still shows the same data..
I have an eventhandler in SearchForm, that fires when i call a method RefreshData() from POSForm, and try to refresh the data, but nothing seems to change.
Just after closing that form (SearchForm) and then open it again, the data is displayed correctly.
I don't know how to do a good refresh (i'm using context.Refresh(RefreshMode.StoreWins,entry))

I would guess you have a screen refresh / datasource refresh issue not an EF issue.
Write debug code to dump Context content to be sure.

Related

Can concurrency cause StalePageException in wicket

We are facing StalePageException very frequently. I tried debugging on locally by adding debug point in getStoredPage() method just before this code and then i tried another request for same flow . The render count is not updated but on production i could see this issue.
Can any one help what is causing this and how can i reproduce .
if (renderCount != null && pageInstance.getRenderCount() != renderCount)
{
throw new StalePageException(pageInstance);
}
StalePageException is usually being thrown when the user opens several browser tabs/windows for the same page instance, for example by copy/pasting the current url from the address bar. Then making some more requests in one of the tabs and then trying to use one of the other tabs.
Wicket makes this check so that the user do not use a stale page instance. Imagine a page that shows the details of some entity. If the user deletes this entity in tab1 then (s)he should not be able to edit the same entity in another tab.

GWT panel fields data refresh delay on slow internet

I am using GWT 2.5.1.
In my GWT web app I have a ComplexPanel object which contains a set of fields(widgets). There are a suggested field (on panel) which gives me the opportunity to find object and info about it. Fields (10-15 of them) contain info about that object.
The problem is when user (client side) has a slow internet connection, fields on form are updated with a delay. And if in moment of delay user click 'Save' button (AsyncCallback), old data (which is not updated) posted to the server.
How it works:
1. Server receive callback from the form and start to processing the data.
2. Server refresh all the fields with new data and end the works.
3. Javascript updating the data on form using about 10 requests.
But: internet is slow and one part of data is refreshed and other no.
4. User click SAVE and mixed data goes to the server.
I need to know (from server side) when all the field are refreshed on client side and server can proceed with a next post request.
Thanks in any advice.
Perform a validation check on click of the save button. There are several things you can do as per your requirement. I have listed one way to validate it.
Set a flag before making the async call as false. For instance, isLoaded = false
Once you have all the fields just update it to true, i.e. isLoaded = true
On save button handler check for isLoaded flag. If false, prompt a message, else save.
Update:
You can count the number of response received. You know that you will get 10 response. So for every response received increment a counter. Activate save only if you have all 10 response recieved.
For a clean way to do this, use gwt-async-future.

Send new value to Google Tag Manager through dataLayer from fancybox (ajax)

I'm using GTM and I need sending several values for each web/product.
In a specific web I've a lightbox to get some data from user and need to send a "conversionValue" with a different value when the user finish the task.
When I try to do this by using dataLayer.push it just add a new object to the original dataLayer (as it is in a fancybox loaded by ajax, not iframe, it gets the "parent page" dataLayer), so I get a dataLayer with many objects and only the last one has the correct "conversionValue".
The problem is, if I try to use this variable from GTM, it gets the first object to look for the conversionValue...
Should I clear the dataLayer before pushing new objects? Am I doing it wrong? Is there any other way to do this?
After reading about Google Tag Manager, it doesn't matter if you add new objects to dataLayer because their variables can't be readed from GTM the same way as you read them for the first time.
You have to read new values by defining events.

Saving changes to DB made in a webpage

I rewrote the title and content 3 times before posting it, I don't find the right way to ask this :P
I have a page that manage a list of notes, I have a CRUD on that page but the items are created and saved in javascript (using knockoutjs).
I create a new note, I add it to the model in javascript and it show up in the page.
The way Im saving the notes to the database is when I add it to the model, I send it via Ajax (async) to the server. So I have my note on screen and in the database really fast.
I send a note without Id to the server and EF will take care of the Id.
So far so good.
Imagine that I add a note but I dont refresh the webpage, so the note is in the database, is in the javascript model too but in the model it doesn't have the id yet.
I make some changes to the note and yeah, I want to update the note in the database... but... how?
I send my note to the server with the changes, but remember, the item still have no Id so I can't say:
Hey EF, give me the note with the ID == xx and we are going to update that note.
The others properties can be changed on the webpage so I have nothing that identifies the note apart from the Id, who doesn't work here.
I tried this:
Send the new note to the server, insert it on the database, retrieve it again (to pick the Id), send it back to javascript and update the object with the Id. So when I edit, I have the Id. Yeah, but the "save" call need to be sync and that destroy the experience.
Any ideas?
EDIT: The sync options is not that slow at the end but there have to be a async way and meh, the thing of "Insert on database", "Retrieve the last item I inserted" and "return back to the client" is a little hackish.
You could return the id of the new record in your asynch call. If you are using jQuery you can subscribe to the "success" callback and as long as your controller returns a JSON with the id of the new record you could update your model on the client side.
Even with this approach, you will need to have a way to identify the item updated on the client side (which is really the root of your question.) For that you can probably generate a random GUID on the client side, send it to the server when saving, and return it to jQuery when returning the ID so that you can identify the correct element to update on the page.

ASP.NET MVC passing data between forms

Im pretty new to ASP.NET MVC, trying to figure out my way around.
Currently i return a ViewModel which has a IEnumeable Events as its only property. This ViewModel is StronglyTyped to a UserControl which dislays the IEnumable Events in tabular form.
One of the properties of the Event Model is an XElement, which contains some XML loaded from the DB.
Now i've added a link to the end of the tablular data to be able to view the XML in a separate page. How do i pass this data to another page for viewing?
I would post a request back to the server with some sort of Id for the Event-object and have the receiving end send back the XML related to that Id.
if you're looping through the Event objects in your IEnumerable, you can do something like:
<%= Html.ActionLink("GetXml", "Events", new { id = currentEvent.Id }) %>;
Now create an Action on your EventsController (given that you have one) like so:
public ActionResult GetXml(int id)
and retrieve the XML to pass back to the View
There are basically two ways of bringing data from one page to another using ASP.NET MVC (or any other language/framework which follows the HTTP protocol):
Sessions: Use a session to store the data you need, and load it back up at the next page.
Post the needed data back to the server. This way, the server can hold it and display it on the next page. Posted data usually comes from input or textarea elements. If you use input type="hidden" you can give it a value which represents your data. This way, you can post it back and forth till you arrive where you want.
Besides what Arve is advising, you could also consider TempData.
If you use the Get-Post-Redirect/Forward concept for you app, you could do something like:
GET - Initial Request comes in, Server responds with View and model data. User selects an item which leads to ...
POST - User selects one of the items from #1, triggering a post. That particular item can be fetched from repository, placed in TempData and then...
REDIRECT/FORWARD - The redirect collects the information out of TenpData and uses it as the model for the new View.
here is an example http://www.eworldui.net/blog/post/2008/05/08/ASPNET-MVC-Using-Post2c-Redirect2c-Get-Pattern.aspx