USE [EMPRecordAllDb]
GO
/****** Object: Table [dbo].[Cities] Script Date: 01-12-2024 20:57:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Cities](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](max) NOT NULL,
[StateId] [int] NOT NULL,
CONSTRAINT [PK_dbo.Cities] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Cities] WITH CHECK ADD CONSTRAINT [FK_dbo.Cities_dbo.States_StateId] FOREIGN KEY([StateId])
REFERENCES [dbo].[States] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Cities] CHECK CONSTRAINT [FK_dbo.Cities_dbo.States_StateId]
GO
USE [EMPRecordAllDb]
GO
/****** Object: Table [dbo].[Countries] Script Date: 01-12-2024 20:58:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Countries](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_dbo.Countries] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
USE [EMPRecordAllDb]
GO
/****** Object: Table [dbo].[States] Script Date: 01-12-2024 20:58:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[States](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](max) NOT NULL,
[CountryId] [int] NOT NULL,
CONSTRAINT [PK_dbo.States] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[States] WITH CHECK ADD CONSTRAINT [FK_dbo.States_dbo.Countries_CountryId] FOREIGN KEY([CountryId])
REFERENCES [dbo].[Countries] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[States] CHECK CONSTRAINT [FK_dbo.States_dbo.Countries_CountryId]
GO
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace curdMVC5DD.Models
{
public class City
{
[Key]
public int Id { get; set; }
[Required(ErrorMessage = "Required Field")]
public string Name { get; set; }
[Required(ErrorMessage = "State is required.")]
public int StateId { get; set; } // Foreign key property
[ForeignKey("StateId")]
public State State { get; set; } // Navigation property
}
}
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace curdMVC5DD.Models
{
public class Country
{
[Key]
public int Id { get; set; }
[Required(ErrorMessage = "Required Field")]
public string Name { get; set; }
}
}
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace curdMVC5DD.Models
{
public class State
{
[Key]
public int Id { get; set; }
[Required(ErrorMessage = "Required Field")]
[DisplayName("State Name")]
public string Name { get; set; }
[Required(ErrorMessage = "Country is required.")]
[DisplayName("Contry Name")]
public int CountryId { get; set; }
[ForeignKey("CountryId")]
public Country Country { get; set; }
}
}
using curdMVC5DD.DatabaseContext;
using curdMVC5DD.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace curdMVC5DD.Controllers
{
public class CountriesStateCitiesController : Controller
{
// GET: CountriesStateCities
EMPContext db = new EMPContext();
// Country Related
public ActionResult Index()
{
return View(db.Countries.OrderBy(x => x.Name).ToList());
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Country country)
{
if (ModelState.IsValid)
{
if (country != null)
{
db.Countries.Add(country);
int affected = db.SaveChanges();
if (affected > 0)
{
TempData["success"] = "Successfully Added";
ModelState.Clear();
return RedirectToAction("Index");
}
else
{
ViewBag.success = "SuccessFully Added";
}
}
}
return View();
}
[HttpGet]
public ActionResult Details(int id)
{
var dataRow = db.Countries.Find(id);
return View(dataRow);
}
[HttpGet]
public ActionResult Edit(int id)
{
var dataRow = db.Countries.Find(id);
return View(dataRow);
}
[HttpPost]
public ActionResult Edit(Country country, int id)
{
if (ModelState.IsValid)
{
if (country != null)
{
db.Entry(country).State = EntityState.Modified;
int affected = db.SaveChanges();
if (affected > 0)
{
TempData["success"] = "Modify successfully";
ModelState.Clear();
return RedirectToAction("Index");
}
else
{
ViewBag.Faild = "something is wrong ";
}
}
}
return View();
}
[HttpGet]
public ActionResult Delete(int id)
{
var dataRow = db.Countries.Find(id);
return View(dataRow);
}
[HttpPost]
public ActionResult Delete(int id, string str)
{
if (id == 0)
{
return HttpNotFound();
}
var dataRow = db.Countries.Find(id);
db.Countries.Remove(dataRow);
db.SaveChanges();
return RedirectToAction("Index");
}
// Wrote code for State
public ActionResult IndexState()
{
return View(db.States.Include(s => s.Country).ToList());
}
[HttpGet]
public ActionResult CreateState()
{
List<Country> showlistCountrt = db.Countries.ToList();
ViewBag.showContries = new SelectList(showlistCountrt, "Id", "Name");
return View();
}
[HttpPost]
public ActionResult CreateState(State state)
{
if (ModelState.IsValid)
{
if (state != null)
{
db.States.Add(state);
int affected = db.SaveChanges();
if (affected > 0)
{
TempData["success"] = "Successfully Added";
ModelState.Clear();
return RedirectToAction("IndexState");
}
else
{
ViewBag.success = "SuccessFully Added";
}
}
}
return View();
}
[HttpGet]
public ActionResult DetailsState(int id)
{
var dataRow = db.States.Include(s => s.Country).OrderBy(x => x.Name).FirstOrDefault(x => x.Id == id);
return View(dataRow);
}
[HttpGet]
public ActionResult EditState(int id)
{
var dataRow = db.States.OrderBy(x => x.Name).Include(s => s.Country).FirstOrDefault(x => x.Id == id);
ViewBag.dataRow = new SelectList(db.Countries, "Id", "Name", dataRow.CountryId);
// var dataRow = db.States.Find(id);
return View(dataRow);
}
[HttpPost]
public ActionResult EditState(State state, int id)
{
if (ModelState.IsValid)
{
if (state != null)
{
db.Entry(state).State = EntityState.Modified;
int affected = db.SaveChanges();
if (affected > 0)
{
TempData["success"] = "Modify successfully";
ModelState.Clear();
return RedirectToAction("IndexState");
}
else
{
ViewBag.Faild = "something is wrong ";
}
}
}
return View();
}
[HttpGet]
public ActionResult DeleteState(int id)
{
var dataRow = db.States.Include(s => s.Country).OrderBy(x => x.Name).FirstOrDefault(x => x.Id == id);
return View(dataRow);
}
[HttpPost]
public ActionResult DeleteState(int id, string str)
{
if (id == 0)
{
return HttpNotFound();
}
var dataRow = db.States.Find(id);
db.States.Remove(dataRow);
db.SaveChanges();
return RedirectToAction("IndexState");
}
// Wrote code for City
public ActionResult IndexCity()
{
return View(db.Cities.Include(s => s.State).ToList());
}
[HttpGet]
public ActionResult CreateCity()
{
List<State> showState = db.States.OrderBy(x => x.Name).ToList();
ViewBag.showContries = new SelectList(showState, "Id", "Name");
return View();
}
[HttpPost]
public ActionResult CreateCity(City city)
{
if (ModelState.IsValid)
{
if (city != null)
{
db.Cities.Add(city);
int affected = db.SaveChanges();
if (affected > 0)
{
TempData["success"] = "Successfully Added";
ModelState.Clear();
return RedirectToAction("IndexCity");
}
else
{
ViewBag.success = "SuccessFully Added";
}
}
}
return View();
}
[HttpGet]
public ActionResult DetailsCity(int id)
{
var dataRow = db.Cities.Include(x => x.State).FirstOrDefault(x => x.Id == id);
return View(dataRow);
}
[HttpGet]
public ActionResult EditCity(int id)
{
var dataRow = db.Cities.OrderBy(x => x.Name).Include(s => s.State).FirstOrDefault(x => x.Id == id);
ViewBag.dataRow = new SelectList(db.States, "Id", "Name", dataRow.StateId);
// var dataRow = db.States.Find(id);
return View(dataRow);
}
[HttpPost]
public ActionResult EditCity(City city, int id)
{
if (ModelState.IsValid)
{
if (city != null)
{
db.Entry(city).State = EntityState.Modified;
int affected = db.SaveChanges();
if (affected > 0)
{
TempData["success"] = "Modify successfully";
ModelState.Clear();
return RedirectToAction("IndexCity");
}
else
{
ViewBag.Faild = "something is wrong ";
}
}
}
return View();
}
[HttpGet]
public ActionResult DeleteCity(int id)
{
var dataRow = db.States.Include(s => s.Country).OrderBy(x => x.Name).FirstOrDefault(x => x.Id == id);
return View(dataRow);
}
[HttpPost]
public ActionResult DeleteCity(int id, string str)
{
if (id == 0)
{
return HttpNotFound();
}
var dataRow = db.States.Find(id);
db.States.Remove(dataRow);
db.SaveChanges();
return RedirectToAction("IndexState");
}
}
}
https://www.asmak9.com/2017/12/aspnet-mvc5-full-calendar-jquery-plugin.html Full Calendar
ReplyDeleteSubject: Request for Leave for Exams
ReplyDeleteDear Mansi Ma'am,
I hope you're having a great day.
I am writing to request leave for my exams, which are on the following dates:
February: 18th and 21st
March: 3rd, 5th, and 7th
I would appreciate your approval for leave on these dates. I’m not sure about the practical exam dates yet, but I will update you once I know them.
Please let me know if you need any more information.
Thank you for your understanding.
Best regards,
Hemant Yadav
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_Notifications_Registration_RegistrationId". The conflict occurred in database "imarcordix-testdb", table "dbo.Registration", column 'RegistrationId'.
ReplyDeleteFailed executing DbCommand (505ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ReplyDeleteALTER TABLE [Notifications] ADD CONSTRAINT [FK_Notifications_Registration_RegistrationId] FOREIGN KEY ([RegistrationId]) REFERENCES [Registration] ([RegistrationId]) ON DELETE CASCADE;