Reuse my controller actions within an Windows Phone 7 application - c#

I'm developing an ASP.NET MVC 3 website that can manage my budget and expenses. It's almost done. So, I have my models, my views, repositories and controllers, and these two last have some important logic, about how to find and return searches and about business logic. OK, so far so good.
But, I'd like to develop and Windows Phone 7 App where I want to make avaiable some part of the features the site will offer, so I could use the exact same controller action that the ASP.NET MVC 3 site have, but I don't have a clue about how to do it.
I never worked with WP7 development, I know it is Silverlight-based, I know a little WPF and Silverlight, but I don't know how to glue my business logic that already exist in my controllers and repositories with the app. I know I can consume Web Services with Silverlight, but then I would have duplicated logic, in my actions and services? How I can handle this? Is there any resources that can help me through this learning process?
What I want, actually, is a way to reuse everything I already have, without duplicating the logic, or, at least, make only small adjustments.
Thanks for the help and sorry if my english isn't clear enough.

Try watching the video series The Full Stack on Channel 9. In the series they build an MVC site with a WP7 companion app.
http://channel9.msdn.com/Series/The-Full-Stack/The-Full-Stack-Part-1-Building-the-Admin-Site-with-ASPNET-MVC-3-NuPack-and-EF-Code-First

You should not program your business logic into your controller. Controllers are part of the user interface and setup the data for the views which are purely web based.
Therefore you cannot reuse your controllers in Silverlight, but you could use your business logic and implement a service interface for the Silverlight application which runs in the browser. If you used Entity Framework you could use the wcf services.
Before you start thinking about Silverlight you should learn XAML and WPF, then Silverlight and last but not least WP7 (which is mainly SL3 based plus some phone specific add-ons).
The other option you have: you use your web application and use the html interface on your phone 7 the same as on your webbrowser. The next release of phone 7 os supports html 5 as well.

Related

How can I implement the same models and data across ASP.NET and Windows Apps

Bit of a beginner question, but I'm currently building an ASP.NET MVC web app and I would like to transfer my models and data across to a Windows Universal App to begin with and then maybe a Xamarin app in the future.
Are there any good tutorials or blog posts out there that anyone can recommend that would help me. The idea is that the user will have the same experience across web and mobile so I don't want to hard code models for each client.
To do this you will need to split your domain model into different projects.
When you create your MVC application create a new C#/VB.NET assembly and place all of your models in the assembly. This way you can reuse the code across multiple projects.
Keep in mind that you shouldn't just dump code into this assembly take the time and create a proper namespace structure so that you don't confuse yourself or anyone else later on down the road.

C# windows form app to silverlight or asp

I am working on c# desktop windows form application using some 3rd/.net libraries and all forms are not WPF and no MVC.
I searched about this and I have some questions.
I'm expecting to change the whole gui code to wpf/XAML/ html forms.
I have two options now using asp or silverlight.
If I converted the project to asp/silverlight can I use the existing 3rd/.net libraries and I think I won't be able to get source code to recompile it?
knowing that the application contains tons lines of code and 6 projects in one solution.
what do you recommend for less effort?
and I can't use gizmox because its commercial license
If you are moving from a WinForms to a Web Server based architecture, I would definitely recommend the MVC route. Silverlight as a technology is a dead end and in addition would not allow you to reuse .net code without recompilation. Using MVC allows you to re-use your existing code, for good or for ill, in the server tier without recompilation. Even if you did use the Silverlight technology you could wrapper your existing libraries in a WCF service tier on the server and have Silverlight call it as web service.
However; the move to a web based architecture will require you to re-write a lot of your code (almost all the UX code will need to be scrapped) and this raises the question of what you are trying to achieve by moving to a web based architecture; so you need to consider both the costs and effort as being substantial - there are no quick ways to move from WinForms to Web, but depending on your business requirements you might consider using ClickOnce or XBAP to distribute your existing Windows application via a browser.

Is MVC is only for web applications

