Posts

DotVVM CRUD application with Cloud Firestore

Image
In previous post we demonstrated how to use DotVVM to create CRUD application with Azure Cosmos DB as your data store. In this post we will demonstrate how to do the same with Cloud Firestore by Google. To know more about DotVVM Framework you can check its official website What is Cloud Firestore? Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform. It keeps your data in sync across client apps through realtime listener and offers offline support for mobile and web apps. You can know more about Cloud Firebase here . Install DotVVM extension refer to  previous post  and follow the steps. To know more about the DotVVM extension visit its page on visual studio marketplace: https://marketplace.visualstudio.com/items?itemName=TomasHerceg.DotVVM-VSExtension2019 Now you are ready to start coding with DotVVM framework. DotVVM extension installs DotVVM sample project which we will...

DotVVM CRUD application with Entity Framework and Cosmos DB

Image
What is DotVVM? DotVVM is open source MVVM framework for ASP.Net Core and OWIN and it is member of .NetFoundation . DotVVM is a free to use under Apache License but also have commercial extensions. DotVVM lets you build interactive web UIs with just C# and HTML using MVVM pattern. DotVVM framework is shipped with many build-in controls like GridView , FileUpload , Validators , and more. Why DotVVM? There are many reason and business scenarios that DotVVM is suitable for and very helpful like:  Migrating legacy ASP.Net web forms application to .Net Core. New ASP.Net applications that contains many forms with a lot of controls/components. To learn more about DotVVM framework visit DotVVM.com . What is Azure Cosmos DB? Azure Cosmos DB is a NoSQL distributed and fully managed database service. Azure Cosmos DB provides different API for different NoSQL models like Document databases, Column databases, Graph databases and Key-Value database. ...

Clean your JSON object before saving into Cloud Firestore database

If you have a registration form and you are collecting user's inputs to json object like user = {   'first_name' : 'Amir',   'middle_name':'',   'last_name':'Ismail'   'age' : 25,   'address' : '',   'phone':null }; notice middle_name , address , and phone fields have no value (empty string and null). If you want to save this in Cloud Firestore database, these fields will be saved which is not recommended because you are losing one of the advantages of  NoSQL document database which any document should contain only fields have value (except your business case requires that field to be exist in all documents even has no value) . To remove empty fields you have to check each input value and save only fields that have value. But if you have big form with many input fields or you have many forms checking each fields will be a nightmare and your code will be dirty. So I tried to write a TypeScrip...

ASP.Net MVC : ActionLink with bootstrap icon

Image
How many times you wanted to add an icon to your action link?!. using Html.ActionLink method is not possible to add icon as it renders the link with just HtmlAttribute you provide. ex : @Html.ActionLink("My Link","actionName","controllerName",new {id = Model.Id}, new {style="margin:10px", @class="btn btn-info"}); this will be rendered as shown in   if I want to add icon using bootstrap css classes, I can not use HtmlHelper methods and have to use plain html tags like this <a href="url-here" class="btn btn-info" style="margin:10px;">         <i class="glyphicon glyphicon-pencil"></i>         <span>My Link</span>     </a> this will be rendered  as so to simplify my .cshtml file and make it easy for developers to add icon to their action links, I have created an extension method IconActionLink that will replace the previous html sinppe...

AutoComplete using customized UIHint attribute in ASP.Net MVC

