public async Task <IHttpActionResult> PostTablePerson(TablePerson tablePerson)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TablePersons.Add(tablePerson);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (TablePersonExists(tablePerson.PersonCPR))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = tablePerson.PersonCPR }, tablePerson));
        }
        public async Task <IHttpActionResult> PutTablePerson(string id, TablePerson tablePerson)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tablePerson.PersonCPR)
            {
                return(BadRequest());
            }

            db.Entry(tablePerson).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TablePersonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> GetTablePerson(string id)
        {
            TablePerson tablePerson = await db.TablePersons.FindAsync(id);

            if (tablePerson == null)
            {
                return(NotFound());
            }

            return(Ok(tablePerson));
        }
        public async Task <IHttpActionResult> DeleteTablePerson(string id)
        {
            TablePerson tablePerson = await db.TablePersons.FindAsync(id);

            if (tablePerson == null)
            {
                return(NotFound());
            }

            db.TablePersons.Remove(tablePerson);
            await db.SaveChangesAsync();

            return(Ok(tablePerson));
        }
Example #5
0
        //populam baza de date din cod si evita duplicatele
        protected override void Seed(DataAccess.Context.ApplicationDbContext context)
        {
            var locality1 = new Locality
            {
                LocalityName = "Buftea",
                County       = "Ifov",
                Latitude     = 44M,
                Longitude    = 25M,
            };
            var locality2 = new Locality
            {
                LocalityName = "Buciumeni",
                County       = "Ifov",
                Latitude     = 44M,
                Longitude    = 25M,
            };


            var person1 = new TablePerson
            {
                FirstName   = "George",
                LastName    = "Macovei",
                Email       = "*****@*****.**",
                DateOfBirth = DateTime.Now,
                PhotoPath   = "223.jpg",
                IsDeleted   = false,
                LocalityId  = 1,
                TestResult  = 0
            };
            var person2 = new TablePerson
            {
                FirstName   = "Ana",
                LastName    = "Macovei",
                Email       = "*****@*****.**",
                DateOfBirth = DateTime.Now,
                PhotoPath   = "default.jpg",
                IsDeleted   = false,
                LocalityId  = 2,
                TestResult  = 0
            };

            var person3 = new TablePerson
            {
                FirstName   = "Raed",
                LastName    = "Gorgiu",
                Email       = "*****@*****.**",
                DateOfBirth = DateTime.Now,
                PhotoPath   = "default.jpg",
                IsDeleted   = false,
                LocalityId  = 2,
                TestResult  = 0
            };
            var question1 = new Question
            {
                QuestionId    = Guid.NewGuid(),
                Sentence      = "Cate continente are Terra?",
                AnswerA       = "5",
                AnswerB       = "7",
                AnswerC       = "3",
                CorrectAnswer = "B"
            };
            var question2 = new Question
            {
                QuestionId    = Guid.NewGuid(),
                Sentence      = "Cate degete are o mana?",
                AnswerA       = "5",
                AnswerB       = "7",
                AnswerC       = "3",
                CorrectAnswer = "A"
            };
            var question3 = new Question
            {
                QuestionId    = Guid.NewGuid(),
                Sentence      = "Cate oceance are Terra?",
                AnswerA       = "5",
                AnswerB       = "7",
                AnswerC       = "3",
                CorrectAnswer = "A"
            };

            context.Localities.Add(locality1);
            context.Localities.Add(locality2);
            context.TablePersons.Add(person1);
            context.TablePersons.Add(person2);
            context.TablePersons.Add(person3);
            context.Questions.Add(question1);
            context.Questions.Add(question2);
            context.Questions.Add(question3);
        }