static void Main(string[] args) { using (var db = new CodeFirstContext()) { Console.Write("Enter a name: "); var name = Console.ReadLine(); var cont = new Contact { ContactName = name }; db.Contacts.Add(cont); db.SaveChanges(); var usr = new User { UserName = "******", Contact = cont }; db.Users.Add(usr); db.SaveChanges(); var query = from b in db.Contacts orderby b.ContactName select b; Console.WriteLine("All contacts in the database:"); foreach (var item in query) { Console.WriteLine(item.ContactName); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }
public void ChangeDoctor(int id, Doctor doctor) { var d = GetDoctor(id); d.FirstName = doctor.FirstName; d.LastName = doctor.LastName; d.Email = doctor.Email; _codeFirstContext.SaveChanges(); }
public ActionResult Create([Bind(Include = "OrderId,OrderCode,OrderAmount")] Order order) { if (ModelState.IsValid) { db.Order.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); }
public ActionResult Create([Bind(Include = "ProjectId,ProjectName,Description")] Project project) { if (ModelState.IsValid) { db.Projects.Add(project); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(project)); }
public ActionResult Create([Bind(Include = "KontaktID,Imie,Nazwisko,Email,NowePole")] CodeFirst codeFirst) { if (ModelState.IsValid) { db.Kontakty.Add(codeFirst); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(codeFirst)); }
public ActionResult Create([Bind(Include = "DepartmentId,Name,Head,Location")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Create([Bind(Include = "DevId,FirstName,LastName,Email,PhoneNum,Adress")] Developer developer) { if (ModelState.IsValid) { db.Developers.Add(developer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(developer)); }
public ActionResult Create([Bind(Include = "PersonId,FirstName,LastName,Email,Adress")] Person person) { if (ModelState.IsValid) { db.People.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PersonId = new SelectList(db.Vehicles, "PersonId", "VehicleName", person.PersonId); return(View(person)); }
public bool AddDoctor(Doctor doctor) { _dbService.Add(doctor); try { _dbService.SaveChanges(); return(true); }catch (Exception e) { return(false); } }
public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Email,PhoneNum,Age,DepartmentId")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", employee.DepartmentId); return(View(employee)); }
public Doctor ModifyDoctor(int id, DoctorModifyDto doctor) { _context.Doctor.Where(x => x.IdDoctor == id).ToList().ForEach(x => { x.Email = doctor.Email; x.FirstName = doctor.FirstName; x.LastName = doctor.LastName; }); _context.SaveChanges(); return(GetDoctor(id)); }
public ActionResult Create([Bind(Include = "ProjectAssignDeveloperId,DevId,ProjectId")] ProjectAssignDeveloper projectAssignDeveloper) { if (ModelState.IsValid) { db.ProjectAssignDevelopers.Add(projectAssignDeveloper); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DevId = new SelectList(db.Developers, "DevId", "FirstName", projectAssignDeveloper.DevId); ViewBag.ProjectId = new SelectList(db.Projects, "ProjectId", "ProjectName", projectAssignDeveloper.ProjectId); return(View(projectAssignDeveloper)); }
public Doctor AddNewDoc(NewDoctor request) { var d = new Doctor { FirstName = "Michał", LastName = "Pała", Email = "*****@*****.**" }; context.Add(d); context.SaveChanges(); var alfa = context.Doctor.Where(a => a.Email == d.Email && a.FirstName == d.FirstName && a.LastName == d.LastName).First(); return(alfa); }
public IActionResult DeleteDoctor(int id) { int z; while (_context.Prescription.Where(x => x.IdDoctor == id).Any() == true) { z = _context.Prescription.Where(x => x.IdDoctor == id).FirstOrDefault().IdPrescription; _context.PrescriptionMedicament.Remove(_context.PrescriptionMedicament.Where(x => x.IdPrescription == z).FirstOrDefault()); _context.Prescription.Remove(_context.Prescription.Where(x => x.IdPrescription == z).FirstOrDefault()); _context.SaveChanges(); } _context.Doctor.Remove(_context.Doctor.Where(x => x.IdDoctor == id).FirstOrDefault()); _context.SaveChanges(); return(Ok("Usunięto lekarza " + id)); }
public Doctor AddDoctor(AddDoctorRequest request) { var d = new Doctor { IdDoctor = request.IdDoctor, FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }; _db.Add(d); _db.SaveChanges(); return(d); }
public IActionResult AddDoctor(Doctor doctor) { var d = new Doctor { IdDoctor = doctor.IdDoctor, FirstName = doctor.FirstName, LastName = doctor.LastName, Email = doctor.Email, Prescriptions = new List <Prescription>() }; _cfc.Doctors.Add(d); _cfc.SaveChanges(); return(Ok("Added doctor " + d)); }
public IActionResult UpdateDoctor(ChangeRequest doc) { var doctor = _context.Doctor.Where(dc => dc.IdDoctor == doc.IdDoctor); Doctor changed = new Doctor { IdDoctor = doc.IdDoctor, FirstName = doc.FirstName, LastName = doc.LastName }; _context.Attach(changed); _context.Entry(changed).Property("FirstName").IsModified = true; _context.Entry(changed).Property("LastName").IsModified = true; _context.Entry(changed).Property("Email").IsModified = true; _context.SaveChanges(); return(Ok("Zaktualizowano doktora o numerze:" + changed.IdDoctor)); }
private void PowerDevices_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // Данная выборка добавляет внешний ключ к полю ТехнологическоеУстройство, из текущего контекса, // так как при добавлении строки в DataGrid это поле пустое. // Существовала ошибка с пустой ссылкой поля currentDevice, когда добавленная строка // силового агрегата не имела внешнего ключа таблицы УстройствоSet. (sender as ObservableCollection <СиловойАгрегатВУстановке>) .Where(w => w.ТехнологическаяУстановка == null) .ToList() .ForEach(x => x.ТехнологическаяУстановка = currentDevice); WorkCollection.ItemCollectionChanged <СиловойАгрегатВУстановке>(cfc, e); if (e.Action == NotifyCollectionChangedAction.Add) { var coll = e.NewItems; foreach (СиловойАгрегатВУстановке item in coll) { cfc.УстройствоРежимРесурсSet.Add(new УстановкаРежимРесурс(item.Id, 1)); } cfc.SaveChanges(); } }
public void WriteDataToDB() { _context.Add(new PlayerInfo { Name = game.gui.PlayerNickName, Score = game.gui.Score }); _context.SaveChanges(); }
public bool AddDoctor(AddDoctorRequest request) { try { dbContext.Add(new Doctor { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }); dbContext.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public CreatedClientResponse CreateClient(CreateClientRequest client) { var generatedSalt = CreateSalt(); var pass = Create(client.Password, generatedSalt); int idClient = db.Client.Max(d => d.IdClient) + 1; var clt = new Client { IdClient = idClient, FirstName = client.FirstName, LastName = client.LastName, Email = client.Email, Phone = client.Phone, Login = client.Login, Password = pass, salt = generatedSalt, RefreshToken = "" }; var clientToReturn = new CreatedClientResponse { IdClient = idClient, FirstName = client.FirstName, LastName = client.LastName, Email = client.Email, Phone = client.Phone, Login = client.Login }; db.Attach(clt); db.Add(clt); db.SaveChanges(); var exist = db.Client.Where(c => c.IdClient == idClient).Count(); if (exist == 1) { return(clientToReturn); } else { return(null); } }
public IActionResult Delete(DoctorId request) { var db = new CodeFirstContext(); db.Remove(db.Doctor.Find(request.IdDoctor)); db.SaveChanges(); return(StatusCode(201, "Doktor został usunięty")); }
public ActionResult Create([Bind(Include = "PersonId,VehicleName")] Vehicle vehicle) { if (ModelState.IsValid) { try { db.Vehicles.Add(vehicle); db.SaveChanges(); return(RedirectToAction("Index")); } catch { ViewBag.msg = "ALREADY ASSIGN "; } } ViewBag.PersonId = new SelectList(db.People, "PersonId", "FirstName", vehicle.PersonId); return(View(vehicle)); }
public ActionResult Edit(CostEstimationOfArticle costestimationofarticlemaster) { if (ModelState.IsValid) { db.Entry(costestimationofarticlemaster).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(costestimationofarticlemaster)); }
public static void Test1(CodeFirstContext context) { Customer c = new Customer(); c.City = "Roman"; c.Name = "Gigel Franaru"; Order o1 = new Order(); o1.Date = DateTime.Now; o1.TotalValue = 255; Order o2 = new Order(); o2.Date = DateTime.Now; o2.TotalValue = 255.52M; Order o3 = new Order(); o3.Date = DateTime.Now; o3.TotalValue = 2098; context.Clients.Add(c); context.SaveChanges(); var customer = context.Clients.Where(cust => cust.Name == c.Name).FirstOrDefault(); customer.Orders.Add(o1); customer.Orders.Add(o2); customer.Orders.Add(o3); context.SaveChanges(); foreach (var x in context.Clients) { Console.WriteLine($"{x.Name} - {x.City}"); foreach (var ord in x.Orders) { Console.WriteLine($"{ord.Date} {ord.TotalValue}"); } Console.WriteLine("------"); } }
public void DeleteDoctor(int id) { var tmp = _context.Doctor.Find(id); if (_context.Prescription.Select(i => i.IdDoctor).First() == id) { var x = _context.Prescription.Where(o => o.IdDoctor == id); var y = x.Select(i => i.IdPrescription).First(); if (_context.PrescriptionMedicament.Select(i => i.IdPrescription).First() == y) { var z = _context.PrescriptionMedicament.Where(i => i.IdPrescription == y); _context.PrescriptionMedicament.Remove(_context.PrescriptionMedicament.Find(z)); _context.Prescription.Remove(_context.Prescription.Find(x)); } } else { _context.Doctor.Remove(tmp); } _context.SaveChanges(); }
public IActionResult AddDoctor(Doctor doctor) { var d = new Doctor { //index autonumer FirstName = doctor.FirstName, LastName = doctor.LastName, Email = doctor.Email, Prescription = new List <Prescription>() }; db.Doctor.Add(d); db.SaveChanges(); return(Ok("dodano: " + d)); }
public CodeFirst.Library.Models.Users CreateUser(string fname, string lname) { Users createdUser = new Users() { UserId = Guid.NewGuid(), UserFn = fname, UserLn = lname }; _dbContext.Users.Add(createdUser); _dbContext.SaveChanges(); return(Mapper.MapUsers(createdUser)); }
static void Main(string[] args) { using (var context = new CodeFirstContext()) { context.Database.CreateIfNotExists();//如果数据库不存在时则创建 TRoles t = new TRoles(); t.Id = 1; t.RoleName = "aa"; context.Roles.Add(t); context.SaveChanges(); } Console.Write("DB has Created!");//提示DB创建成功 Console.Read(); }
public ActionResult DodajKontakt(CodeFirst codeFirst) { if (!ModelState.IsValid) { return(View("Index", codeFirst)); } else { CodeFirstContext db = new CodeFirstContext(); db.Kontakty.Add(codeFirst); db.SaveChanges(); return(View("Index")); } }
public void TestConcurrencyWithTimestampColumn() { using (new TransactionScope()) { using (var context = new CodeFirstContext()) { context.Demos.Add(new Demo { Cursus = "ADONETB", Omschrijving = "Entity Framework with VS2013" }); context.SaveChanges(); } using (var c1 = new CodeFirstContext()) using (var c2 = new CodeFirstContext()) { var d1 = c1.Demos.First(); var d2 = c2.Demos.First(); d1.Cursus = "TEST1"; d2.Cursus = "TEST2"; c1.SaveChanges(); c2.SaveChanges(); } } }