Пример #1
0
        public IList <GrupCustomer> GetAll()
        {
            IList <GrupCustomer> oList = null;

            if (_isUseWebAPI)
            {
                //_unitOfWork = new UnitOfWork(_isUseWebAPI, _baseUrl, _log);
                //oList = _unitOfWork.GrupCustomerRepository.GetAll();
            }
            else
            {
                using (IDapperContext context = new DapperContext())
                {
                    GrupCustomerRepository repo = new GrupCustomerRepository(context, _log);
                    oList = repo.GetAll();
                }
            }

            return(oList);
        }
Пример #2
0
        public int SoftDelete(GrupCustomer obj)
        {
            var result = 0;

            if (_isUseWebAPI)
            {
                //_unitOfWork = new UnitOfWork(_isUseWebAPI, _baseUrl, _log);
                //result = _unitOfWork.GrupCustomerRepository.Delete(obj);
            }
            else
            {
                using (IDapperContext context = new DapperContext())
                {
                    GrupCustomerRepository repo = new GrupCustomerRepository(context, _log);
                    result = repo.Delete(obj, true);
                }
            }

            return(result);
        }
Пример #3
0
        public GrupCustomer GetByID(int id)
        {
            GrupCustomer obj = null;

            if (_isUseWebAPI)
            {
                // TODO: not implemented yet
                //_unitOfWork = new UnitOfWork(_isUseWebAPI, _baseUrl, _log);
                //obj = _unitOfWork.GrupCustomerRepository.GetByID(id);
            }
            else
            {
                using (IDapperContext context = new DapperContext())
                {
                    GrupCustomerRepository repo = new GrupCustomerRepository(context, _log);
                    obj = repo.GetByID(id);
                }
            }

            return(obj);
        }
Пример #4
0
        public int Save(GrupCustomer obj)
        {
            var result = 0;

            if (_isUseWebAPI)
            {
                //obj.GrupCustomer_id = Guid.NewGuid().ToString();

                //_unitOfWork = new UnitOfWork(_isUseWebAPI, _baseUrl, _log);
                //result = _unitOfWork.GrupCustomerRepository.Save(obj);
            }
            else
            {
                using (IDapperContext context = new DapperContext())
                {
                    GrupCustomerRepository repo = new GrupCustomerRepository(context, _log);
                    result = repo.Save(obj);
                }
            }

            return(result);
        }
Пример #5
0
        public bool Import(string workSheetName, ref int rowCount)
        {
            var result = false;

            try
            {
                var ws = _workbook.Worksheet(workSheetName);

                // Look for the first row used
                var firstRowUsed = ws.FirstRowUsed();

                // Narrow down the row so that it only includes the used part
                var golonganRow = firstRowUsed.RowUsed();

                // First possible address of the company table:
                var firstPossibleAddress = ws.Row(golonganRow.RowNumber()).FirstCell().Address;

                // Last possible address of the company table:
                var lastPossibleAddress = ws.LastCellUsed().Address;

                // Get a range with the remainder of the worksheet data (the range used)
                var golonganRange = ws.Range(firstPossibleAddress, lastPossibleAddress).RangeUsed();

                // Treat the range as a table (to be able to use the column names)
                var grupCustomerTable = golonganRange.AsTable();

                var listOfGrupCustomer = new List <GrupCustomer>();

                listOfGrupCustomer = grupCustomerTable.DataRange.Rows().Select(row => new GrupCustomer
                {
                    nama_grup = row.Field("NAMA GRUP").GetString(),
                    deskripsi = row.Field("DESKRIPSI").GetString()
                }).ToList();

                if (listOfGrupCustomer.Count == 1 && listOfGrupCustomer[0].nama_grup.Length == 0)
                {
                    rowCount = 0;
                    return(false);
                }

                rowCount = listOfGrupCustomer.Count;

                using (IDapperContext context = new DapperContext())
                {
                    GrupCustomerRepository repo = new GrupCustomerRepository(context, _log);

                    foreach (var grupCustomer in listOfGrupCustomer)
                    {
                        if (grupCustomer.nama_grup.Length > 0)
                        {
                            // cek duplikasi data berdasarkan nama grup
                            if (grupCustomer.nama_grup.Length > 30)
                            {
                                grupCustomer.nama_grup = grupCustomer.nama_grup.Substring(0, 50);
                            }

                            var oldGrupCustomer = repo.GetByName(grupCustomer.nama_grup, false)
                                                  .FirstOrDefault();

                            // hanya data yg belum ada akan di import
                            if (oldGrupCustomer == null)
                            {
                                result = Convert.ToBoolean(repo.Save(grupCustomer));
                            }
                        }
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                _log.Error("Error:", ex);
            }
            finally
            {
                _workbook.Dispose();
            }

            return(result);
        }