예제 #1
0
        public void SearchPersonNoResults()
        {
            using (_testSubject = new PersonContext())
            {
                //Create and save new Person
                _testSubject.Add(_person1);
                _testSubject.Add(_person2);

                var persons = _testSubject.Search("SomeStringThatReturnsNoResults");
                Assert.IsNotNull(persons);
                Assert.AreEqual(0, persons.Count);
            }
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Name, Surname, Patronymic, Tel, Position,TagId,Image")] PersonModel person)
        {
            Person _person = new Person {
                Name = person.Name, Surname = person.Surname, Patronymic = person.Patronymic,
                Tel  = person.Tel, Position = person.Position, TagId = person.TagId
            };

            if (ModelState.IsValid && RidCheck(person.TagId))
            {
                if (person.Image != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(person.Image.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)person.Image.Length);
                    }

                    _person.Image = imageData;
                }
                _context.Add(_person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello! Please answer a few questions!");
            System.Console.WriteLine("First Name:");
            string fname = Console.ReadLine();

            System.Console.WriteLine("Last Name:");
            string lname = Console.ReadLine();

            System.Console.WriteLine("Age:");
            string age = Console.ReadLine();

            int myAge = Int32.Parse(age);


            using (var db = new PersonContext()){
                var TableContents = db.Persons;

                Person NewPerson = new Person {
                    FirstName = fname,
                    LastName  = lname,
                    Age       = myAge
                };
                db.Add(NewPerson);
                db.SaveChanges();
            }


            System.Console.WriteLine($"Thank You {fname} {lname}!");
        }
예제 #4
0
 public void CreatePerson()
 {
     _context.Add(new Person() { 
         FirstName = "Robert ", LastName = "Berends",
         City = "Birmingham", Address = "2632 Petunia Way" });
     _context.SaveChanges();
 }
예제 #5
0
            private static void Add02(PersonContext ctx)
            {
                Person person = new Person
                {
                    FirstName = "Reza",
                    LastName  = "Akbari",
                };

                JobData jobData = ctx.JobDatas.FirstOrDefault();


                person.JobData = jobData;
                Console.WriteLine("Person:" + ctx.Entry(person).State);
                Console.WriteLine("JobData:" + ctx.Entry(jobData).State);
                Console.WriteLine("ok");
                ctx.Add(person);
                Console.WriteLine("Person:" + ctx.Entry(person).State);
                Console.WriteLine("JobData:" + ctx.Entry(jobData).State);
                Console.WriteLine("ok");
                ctx.SaveChanges();
                Console.WriteLine("Person:" + ctx.Entry(person).State);
                Console.WriteLine("JobData:" + ctx.Entry(jobData).State);
                Console.WriteLine("ok");
                Console.ReadLine();
            }
예제 #6
0
            private static void Add01(PersonContext ctx)
            {
                Person person = new Person
                {
                    FirstName = "Ali",
                    LastName  = "Nouri",
                };

                JobData jobData = new JobData
                {
                    JobTitle = "Developer"
                };

                person.JobData = jobData;
                Console.WriteLine("Person:" + ctx.Entry(person).State);
                Console.WriteLine("JobData:" + ctx.Entry(jobData).State);
                Console.WriteLine("ok");
                ctx.Add(person);
                Console.WriteLine("Person:" + ctx.Entry(person).State);
                Console.WriteLine("JobData:" + ctx.Entry(jobData).State);
                Console.WriteLine("ok");
                ctx.SaveChanges();
                Console.WriteLine("Person:" + ctx.Entry(person).State);
                Console.WriteLine("JobData:" + ctx.Entry(jobData).State);
                Console.WriteLine("ok");
                Console.ReadLine();
            }
예제 #7
0
 public bool CreatePerson(string firstName, string lastName, int age, short gender)
 {
     _personContext.Add(new PersonModel {
         FirstName = firstName, LastName = lastName, Age = age, Gender = gender
     });
     _personContext.SaveChanges();
     return(true);
 }
예제 #8
0
 public IActionResult Create(int id)
 {
     _context.Add(new Person()
     {
         FirstName = "Charlize", LastName = "Theron", City = "Los Angeles", Address = "Dreams st 1000"
     });
     _context.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
예제 #9
0
 public IActionResult Create()
 {
     _context.Add(new Person()
     {
         FirstName = "Robert", LastName = "Berends", City = "Birmingham", Address = "2632 Petunia Way"
     });
     _context.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }
예제 #10
0
        public void SearchPerson()
        {
            using (_testSubject = new PersonContext())
            {
                //Create and save new Person
                _testSubject.Add(_person1);
                _testSubject.Add(_person2);

                var persons = _testSubject.Search("John");
                Assert.IsNotNull(persons);
                Assert.AreEqual(1, persons.Count);
                Assert.IsNotNull(persons[0]);

                var person = persons[0];
                AssertPerson(person, FirstName1, LastName1, Interests1, Image1, FirstStreetLine1,
                             SecondStreetLine1, City1, State1, Zip1, Country1, DateOfBirth1);
            }
        }
예제 #11
0
        public int CreatePerson(CreatePerson cmd)
        {
            _logger.LogInformation("Creating person");

            var person = cmd.ToPerson();

            _personContext.Add(person);
            _personContext.SaveChanges();
            return(person.Id);
        }
예제 #12
0
        public async Task <IActionResult> Create([Bind("Id,Name,Creator,YearCreation,ImageUrl,Description")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #13
0
        public IActionResult Post([FromBody] Person item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _personContext.Add(item);

            return(CreatedAtRoute(new { id = item.Key }, item));
        }
예제 #14
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Apellido,Estado,Carrera")] Persona persona)
        {
            if (ModelState.IsValid)
            {
                _context.Add(persona);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(persona));
        }
예제 #15
0
        public async Task <IActionResult> Create([Bind("ID,Name,YoB")] Human human)
        {
            if (ModelState.IsValid)
            {
                _context.Add(human);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(human));
        }
        public async Task <IActionResult> Create([Bind("PersonId,FullName,EmpCode,Position,OfficeLocation")] Person person)
        {
            if (ModelState.IsValid)
            {
                personContext.Add(person);
                await personContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #17
0
        public async Task <IActionResult> Create([Bind("PersonId,Name,CPF,Birthday,Age")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #18
0
        public async Task <IActionResult> Create([Bind("CityId,CityName,ZipCode,CountryRegion")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
예제 #19
0
        public async Task <IActionResult> Create([Bind("EmailId,EmailAddress")] Email email)
        {
            if (ModelState.IsValid)
            {
                _context.Add(email);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(email));
        }
예제 #20
0
        public async Task <IActionResult> Create([Bind("PersonId,firstName,lastName,birthDate,age")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction("PersonDetails"));
            }
            return(View(person));
        }
예제 #21
0
 public PersonController(PersonContext personContext)
 {
     _personContext = personContext;
     if (_personContext.Persons.Count() == 0)
     {
         _personContext.Add(new PersonModel {
             FirstName = "Zhaoyang", LastName = "Liu", Age = 24, Gender = (short)1
         });
         _personContext.SaveChanges();
     }
 }
예제 #22
0
        public static void Seed(this PersonContext context)
        {
            context.Add(new Person
            {
                name        = "Knight",
                displayName = "Lothric",
                skills      = new List <Skill>()
                {
                    new Skill {
                        name = "strength", level = 2
                    },
                    new Skill {
                        name = "health", level = 10
                    }
                }
            });
            context.Add(new Person
            {
                name        = "Pyromancer",
                displayName = "Izalit",
                skills      = new List <Skill>()
                {
                    new Skill {
                        name = "fireball", level = 2
                    },
                    new Skill {
                        name = "firestorm", level = 2
                    }
                }
            });
            context.Add(new Person
            {
                name        = "Deprived",
                displayName = "King",
                skills      = new List <Skill>()
                {
                }
            });

            context.SaveChanges();
        }
예제 #23
0
        public async Task <IActionResult> Create([Bind("ID,Number,PersonID")] PhoneNumber phoneNumber)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phoneNumber);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonID"] = new SelectList(_context.People, "ID", "FirstName", phoneNumber.PersonID);
            return(View(phoneNumber));
        }
예제 #24
0
        public async Task <IActionResult> Create([Bind("AddressId,StreetAddress,AddressType,CityId")] Address address)
        {
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.City, "CityId", "CityName", address.CityId);
            return(View(address));
        }
예제 #25
0
        public IActionResult Create(Person model)
        {
            if (ModelState.IsValid)
            {
                context.Add(model);

                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
예제 #26
0
        public void SearchPersonWithEmptyString()
        {
            using (_testSubject = new PersonContext())
            {
                //Create and save new Person
                _testSubject.Add(_person1);
                _testSubject.Add(_person2);

                var persons = _testSubject.Search("");
                Assert.IsNotNull(persons);
                Assert.AreEqual(2, persons.Count);
                Assert.IsNotNull(persons[0]);
                Assert.IsNotNull(persons[1]);

                AssertPerson(persons[0], FirstName2, LastName2, Interests2, Image2, FirstStreetLine2,
                             SecondStreetLine2, City2, State2, Zip2, Country2, DateOfBirth2);

                AssertPerson(persons[1], FirstName1, LastName1, Interests1, Image1, FirstStreetLine1,
                             SecondStreetLine1, City1, State1, Zip1, Country1, DateOfBirth1);
            }
        }
예제 #27
0
        // POST: PersonEntities/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> CreatePerson([Bind("Id,FirstName,LastName,Title,Age,City,PostCode")] PersonEntity personEntity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction("Index"));
        }
예제 #28
0
        public async Task <IActionResult> Create([Bind("ID,PersonID,Address")] EMailAddress eMailAddress)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eMailAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonID"] = new SelectList(_context.People, "ID", "ID", eMailAddress.PersonID);
            return(View(eMailAddress));
        }
예제 #29
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Birthday,City,State")] Person person)
        {
            if (ModelState.IsValid)
            {
                _log.LogInformation("Creating person");
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            _log.LogWarning("The Model State to create a person was not valid");
            return(View(person));
        }
예제 #30
0
        public async Task <IActionResult> Create([Bind("PersonId,FullName,EmailId,AddressId")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"] = new SelectList(_context.Address, "AddressId", "StreetAddress", person.AddressId);
            ViewData["EmailId"]   = new SelectList(_context.Email, "EmailId", "EmailAddress", person.EmailId);
            return(View(person));
        }