Пример #1
0
        public async Task <IActionResult> UploadAsync(IFormFile uploadedFile)
        {
            if (uploadedFile != null)
            {
                // шлях до папки Files
                string path = _appEnvironment.WebRootPath + "/Files/" + Guid.NewGuid() + "." + uploadedFile.FileName;


                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }
                FileService          fileService = new FileService();
                IEnumerable <string> strings     = fileService.ParseFile(path);
                List <ViewCsv>       entities    = new List <ViewCsv>();
                foreach (var e in strings)
                {
                    IEnumerable <string> elements = fileService.SplitString(e);
                    ViewCsv dto = fileService.GetCsv(elements);

                    entities.Add(dto);
                }
                await _csvService.Insert(entities);
            }

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,DateOfBirth,Phone,Salary,IsMaried")] ViewCsv csv)
        {
            if (id != csv.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _csvService.Update(csv);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CsvExists(csv.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(csv));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,FullName,DateOfBirth,Phone,Salary,IsMaried")] ViewCsv csv)
        {
            if (ModelState.IsValid)
            {
                await _csvService.Insert(csv);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(csv));
        }
Пример #4
0
        public async Task <ViewCsv> Update(ViewCsv userDto)
        {
            var entity = new Csv();

            _mapper.Map(userDto, entity);
            _csvRepository.Update(entity);
            await _csvRepository.SaveAsync().ConfigureAwait(false);

            return(_mapper.Map <Csv, ViewCsv>(entity));
        }
Пример #5
0
        public ViewCsv GetCsv(IEnumerable <string> inputString)
        {
            ViewCsv result = new ViewCsv();


            result.FullName    = inputString.ElementAt(0);
            result.DateOfBirth = DateTime.Parse(inputString.ElementAt(1));
            result.IsMaried    = Boolean.Parse(inputString.ElementAt(2));
            result.Phone       = inputString.ElementAt(3);
            result.Salary      = Decimal.Parse(inputString.ElementAt(4), CultureInfo.InvariantCulture);
            return(result);
        }