I want to create an application which i want to work both on web and windows for which i want to make seperate presentation layer. first of all i want to know, Is MVC is only for web applications?
By all means no. Check out this quote from http://blog.iandavis.com/2008/12/09/what-are-the-benefits-of-mvc/
The Model/View/Controller (MVC) triad of classes [first described by
Krasner and Pope in 1988] is used to build user interfaces in
Smalltalk-80.
When I was in graduate school we used MVC for Java apps...
Not necessarily only for web, depends on how you use it. It's just a framework that should work on both. Example, iOS development is also done on MVC style. But if you're using WPF/Silverlight, you should look at MVVM rather than MVC.
As far as i know MVC gives you more command over building the html. User MVC if you want a clean and more controlled html output. if you are developing a business application set-up a a solution and DAL and other business logics layers in class library type projects and then build separate user interfaces for both web and desktop. ASP.NET will be best if you don't want more control over output HTML.

Cross platform mobile HTML5 app with .NET / C# as the technology stack - pointers?

I'm trying to figure out various pieces that need to go into building for the mobile web with .NET / C#. I've so far been working mostly with native app development (iOS / Droid / B'Berry) and have very little experience with web development in general. But for the current project I'm working on, I believe a web-app is the way to go and would like to figure out what I pieces I need to get it working.
To give a brief overview of the application, our company uses SQL Server / .NET / VS for all of our web dev projects. The programmers here are familiar with this stack and I would like to keep it that way if possible. We're building a new product that needs a web + mobile view. The web view is currently being built as a separate project completely, but that can be changed if needed.
I'm just looking for some input on how to design something that handles screen resolutions, device types etc. and creates layouts appropriately in VS. Also, any best practices when trying to do this are much appreciated.
Thanks,
Teja.
handles screen resolutions, device types etc. and creates layouts appropriately
This is all presentation layer and shouldn't be a concern for any development framework. Sadly, it is. For instance, I'm currently working with a JSF team and so much of the presentation layer is produced via the JSF framework and it's a nightmare to maintain a sane presentation layer code base that way.
.net used to be that way too. Much of the early days of asp.net was full of invalid markup, bloated generated JS and the legendary postback cache tag.
Ideally, you'd have a presentation layer team that was independent of the particular framework. Mobile apps, more than anywhere, require the ability to maintain a lean, streamlined presentation layer and the best way to handle that is to let your team write their own HTML, CSS and JS as needed. I've worked with a C# team that was heavily using RESTful services that worked fairly well. We had built our own template framework and all HTML, CSS and JS was completely independent of the back end C#.
Fortunately, MS has gotten better and newer ways to implement via asp.net (such as the MVC model) can hopefully offer you better management of the presentation layer.

Sharing presentation logic between C# application with windows and web UIs

I need to build an application in C# that will have multiple UIs, 2 for web and one that will be the same application, but able to be used with no internet access. I am leaning towards MVC for web, then MVVM/WPF for the windows application (Silverlight is not an option). I should be able to inject a different repository implementation for the two paradigms, thus solving the disconnected-from-the-internet issue.
What I am wondering is how best to re-use as much presentation logic as possible. Ideally, I would like to be able to use the same controller/presenter-type entities to run both UIs. I'm looking for an example of a good solution to this problem. I don't see a clear path to re-using MVC's Controllers (they seem too tighly bound to the MVC framework to work), but at the same time I'm not excited about the overhead involved in implementing a custom MVVM or MVP pattern for the web (which I fear is the answer).
Alternatively, am I crazy to even try to re-use those components? Is it not worth the hassle? We can easily share the services underpinning the UIs, but it seems a shame to write such similar UI code twice.
The right thing to do is to share only the Business Layer and Database Access Layer. At least you will have consistency between all the clients.
Then build the clients taking advantage of the benefits of each platform (richness of the desktop app and simplicity in the web app)
Of course it all depends on the budget.
You have the option of using WPF for everything for max re-use. WPF can be deployed as partial trust XBAPs.
There are downsides though
* Download size can be a problem
* Clients need the correct framework version and can only run in Internet Explorer (Firefox through plugin (not working on Windows 7))
I've tried it on a solution with a small XBAP client and a larger Standalone Application - and it is really minor details that cannot be reused (Window in app, Page in XBAP and so on). Makes for nice consistent layout too.
This is slightly hackish (and not really recommended, unless you really understand what you are doing :)), but you could try creating a desktop app, which embeds a browser. This enables you to reuse the GUI. You will also need to package a web-server, which might be a problem though if you are using C#/MVC/.NET.

Categories

Resources