Posts

Showing posts from 2016

Crud opetation with Angular js and web api or upload image

Image
Controller using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; using WebApplication4.DataModel; using WebApplication4.Models; namespace WebApplication4.Controllers {     public class ProductController : ApiController     {         testDBEntities db = new testDBEntities();         [HttpGet]         public IEnumerable<ProductModel> All()         {             return db.Products.Select(x => new ProductModel { Id = x.Id, Name = x.Name, Image = x.Image, Price = x.Price, CategoryId = x.CategoryId, SubCategoryId = x.SubCategoryId,IsActive=x.IsActive });         }         [HttpGet]         public ProductModel ProductById(int id)         {             return db.Products.Where(x=>x.Id==id).Select(x => new ProductModel { Id = x.Id, Name = x.Name, Image = x.Image, Price = x.Price, CategoryId = x.CategoryId, SubCategoryId = x.SubCategory

How to read data from html page / web scraping

Here I have a sample code but modify according requirement public ActionResult GetDetail(FormCollection form, string command)         {             try {             var userInfo = from user in webscrapinEntity.Login_Info                            select new                            {                                Name = user.UserName,                                id = user.Id                            };             SelectList list = new SelectList(userInfo, "id", "Name");             ViewBag.Roles = list;             int userId = Convert.ToInt16(Request.Form["users"]);             var u = webscrapinEntity.Login_Info.Find(userId);             var un = u.UserName;             var up = u.Password;             //    var st = DateTime.Parse(Request.Form["txtformdate"]);             //var ed = DateTime.Parse(Request.Form["txttodate"]);             var s = Request.Form["txtformdate"];             var l = Request.Form[&qu

How to call web service/web api with credential.

When call web service or web api some web service or web api is required authentication or access data or call the service. These service or web api's how to call with user name or password in asp.net. I am explain this with example in mvc application. Suppose you have username is "Admin", password is"Root@123" and your web service url is "https://apidomain.example.com/odata/v2/alldata('id')/?$format=json". First of all you create a controller and action where you call the web service. Like you create a action name is "Index" with task public async Task<ActionResult> Index(){ return view(); } After that you use the CredentialCache class to add the Credentials and the "Basic" authorization Below code of the snippet is the complete code for call a web service with credentials. public async Task<ActionResult> Index()         {             try             {                 var credentials = new NetworkCredential(&

WPF Custom Dictionary

Image
adding custom dictionary in wpf  MainWoindow.xaml file code <Window x:Class="WpfApplication2.MainWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:sys="clr-namespace:System;assembly=system"         Title="Custom Dictionaries Example">     <Grid Margin="0,0,0,-6">         <RichTextBox Name="RichTextBox1" HorizontalAlignment="Left" SpellCheck.IsEnabled="True" Height="77" Margin="31,8,0,0" VerticalAlignment="Top" Width="704">             <SpellCheck.CustomDictionaries>                 <sys:Uri>pack://application:,,,/dictionary.lex</sys:Uri>             </SpellCheck.CustomDictionaries>             <RichTextBox.ContextMenu>                 <ContextMenu></ContextMenu>