73 - Special Task List
73 - Special Task List
Special exercises :
1. Write a program to allow user to upload Excel file and read data from excel and store it
into database, columns are as follows.
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Excel_final.Models;
using Microsoft.AspNetCore.Http;
using OfficeOpenXml;
namespace Excel_final.Controllers
{
return View();
await file.CopyToAsync(stream);
var rowcount=worksheet.Dimension.Rows;
for(int row=2;row<=rowcount;row++)
list.Add(new Employees {
EmployeeID = worksheet.Cells[row,1].Value.ToString().Trim(),
});
dbContext.Employees.AddRange(list);
dbContext.SaveChanges();
return RedirectToAction("Index");
return View();
return View();
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Excel_final.Models
}
}
View
@{
<div class="container">
</form>
</div>
</div>
I.e. 2 lowercase, 1 upercase, 1 numeric, 2 special character etc where number should be
choose by user.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
{
// You can retrieve the password policy configuration from a database or a
configuration file
int lowercaseCount = 2;
int uppercaseCount = 1;
int numericCount = 1;
int specialCount = 2;
System.Text.RegularExpressions.Regex.IsMatch(password, specialRegex))
}
else
View
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>User Registration</title>
</head>
<body>
<div>
<h1>User Registration</h1>
<div>
</div>
<div>
</div>
<div>
</div>
</div>
</form>
</body>
</html>
PasswordRegex.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
Number of Special Characters: <asp:TextBox ID="txtSpecial"
runat="server"></asp:TextBox>
</div>
<div>
</div>
</div>
</form>
</body>
</html>
PasswordRegex.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
lblMessage.Visible = true;
}
3. Write a program to allow user to login with Google authenticator OTP code.
using FluentAssertions.Common;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using WebApplication1.Data;
var connectionString =
builder.Configuration.GetConnectionString("WebApplication1ContextConnection") ?? throw new
InvalidOperationException("Connection string 'WebApplication1ContextConnection' not found.");
builder.Services.AddDbContext<WebApplication1Context>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDefaultIdentity<IdentityUser>(options =>
options.SignIn.RequireConfirmedAccount =
true).AddEntityFrameworkStores<WebApplication1Context>();
builder.Services.AddAuthentication().AddGoogle(googleOptions =>
googleOptions.ClientSecret = configuration["Authenticaation:Google:ClientSecret"];
});
builder.Services.AddControllersWithViews();
if (!app.Environment.IsDevelopment())
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see
https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run()