예제 #1
0
 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();
     }
 }
예제 #2
0
        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();
        }
예제 #3
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
        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));
        }
예제 #7
0
        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));
        }
예제 #9
0
 public bool AddDoctor(Doctor doctor)
 {
     _dbService.Add(doctor);
     try
     {
         _dbService.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         return(false);
     }
 }
예제 #10
0
        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));
        }
예제 #13
0
        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);
        }
예제 #14
0
        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));
        }
예제 #15
0
        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);
        }
예제 #16
0
        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));
        }
예제 #17
0
        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));
        }
예제 #18
0
        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();
            }
        }
예제 #19
0
 public void WriteDataToDB()
 {
     _context.Add(new PlayerInfo {
         Name = game.gui.PlayerNickName, Score = game.gui.Score
     });
     _context.SaveChanges();
 }
예제 #20
0
 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);
     }
 }
예제 #21
0
        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);
            }
        }
예제 #22
0
        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"));
        }
예제 #23
0
        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));
 }
예제 #25
0
        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("------");
            }
        }
예제 #26
0
        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();
        }
예제 #27
0
        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));
        }
예제 #28
0
        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));
        }
예제 #29
0
 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();
 }
예제 #30
0
 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"));
     }
 }
예제 #31
0
        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();
                }
            }
        }