Exemple #1
0
        public ActionResult <ProvinceDistrictReadDto> CreateProvinceDistrict(ProvinceDistrictCreateDto provinceCreateDto)
        {
            var receievedata = _mapper.Map <ProvinceDistrict>(provinceCreateDto);

            _repo.CreateProvinceDistrict(receievedata);
            _repo.SaveChanges();
            var newdata = _mapper.Map <ProvinceDistrictReadDto>(receievedata);

            return(CreatedAtRoute(nameof(GetProvinceDistrictById), new { Id = newdata.ProvinceDistrictId }, newdata));
        }
Exemple #2
0
        public ActionResult <CityMunicipalityReadDto> CreateCityMunicipality(CityMunicipalityCreateDto citymunicipalityCreateDto)
        {
            var receievedata = _mapper.Map <CityMunicipality>(citymunicipalityCreateDto);

            _repo.CreateCityMunicipality(receievedata);
            _repo.SaveChanges();
            var newdata = _mapper.Map <CityMunicipalityReadDto>(receievedata);

            return(CreatedAtRoute(nameof(GetCityMunicipalityById), new { Id = newdata.CityMunicipalityId }, newdata));
        }
Exemple #3
0
        public ActionResult <RegionReadDto> CreateRegion(RegionCreateDto regionCreateDto)
        {
            var receievedata = _mapper.Map <Region>(regionCreateDto);

            _repo.CreateRegion(receievedata);
            _repo.SaveChanges();
            var newdata = _mapper.Map <RegionReadDto>(receievedata);

            return(CreatedAtRoute(nameof(GetRegionById), new { Id = newdata.RegionId }, newdata));
        }
        public ActionResult <BarangayReadDto> CreateBarangay(BarangayCreateDto barangayCreateDto)
        {
            var receievedata = _mapper.Map <Barangay>(barangayCreateDto);

            _repo.CreateBarangay(receievedata);
            _repo.SaveChanges();
            var newdata = _mapper.Map <BarangayReadDto>(receievedata);

            return(CreatedAtRoute(nameof(GetBarangayById), new { Id = newdata.BarangayId }, newdata));
        }
Exemple #5
0
        public ActionResult UploadFile(IFormFile psgc)
        {
            var tempreglist  = new List <Region>();
            var temprovlist  = new List <ProvinceDistrict>();
            var tempcitylist = new List <CityMunicipality>();
            var tempbara     = new List <Barangay>();

            using (var reader = new StreamReader(psgc.OpenReadStream()))
            {
                while (reader.Peek() >= 0)
                {
                    var psgcrow = reader.ReadLine().Split(",");
                    if (psgcrow.Length != 3)
                    {
                        return(BadRequest());
                    }
                    if (psgcrow[0].Length != 9)
                    {
                        return(BadRequest());
                    }
                    var regcode             = psgcrow[0].Substring(0, 2) + "0000000";
                    var provdistcode        = psgcrow[0].Substring(0, 4) + "00000";
                    var citymunisubmunicode = psgcrow[0].Substring(0, 6) + "000";
                    if (ShareLib.CheckIfRegion(psgcrow[0]))
                    {
                        Region newreg = new Region
                        {
                            RegionId   = Guid.NewGuid(),
                            RegionCode = psgcrow[0],
                            RegionName = psgcrow[1]
                        };
                        tempreglist.Add(newreg);
                    }
                    if (ShareLib.CheckIfProviceDistrict(psgcrow[0]))
                    {
                        ProvinceDistrict newprov = new ProvinceDistrict
                        {
                            ProvinceDistrictId      = Guid.NewGuid(),
                            ProvinceDistrictCode    = psgcrow[0],
                            ProvinceDistrictName    = psgcrow[1],
                            ProvinceDistrictOldName = psgcrow[2],
                            Region = tempreglist.Where(w => w.RegionCode == regcode).First()
                        };
                        temprovlist.Add(newprov);
                    }
                    if (ShareLib.CheckIfCityMunicipalitySub(psgcrow[0]))
                    {
                        CityMunicipality newcitmun = new CityMunicipality
                        {
                            CityMunicipalityId      = Guid.NewGuid(),
                            CityMunicipalityCode    = psgcrow[0],
                            CityMunicipalityName    = psgcrow[1],
                            CityMunicipalityOldname = psgcrow[2],
                            ProvinceDistrict        = temprovlist.Where(w => w.ProvinceDistrictCode == provdistcode).First()
                        };
                        tempcitylist.Add(newcitmun);
                    }
                    if (ShareLib.CheckIfBarangay(psgcrow[0]))
                    {
                        Barangay newbrg = new Barangay
                        {
                            BarangayId         = Guid.NewGuid(),
                            BarangayCode       = psgcrow[0],
                            BarangayName       = psgcrow[1],
                            BarangayOldname    = psgcrow[2],
                            CityMunicipality   = tempcitylist.Where(w => w.CityMunicipalityCode == citymunisubmunicode).First(),
                            CityMunicipalityId = tempcitylist.Where(w => w.CityMunicipalityCode == citymunisubmunicode).First().CityMunicipalityId
                        };
                        tempbara.Add(newbrg);
                    }
                }
            }
            _repo.Import(tempreglist, temprovlist, tempcitylist, tempbara);
            _repo.SaveChanges();
            return(Ok());
        }