コード例 #1
0
ファイル: Task1Service.cs プロジェクト: BiserB/Assignment_IS
        public void CreateNewPerson(CreatePersonModel model)
        {
            Person newPerson = null;

            if (model.Age != 0 && !String.IsNullOrWhiteSpace(model.Name))
            {
                newPerson = new Person(model.Name, model.Age);
            }
            else if (model.Age != 0)
            {
                newPerson = new Person(model.Age);
            }
            else
            {
                newPerson = new Person();
            }

            Task1Repo.AddPerson(newPerson);
        }
コード例 #2
0
ファイル: Task1Service.cs プロジェクト: BiserB/Assignment_IS
        public void AddPersonsFromFile()
        {
            string rootPath = this.hostingEnvironment.ContentRootPath;

            string fullPath = rootPath + PERSONS_FILEPATH;

            if (!File.Exists(fullPath))
            {
                throw new FileNotFoundException("File not found at " + fullPath);
            }

            string text = File.ReadAllText(fullPath);

            PersonDto[] personDtos = JsonConvert.DeserializeObject <PersonDto[]>(text);

            foreach (var dto in personDtos)
            {
                Task1Repo.AddPerson(new Person(dto.Name, dto.Age));
            }
        }