コード例 #1
0
        public async Task Update_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "PersonService Update(PersonServiceModel) method does not work properly.";

            var context = HealthInsDbContextInMemoryFactory.InitializeContext();

            this.personService = new PersonService(context);
            await SeedData(context);

            PersonServiceModel person = context.Persons.First().To <PersonServiceModel>();

            person.Egn       = "112222221";
            person.EndDate   = DateTime.Now.AddDays(2);
            person.FullName  = "Ivan 22";
            person.Smoker    = true;
            person.Sex       = "Female";
            person.StartDate = DateTime.Parse("01/01/1996").AddDays(3);


            var actualResults = await this.personService.Update(person);

            var actualEntry = this.personService.GetById(person.Id);

            Assert.True(person.FullName == actualEntry.FullName, errorMessagePrefix + " " + "Egn is not returned properly.");
            Assert.True(person.Egn == actualEntry.Egn, errorMessagePrefix + " " + "Egn is not returned properly.");
            Assert.True(person.StartDate.ToShortDateString() == actualEntry.StartDate.ToShortDateString(), errorMessagePrefix + " " + "StartDate is not returned properly.");
            Assert.True(person.Sex == actualEntry.Sex, errorMessagePrefix + " " + "Sex is not returned properly.");
            Assert.True(person.EndDate.ToShortDateString() == actualEntry.EndDate.ToShortDateString(), errorMessagePrefix + " " + "EndDate is not returned properly.");
            Assert.True(person.Smoker == actualEntry.Smoker, errorMessagePrefix + " " + "Smoker Type is not returned properly.");
        }
コード例 #2
0
        public async Task Create_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ContractService Create(ContractServiceModel) method does not work properly.";

            var context = HealthInsDbContextInMemoryFactory.InitializeContext();

            this.personService = new PersonService(context);
            await SeedData(context);

            PersonServiceModel newPerson = new PersonServiceModel()
            {
                Id        = 3,
                Egn       = "11222222",
                EndDate   = DateTime.Now,
                FullName  = "Ivan 2",
                Smoker    = false,
                Sex       = "Male",
                StartDate = DateTime.Parse("01/01/1996")
            };
            var actualResults = await this.personService.Create(newPerson);

            var actualEntry = this.personService.GetById(3);

            Assert.True(newPerson.FullName == actualEntry.FullName, errorMessagePrefix + " " + "Egn is not returned properly.");
            Assert.True(newPerson.Egn == actualEntry.Egn, errorMessagePrefix + " " + "Egn is not returned properly.");
            Assert.True(newPerson.StartDate.ToShortDateString() == actualEntry.StartDate.ToShortDateString(), errorMessagePrefix + " " + "StartDate is not returned properly.");
            Assert.True(newPerson.Sex == actualEntry.Sex, errorMessagePrefix + " " + "Sex is not returned properly.");
            Assert.True(newPerson.EndDate.ToShortDateString() == actualEntry.EndDate.ToShortDateString(), errorMessagePrefix + " " + "EndDate is not returned properly.");
            Assert.True(newPerson.Smoker == actualEntry.Smoker, errorMessagePrefix + " " + "Smoker Type is not returned properly.");
        }
コード例 #3
0
ファイル: PersonController.cs プロジェクト: kgyorev/HealthIns
        public async Task <IActionResult> Details(long Id)
        {
            PersonServiceModel     personFromDB = this.personService.GetById(Id);
            PersonCreateInputModel person       = personFromDB.To <PersonCreateInputModel>();

            return(this.View(person));
        }
コード例 #4
0
        public async Task <bool> Create(PersonServiceModel personServiceModel)
        {
            Person person = AutoMapper.Mapper.Map <Person>(personServiceModel);

            context.Persons.Add(person);
            int result = await context.SaveChangesAsync();

            personServiceModel.Id = person.Id;
            return(result > 0);
        }
コード例 #5
0
ファイル: PersonController.cs プロジェクト: kgyorev/HealthIns
        public async Task <IActionResult> Edit(PersonCreateInputModel personCreateInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(personCreateInputModel));
            }
            PersonServiceModel personServiceModel = AutoMapper.Mapper.Map <PersonServiceModel>(personCreateInputModel);

            await this.personService.Update(personServiceModel);

            this.TempData["info"] = String.Format(UPDATED_PERSON, personServiceModel.Id);
            return(this.Redirect("/Person/Search"));
        }
コード例 #6
0
        public async Task <bool> Update(PersonServiceModel personServiceModel)
        {
            Person persontDB = this.context.Persons.SingleOrDefault(p => p.Id == personServiceModel.Id);

            persontDB.StartDate = personServiceModel.StartDate;
            persontDB.EndDate   = personServiceModel.EndDate;
            persontDB.FullName  = personServiceModel.FullName;
            persontDB.Egn       = personServiceModel.Egn;
            persontDB.Sex       = personServiceModel.Sex;
            persontDB.Smoker    = personServiceModel.Smoker;

            context.Update(persontDB);
            int result = await context.SaveChangesAsync();

            return(result > 0);
        }