示例#1
0
 public List <SaveResult <BTSDTO> > ExecuteImport(BTSImportDTO importDTO, DateTime dateStamp)
 {
     using (var transaction = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromHours(1)))
     {
         var list   = CreateListFromExcelBase64(importDTO);
         var result = GetSaveResults(list, dateStamp);
         Db.SaveChanges();
         transaction.Complete();
         return(result);
     }
 }
示例#2
0
        public List <BTSDTO> CreateListFromExcelBase64(BTSImportDTO importDTO)
        {
            var base64 = importDTO.File;

            base64 = base64.Replace("data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,", "");
            var wb    = ExcelConverter.FromBase64(base64);
            var sheet = wb.Worksheet("BTSUpload");

            var           nonEmptyRowCount = sheet.RowsUsed().Count() + 1;
            var           areaQuery        = new AreaQuery(Db);
            var           operatorQuery    = new OperatorQuery(Db);
            var           technologyQuery  = new TechnologyQuery(Db);
            var           btsQuery         = new BTSQuery(Db);
            List <BTSDTO> btsList          = new List <BTSDTO>();

            //first index is 1, and the first one is header title
            for (int i = 2; i < nonEmptyRowCount; i++)
            {
                var row     = sheet.Row(i);
                var towerId = row.Cell(1).Value.ToString();
                var btsName = row.Cell(2).Value.ToString();

                //get by itsname first;
                var btsDtoOnDb = btsQuery.GetByTowerID(towerId);
                var btsPk      = 0;

                if (btsDtoOnDb == null)
                {
                    btsDtoOnDb = btsQuery.GetByName(btsName);
                }

                if (btsDtoOnDb != null)
                {
                    btsPk = btsDtoOnDb.BTS_PK;
                }

                var cellId = row.Cell(3).Value.ToString();

                var operatorName = row.Cell(4).Value.ToString();
                var operatorId   = operatorQuery.GetByTitle(operatorName).Operator_PK;

                var longitude = Convert.ToString(row.Cell(5).Value);
                var latitude  = Convert.ToString(row.Cell(6).Value);

                var areaName = row.Cell(7).Value.ToString();
                var areaId   = areaQuery.GetByTitle(areaName).Area_PK;

                var address = row.Cell(8).Value.ToString();
                var status  = row.Cell(9).Value.ToString();

                List <BTSTechnologyDTO> techno = new List <BTSTechnologyDTO>();

                var technology = row.Cell(10).Value.ToString().Split(';').ToList();
                foreach (var item in technology)
                {
                    BTSTechnologyDTO itemtech = new BTSTechnologyDTO();
                    try
                    {
                        itemtech.Technology_FK = technologyQuery.GetByTitle(item).Technology_PK;
                    }
                    catch (Exception)
                    {
                        itemtech.Technology_FK = 0;
                    }
                    techno.Add(itemtech);
                }



                btsList.Add(new BTSDTO()
                {
                    BTS_PK          = btsPk,
                    Name            = btsName,
                    CellID          = cellId,
                    Latitude        = latitude,
                    Longitude       = longitude,
                    Alamat          = address,
                    Area_FK         = areaId,
                    AreaTitle       = areaName,
                    OperatorTitle   = operatorName,
                    Operator_FK     = operatorId,
                    Status_FK       = 1,
                    TowerID         = towerId,
                    StatusBTS_FK    = 1,
                    BTSTechnologies = techno
                });
            }

            return(btsList);
        }