Image
In one project I worked on recently, I wanted to display list of suppliers which is very very long list, it was more than 6000 items. to display such number of items in dropdown list in a page of course will affect page load time. The best solution was using Autocomplete jQuery plugin , it is light, powerful, and covers my needs but unfortunately I need to display that suppliers list in many pages for different view models. One of possible solutions copy/paste autocomplete code snippet in each view.This solution didn't make me satisfied and I thought of course there is better way and more elegant to do it. One possible alternative is Editor Template, in most cases we need the Id value not the item full details. for simplicity I'm using list of programming languages as a data source. I override UIHint attribute to pass the URL of our datasource, the URL will be used as source for autocomplete jQuery plugin. public class AutoCompleteUIHintAttribute : UIHintAttribute {...

5 Tips to Improve ASP.NET Application Performance

Web application is designed to handle hundreds and thousands of requests per seconds so to handle these requests effectively and successfully it is important to resolve any potential performance bottlenecks. Now we will state some tips that improve the performance of your web application. 1 - Cache Commonly used objects You can cache commonly used objects in ASP.Net using Cache class that provides an extensive caching mechanism that storing resources and allow you to: Define an expiration for a cached object either by specified a TimeSpan or a fixed DateTime . Define priority for cached objects. when there is a memory lack and objects need to be freed. Define validity for a cached object by adding dependacies Attach callbacks to cached objects,so when an objects is removed from cache the callback is invoked. you can add objects to cache by adding it to cache  Dictionary Cache["Mykey"] = myObject; or using Insert method of Cache class Cache.Insert("MyKe...

Android : How to change progress bar color at runtime programmatically?

Image
I faced this problem while creating one of my android applications(in fact, it is my first application :) ). Lets consider we want to create an android application to calculate the commitments progress of a certain category for http://area51.stackexchange.com/  website ( note we will display a progress bar with one color red or green for simplicity ). Each time we run this application it calculate the commitment percentage and display a red progress bar if it is less than 50% or green one if it equal or greater than 50%. For learning purpose we will insert the number of total required committed users and the number of committed users and calculate the progress of commitment process. Now lets write our code. If it is your first android application you can refer to this post to know how to create an android application.        How to create the full layout of this simple application is beyond this post, we will concentrate on the progress bar....

ASP.Net MVC : Conditional Validation using ValidationAttribute

In ASP.Net MVC we can validate each input field by decorating the corresponding property in the model class with some validation attributes like Required , MaxLength , MinLength ,...etc. Sometime we need to validate a property according to another property value for example if we have a registration form and we need the user enter his age if he is a male and age not required if the user sex is female. So if we decorated the Age property with Required attribute it will show error message even if the user is female, so we need to bypass this check with females. Assume our registration form will contains three fields, name, sex and age, and its model will be as follows public class RegisterationModel { [Required(ErrorMessage = "*")] public String Name { get; set; } [Required(ErrorMessage = "*")] [Display(Name = "Gender")] public Sex Sex { get; set; } [RequiredIf("Sex", Sex.Male, "enter your age")] pu...

Restrict non-ajax requests using ActionMethodSelectorAttribute

In ASP.Net MVC each coming request is routed to a certain action method inside some controller and with JQuery it became piece of cake to call this action method using ajax. In some scenarios we need to restrict the incoming requests to be ajax request only, fortunately ASP.Net MVC represent a new method to Request object called IsAjaxRequest() that return true if the current request come from ajax call and return false if current request is normal request(typing url in address bar of a browser, click a link to this page,..etc). We can use that method to deny any request come from ajax call or vise versa. public class HomeController { public ActionResult Index() { if(Request.IsAjaxRequest()) { //Do something } else { //Do something else } } } As we see if we need to make this check many times in our project, we will rewrite the same if statement for each action we need it be called via ajax only, but is there anot...

How to create android application?

Image
We have already showed how to prepare your machine to develop your android application  now it is the time to check if we prepared our machine successfully and we can write our first android application or not. We will start learning developing android application by writing a simple application that will display "Hello World" sentence (the most famous example to start learning new tech). Follow the next steps to create your first android application: Lunch Eclipse and select File > New > Project you will find a list of available projects templates select  android project template then click next, you will see window like this   Application Name : the name of your applications that will be appear on application list of your device(mobile or tablet) Project Name : the name that will be appear in your eclipse work-space. Packaeg Name : it will be used as identifier for your application and must be unique across all applications. Build SDK : specify...

Fundamental components of android application

This post is a one of some posts about android platform I will write to explore this platform and learn you(and me) developing android applications for mobiles and tablets devices. You don't have to own android mobile to create android application, what is you really need is a tool (Emulator) to test and debug your application. You can refer to this post  where I showed how to prepare your machine to be able to create your android application. That post was written before releasing Ice Cream Sandwich  version (android 4.x) but it does not matter, just you should download the latest version of all tools you have to install. My reference for writing these posts is Pro Android 4 book. In this post we will explore the key components of android framework which we must understand before delving into coding process. View: views are user interface(UI) elements such as buttons, labels, text fields, or any other UI element. Views also can contain other views. Anyth...

Load partial page in jquery and ASP.Net MVC

In this post I will show you how much ASP.Net MVC and JQuery are making up a dangerous duet and how you can do big tasks in simple way with little efforts. We can take a look at a live example of what we will do in this post. In stackoverflow website specially users page and tags page you will find a text box to search users/tags. the page is loaded with some users info sorted with default setting. if you start to write something in that text box, the users collection will be filtered by the name you entered in ajax manner and ordered alphabetically(ascending). The issue here is how using the same piece of code that produce the whole page when it be loaded in first time to filter the users when you type some letters in the text box and update just the part that display the users data. Here the magic of ASP.Net MVC and  JQuery  come to the scene. Lets start to build our page first then start to filter our users collection. I will not show you how to cr...