Subscribe Us

LightBlog

Monday, 27 July 2020

July 27, 2020

CRUD Operations using MVC scaffolding with LINQ to SQL

In this article,I will show you CRUD operations using mvc scaffolding with linq to sql.

---Table Script---
create table Employee
(
   id int primary key identity(1,1),
   name varchar(50),
   salary decimal(18,2)
)

Here must add package in project solution :
   System.Data.Linq

---Model Class---
[Table]
public class Employee
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true)]
    public int id { get; set; }
    [Column]
    public string name { get; set; }
    [Column]
    public decimal salary { get; set; }
}

---employee controller--
DataContext dc = new DataContext("Data Source=.;Initial Catalog=TESTDB;Integrated Security=True");

public ActionResult Index()
{
    IEnumerable<Employee> emp_data = dc.GetTable<Employee>();
    return View(emp_data);
}

public ActionResult Create()
{
    return View();
}

[HttpPost]
public ActionResult Create(Employee emp)
{
    dc.GetTable<Employee>().InsertOnSubmit(emp);
    dc.SubmitChanges();
    return RedirectToAction("Index");
}

[HttpGet]
public ActionResult Edit(int id)
{
    Employee emp = dc.GetTable<Employee>().Single(x => x.id == id);
    return View(emp);
}

[HttpPost]
public ActionResult Edit(Employee empobj)
{
    Employee emp = dc.GetTable<Employee>().Single(x => x.id == empobj.id);
    UpdateModel(emp);
    dc.SubmitChanges();
    return RedirectToAction("Index");
}

[HttpGet]
public ActionResult Delete(int id)
{
    Employee emp = dc.GetTable<Employee>().Single(x => x.id == id);
    return View(emp);
}

[HttpPost]
public ActionResult Delete(Employee empobj)
{
    Employee emp = dc.GetTable<Employee>().Single(x => x.id == empobj.id);
    dc.GetTable<Employee>().DeleteOnSubmit(emp);
    dc.SubmitChanges();
    return RedirectToAction("Index");
}

Note: Accoding to action method you can add scaffolding templet on view.

Thursday, 9 July 2020

July 09, 2020

How to Binding local data in Event Scheduler in Angular 7 ?

- app.component.html
<router-outlet></router-outlet>

- app.component.ts
import { Component } from '@angular/core';
import { EventSettingsModel, DayService, WeekService, WorkWeekService, MonthService, AgendaService } from '@syncfusion/ej2-angular-schedule';

@Component({
  selector: 'app-root',
  providers: [DayService, WeekService, WorkWeekService, MonthService, AgendaService],
  // specifies the template string for the Schedule component
  template: `<ejs-schedule width='100%' height='550px' 
  [selectedDate]='selectedDate' [eventSettings]='eventSettings'></ejs-schedule>`
})
export class AppComponent {
    public selectedDate: Date = new Date(2028, 1, 15);
    public eventSettings: EventSettingsModel = {
        dataSource: [
        {
            Id: 1,
            Subject: 'Explosion of Betelgeuse Star',
            StartTime: new Date(2018, 1, 15, 9, 30),
            EndTime: new Date(2018, 1, 15, 11, 0)
        }, {
            Id: 2,
            Subject: 'Thule Air Crash Report',
            StartTime: new Date(2018, 1, 12, 12, 0),
            EndTime: new Date(2018, 1, 12, 14, 0)
        }, {
            Id: 3,
            Subject: 'Blue Moon Eclipse',
            StartTime: new Date(2018, 1, 13, 9, 30),
            EndTime: new Date(2018, 1, 13, 11, 0)
        }]
    };
 }

- app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ScheduleModule } from '@syncfusion/ej2-angular-schedule';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { DayService, WeekService, WorkWeekService, MonthService, AgendaService, MonthAgendaService} from '@syncfusion/ej2-angular-schedule';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ScheduleModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [DayService, 
                WeekService, 
                WorkWeekService, 
                MonthService,
                AgendaService,
                MonthAgendaService]
})
export class AppModule { }

-app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';


const routes: Routes = [];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
Note:

Setup Angular Environment
You can use Angular CLI to setup your Angular applications. To install Angular CLI use the following command.
npm install -g @angular/cli

Create an Angular Application
Start a new Angular application using below Angular CLI command.

ng new my-app
cd my-app

Adding Syncfusion Schedule package
To install Schedule component, use the following command.
npm install @syncfusion/ej2-angular-schedule --save
                        

Wednesday, 1 July 2020

July 01, 2020

QRCode and Barcode generate in ASP.NET MVC

In this article, i will show you how to generate QRCode and Barcode in  ASP.NET MVC
  • Add this two packages QRCoder and GenCode128
         #region QR Code Generation 
        public ActionResult GetQRCodeImage(string qrcode)
        {
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrcode,
            QRCodeGenerator.ECCLevel.Q);
            QRCode qrCode = new QRCode(qrCodeData);
            Bitmap qrCodeImage = qrCode.GetGraphic(20);
            ImageConverter converter = new ImageConverter();
            byte[] img = (byte[])converter.ConvertTo(qrCodeImage, typeof(byte[]));
            return new FileStreamResult(new System.IO.MemoryStream(img), "image/jpeg");
        }
        #endregion

        #region Bar Code Generation
        public ActionResult GetBarcodeImage(string brcode)
        {
            Image myimg = Code128Rendering.MakeBarcodeImage(brcode, int.Parse("2"), true);
            ImageConverter converter = new ImageConverter();
            byte[] img = (byte[])converter.ConvertTo(myimg, typeof(byte[]));
            return new FileStreamResult(new System.IO.MemoryStream(img), "image/jpeg");
        }
        #endregion

QRCode
QRCode
Code128
GenCode128