public static void Insert() { using (EntityModelContext context = new EntityModelContext()) { Employee emp = new Employee { Id = 5, Name = "Vishal", }; context.Entry(emp).Property("CreatedDate").CurrentValue = DateTime.Now; context.Add(emp); context.SaveChanges(); } Console.ReadLine(); Console.Clear(); }
public static void Insert() { using (EntityModelContext context = new EntityModelContext()) { Employee emp = new Employee { Id = 5, Name = "Vishal", IsDeleted = false, EmployeeDetail = new EmployeeDetail { EmailAddress = "*****@*****.**", MobileNumber = "895648552" } }; context.Add(emp); context.SaveChanges(); } Console.ReadLine(); Console.Clear(); }
public IActionResult Save([FromBody] MyDetails myDetail) { bool isNew = false; MyDetails data = _context.MyDetails.Where(p => p.Id == myDetail.Id).FirstOrDefault(); if (data == null) { data = new MyDetails(); isNew = true; } data.FirstName = myDetail.FirstName; data.LastName = myDetail.LastName; data.AdharNumber = myDetail.AdharNumber; data.Email = myDetail.Email; data.PhoneNumber = myDetail.PhoneNumber; if (isNew) { _context.Add(data); } _context.SaveChanges(); return(Ok(data)); }