예제 #1
0
        public async Task <IEnumerable <string> > Get()
        {
            var res = new {
                name = "Vlad",
                age  = 24
            };

            await _invokeHandler.InvokeAsync(async() =>
            {
                await Task.Delay(10);

                return(InvokeResult <object> .Ok());
            }, res);

            return(new string[] { "value1", "value2" });
        }
예제 #2
0
        public async Task <InvokeResult <object> > UploadMunrosDataAsync(IFormFile file)
        => await _invokeHandler.InvokeAsync(async() =>
        {
            var uploadResult = await _fileReaderService.UploadMunrosFileAsync(file);

            if (!uploadResult.IsSuccess)
            {
                return(InvokeResult <object> .Fail(uploadResult.Code));
            }

            var munrosModelResult = _munroService.ConvertMunrosFullModelToMunrosModel(uploadResult.Result);
            if (!munrosModelResult.IsSuccess)
            {
                return(InvokeResult <object> .Fail(munrosModelResult.Code));
            }

            _munrosRepository.AddRange(munrosModelResult.Result);

            return(InvokeResult <object> .Ok());
        });
예제 #3
0
        public async Task <InvokeResult <IEnumerable <MunroFullModel> > > UploadMunrosFileAsync(IFormFile file)
        => await _invokeHandler.InvokeAsync(async() =>
        {
            if (file == null)
            {
                return(InvokeResult <IEnumerable <MunroFullModel> > .Fail(ResultCode.ValidationError,
                                                                          "You need to attach a .csv file"));
            }

            string extension = Path.HasExtension(file.FileName)
                    ? Path.GetExtension(file.FileName)
                    : string.Empty;

            var isSupported = IsFileTypeSupported(extension);

            if (!isSupported)
            {
                var errorMessage = "File Extension Is Unsupported";
                return(InvokeResult <IEnumerable <MunroFullModel> > .Fail(ResultCode.UnsupportedFileExtension,
                                                                          errorMessage));
            }

            var munroFullModels = new List <MunroFullModel>();

            using (var reader = new StreamReader(file.OpenReadStream()))
            {
                var header = true;
                while (!reader.EndOfStream)
                {
                    var line = await reader.ReadLineAsync();
                    if (header)
                    {
                        header = false;
                        continue;
                    }

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    var values = line.Split(',');
                    if (values.Count() != 30)
                    {
                        continue;
                    }

                    munroFullModels.Add(new MunroFullModel
                    {
                        RunningNo            = values[0],
                        DoBIHNumber          = values[1],
                        Streetmap            = $"{values[2]},{values[3]}",
                        Geograph             = values[4],
                        HillBagging          = values[5],
                        Name                 = values[6],
                        SMCSection           = values[7],
                        RHBSection           = values[8],
                        Section              = values[9],
                        Heightm              = values[10],
                        Heightft             = values[11],
                        Map150               = values[12],
                        Map125               = values[13],
                        GridRef              = values[14],
                        GridRefXY            = values[15],
                        Xcoord               = values[16],
                        Ycoord               = values[17],
                        HillCategory1891     = values[18],
                        HillCategory1921     = values[19],
                        HillCategory1933     = values[20],
                        HillCategory1953     = values[21],
                        HillCategory1969     = values[22],
                        HillCategory1974     = values[23],
                        HillCategory1981     = values[24],
                        HillCategory1984     = values[25],
                        HillCategory1990     = values[26],
                        HillCategory1997     = values[27],
                        HillCategoryPost1997 = values[28],
                        Comments             = values[29]
                    });
                }
            }

            return(InvokeResult <IEnumerable <MunroFullModel> > .Ok(munroFullModels));
        });