예제 #1
0
 public EmployeeModel RetrieveEmployeeById(long employeeId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var EMPLOYEE = context.EMPLOYEE.FirstOrDefault(emp => emp.EMPLOYEE_ID == employeeId);
             if (EMPLOYEE != null)
             {
                 return(new  EmployeeModel
                 {
                     EmployeeId = EMPLOYEE.EMPLOYEE_ID,
                     DisplayName = EMPLOYEE.DISPLAY_NAME,
                     Username = EMPLOYEE.USERNAME.ToLower(),
                     IsAdmin = EMPLOYEE.ADMIN_FLAG.Equals("Y", StringComparison.OrdinalIgnoreCase) ? true : false,
                     IsEligible = EMPLOYEE.ELIGIBLE_FLAG.Equals("Y", StringComparison.OrdinalIgnoreCase) ? true : false
                 });
             }
             else
             {
                 return(null);
             }
         }
     }
     catch { throw; }
 }
예제 #2
0
        public long CreateEmployee(string userName, string displayName, bool isAdmin, bool isEligible, int balance, long cycleId, DateTime balanceEffectiveDate)
        {
            try
            {
                using (var context = new GritCoinEntities())
                {
                    var EMPLOYEE = new EMPLOYEE
                    {
                        EMPLOYEE_ID   = GetSequenceNextValue(context, "GRITCOIN.EMPLOYEE_SEQ"),
                        USERNAME      = userName.ToLower(),
                        DISPLAY_NAME  = displayName,
                        ADMIN_FLAG    = isAdmin ? "Y" : "N",
                        ELIGIBLE_FLAG = isEligible ? "Y" : "N"
                    };
                    context.AddToEMPLOYEE(EMPLOYEE);
                    context.SaveChanges();

                    var BALANCE_TO_AWARD = new BALANCE_TO_AWARD
                    {
                        BALANCE_TO_AWARD_ID = GetSequenceNextValue(context, "GRITCOIN.BALANCE_TO_AWARD_SEQ"),
                        CYCLES         = context.CYCLES.FirstOrDefault(cyc => cyc.CYCLE_ID == cycleId),
                        COUNT          = balance,
                        EFFECTIVE_DATE = balanceEffectiveDate,
                        EMPLOYEE       = EMPLOYEE
                    };
                    context.AddToBALANCE_TO_AWARD(BALANCE_TO_AWARD);
                    context.SaveChanges();

                    return(EMPLOYEE.EMPLOYEE_ID);
                }
            }
            catch { throw; }
        }
예제 #3
0
        public EmployeeModel GetEmployeeByUsername(string username)
        {
            using (var context = new GritCoinEntities())
            {
                EMPLOYEE employee = context.EMPLOYEE.FirstOrDefault(emp => emp.USERNAME.ToLower() == username.ToLower());
                if (employee != null)
                {
                    //TODO remove balances if not needed
                    List <BalanceToAwardModel> balances = employee.BALANCE_TO_AWARD
                                                          .Select(bal => new BalanceToAwardModel
                    {
                        BalanceToAwardId = bal.BALANCE_TO_AWARD_ID,
                        Balance          = bal.COUNT,
                        EffectiveDate    = bal.EFFECTIVE_DATE,
                        Cycle            = ConvertCycleToCycleModel(bal.CYCLES)
                    }).ToList();

                    return(new EmployeeModel
                    {
                        EmployeeId = employee.EMPLOYEE_ID,
                        DisplayName = employee.DISPLAY_NAME,
                        Username = employee.USERNAME,
                        IsAdmin = employee.ADMIN_FLAG == "Y" ? true : false,
                        IsEligible = employee.ELIGIBLE_FLAG == "Y" ? true : false,
                        BalancesToAward = balances
                    });
                }
            }
            return(null);
        }
예제 #4
0
 public BalanceToAwardModel RetrieveBalanceToAwardById(long balanceToAwardId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var BALANCE = context.BALANCE_TO_AWARD.FirstOrDefault(BALANCE_TO_AWARD => BALANCE_TO_AWARD.BALANCE_TO_AWARD_ID == balanceToAwardId);
             if (BALANCE != null)
             {
                 return(new BalanceToAwardModel
                 {
                     Balance = BALANCE.COUNT,
                     BalanceToAwardId = BALANCE.BALANCE_TO_AWARD_ID,
                     EffectiveDate = BALANCE.EFFECTIVE_DATE,
                     Cycle = new CycleModel
                     {
                         CycleId = BALANCE.CYCLES.CYCLE_ID,
                         StartDate = BALANCE.CYCLES.START_DATE.Value,
                         EndDate = BALANCE.CYCLES.END_DATE.Value
                     }
                 });
             }
             else
             {
                 return(null);
             }
         }
     }
     catch { throw; }
 }
예제 #5
0
 public List <BalanceToAwardModel> RetrieveBalanceToAwardListByCycle(long?cycleId)
 {
     if (!cycleId.HasValue)
     {
         cycleId = CurrentCycle.CycleId;
     }
     try
     {
         using (var context = new GritCoinEntities())
         {
             return(context.BALANCE_TO_AWARD.Where(BALANCE => BALANCE.CYCLE_ID == cycleId).Select(
                        BALANCE => new BalanceToAwardModel
             {
                 Balance = BALANCE.COUNT,
                 BalanceToAwardId = BALANCE.BALANCE_TO_AWARD_ID,
                 EffectiveDate = BALANCE.EFFECTIVE_DATE,
                 Cycle = new CycleModel
                 {
                     CycleId = BALANCE.CYCLES.CYCLE_ID,
                     StartDate = BALANCE.CYCLES.START_DATE.Value,
                     EndDate = BALANCE.CYCLES.END_DATE.Value
                 }
             }).OrderByDescending(bal => bal.BalanceToAwardId).ToList());
         }
     }
     catch { throw; }
 }
예제 #6
0
        public void CreateBalanceToAwardToAllEligibleUsers(long balance, DateTime effectiveDate, long cycleId)
        {
            try
            {
                using (var context = new GritCoinEntities())
                {
                    List <EmployeeModel> users = new EmployeeService().RetrieveEmployeeList().Where(Emp => Emp.IsEligible).ToList();
                    foreach (EmployeeModel user in users)
                    {
                        var BALANCE_TO_AWARD = new BALANCE_TO_AWARD
                        {
                            BALANCE_TO_AWARD_ID = GetSequenceNextValue(context, "GRITCOIN.BALANCE_TO_AWARD_SEQ"),
                            COUNT          = balance,
                            EFFECTIVE_DATE = effectiveDate,
                            CYCLE_ID       = cycleId,
                            EMPLOYEE_ID    = user.EmployeeId
                        };

                        context.AddToBALANCE_TO_AWARD(BALANCE_TO_AWARD);
                    }
                    context.SaveChanges();
                }
            }
            catch { throw; }
        }
예제 #7
0
 public long CreateTransaction(long senderId, long recipientId, bool isAnonymous, TransactionState state, string comment, bool?fromPool = null)
 {
     if (senderId == recipientId)
     {
         throw new Exception("Sender and receiver can't be the same");
     }
     try
     {
         using (var context = new GritCoinEntities())
         {
             var SENDER = context.EMPLOYEE.FirstOrDefault(EMP => EMP.EMPLOYEE_ID == senderId);
             if (!fromPool.HasValue || fromPool.Value == false)
             {
                 fromPool = SENDER != null && SENDER.ELIGIBLE_FLAG == "N" ? true : false;
             }
             var TRANSACTION = new TRANSACTIONS
             {
                 TRANSACTION_ID     = GetSequenceNextValue(context, "GRITCOIN.TRANSACTIONS_SEQ"),
                 ANONYMOUS_FLAG     = isAnonymous ? "Y" : "N",
                 EFFECTIVE_DATE     = DateTime.Now,
                 CYCLE_ID           = CurrentCycle.CycleId,
                 RECIPIENT          = recipientId,
                 SENDER             = senderId,
                 SYSTEM_CHANGE_DATE = DateTime.Now,
                 TRANSACTION_STATE  = state.ToString(),
                 NOTE           = comment,
                 FROM_POOL_FLAG = fromPool.HasValue && fromPool.Value ? "Y" : "N"
             };
             context.AddToTRANSACTIONS(TRANSACTION);
             context.SaveChanges();
             return(TRANSACTION.TRANSACTION_ID);
         }
     }
     catch { throw; }
 }
예제 #8
0
 public List <Tuple <string, string> > GetAllValidToReceiveUsers(long currentEmployeeId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             List <EMPLOYEE> EMPLOYEES = context.EMPLOYEE.Where(EMP => EMP.ELIGIBLE_FLAG == "Y" && EMP.EMPLOYEE_ID != currentEmployeeId).ToList();
             return(EMPLOYEES.OrderBy(EMP => EMP.DISPLAY_NAME).Select(EMP => new Tuple <string, string>(EMP.DISPLAY_NAME, EMP.EMPLOYEE_ID.ToString())).ToList());
         }
     }
     catch { throw; }
 }
예제 #9
0
        protected long GetSequenceNextValue(GritCoinEntities context, string sequenceName)
        {
            long    returnValue = 0;
            decimal?nextValue   = null;

            context.GET_SEQUENCE_NEXT_VALUE(sequenceName, ref nextValue);

            if (nextValue.HasValue)
            {
                returnValue = (long)nextValue;
            }

            return(returnValue);
        }
예제 #10
0
 public void DeleteEmployee(long employeeId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var EMPLOYEE = context.EMPLOYEE.FirstOrDefault(emp => emp.EMPLOYEE_ID == employeeId);
             if (EMPLOYEE != null)
             {
                 context.DeleteObject(EMPLOYEE);
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #11
0
 public void DeleteBalanceToAward(long balanceId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var BALANCE = context.BALANCE_TO_AWARD.FirstOrDefault(BALANCE_TO_AWARD => BALANCE_TO_AWARD.BALANCE_TO_AWARD_ID == balanceId);
             if (BALANCE != null)
             {
                 context.DeleteObject(BALANCE);
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #12
0
 public void DeleteTransaction(long transactionId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 context.DeleteObject(TRANSACTION);
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #13
0
 public void DeleteCycle(long cycleId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var cycle = context.CYCLES.FirstOrDefault(cyc => cyc.CYCLE_ID == cycleId);
             if (cycle != null)
             {
                 context.DeleteObject(cycle);
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #14
0
 public void UpdateStatus(long transactionId, TransactionState state)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 TRANSACTION.TRANSACTION_STATE = state.ToString();
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #15
0
 public TransactionModel RetrieveTransactionById(long transactionId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 return(new TransactionModel
                 {
                     TransactionId = TRANSACTION.TRANSACTION_ID,
                     CycleId = TRANSACTION.CYCLE_ID,
                     EffectiveDate = TRANSACTION.EFFECTIVE_DATE,
                     GritCoin = TRANSACTION.COINS == null ? null : new GCMS.Oracle.DataTransferObjects.GritCoinModel
                     {
                         CoinId = TRANSACTION.COINS.GRITCOIN_ID,
                         CoinNumber = TRANSACTION.COINS.SERIAL_NUMBER
                     },
                     IsAnonymous = TRANSACTION.ANONYMOUS_FLAG == "Y" ? true : false,
                     Recipient = new EmployeeModel
                     {
                         DisplayName = TRANSACTION.EMPLOYEE_RECIPIENT.DISPLAY_NAME,
                         EmployeeId = TRANSACTION.EMPLOYEE_RECIPIENT.EMPLOYEE_ID
                     },
                     Sender = new EmployeeModel
                     {
                         DisplayName = TRANSACTION.EMPLOYEE_SENDER.DISPLAY_NAME,
                         EmployeeId = TRANSACTION.EMPLOYEE_SENDER.EMPLOYEE_ID,
                     },
                     SystemChangeDate = TRANSACTION.SYSTEM_CHANGE_DATE,
                     TransactionState = (TransactionState)Enum.Parse(typeof(TransactionState), TRANSACTION.TRANSACTION_STATE),
                     Comment = TRANSACTION.NOTE,
                     FromPool = TRANSACTION.FROM_POOL_FLAG == "Y" ? true : false,
                     SpentDate = TRANSACTION.SPENT_DATE,
                     SpendComment = TRANSACTION.SPENT_NOTE
                 });
             }
             else
             {
                 return(null);
             }
         }
     }
     catch { throw; }
 }
예제 #16
0
 public List <CycleModel> RetrieveCyclesList()
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             return(context.CYCLES.Select(
                        cycle => new CycleModel
             {
                 CycleId = cycle.CYCLE_ID,
                 StartDate = cycle.START_DATE.Value,
                 EndDate = cycle.END_DATE.Value
             }).OrderByDescending(cyc => cyc.CycleId).ToList());
         }
     }
     catch { throw; }
 }
예제 #17
0
 public void SpendTransaction(long transactionId, string comment)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 TRANSACTION.SPENT_NOTE = comment;
                 TRANSACTION.SPENT_DATE = DateTime.Now;
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #18
0
 public void UpdateCycle(long cycleId, DateTime startDate, DateTime endDate)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var cycle = context.CYCLES.FirstOrDefault(cyc => cyc.CYCLE_ID == cycleId);
             if (cycle != null)
             {
                 cycle.START_DATE = startDate;
                 cycle.END_DATE   = endDate;
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #19
0
 public void UpdateStatusDeclinedNote(long transactionId, string note)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 TRANSACTION.DECLINED_NOTE     = note;
                 TRANSACTION.TRANSACTION_STATE = TransactionState.Declined.ToString();
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #20
0
 public void UpdateTransaction(long transactionId, TransactionState state, long coinSerialNumber)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var TRANSACTION = context.TRANSACTIONS.FirstOrDefault(TRA => TRA.TRANSACTION_ID == transactionId);
             if (TRANSACTION != null)
             {
                 TRANSACTION.TRANSACTION_STATE = state.ToString();
                 TRANSACTION.GRITCOIN_ID       = GetOrCreateCoinId(coinSerialNumber);
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #21
0
 public List <TransactionModel> RetrievePoolTransactionListByCycle(long?cycleId)
 {
     try
     {
         if (!cycleId.HasValue)
         {
             cycleId = CurrentCycle.CycleId;
         }
         using (var context = new GritCoinEntities())
         {
             return(context.TRANSACTIONS.Where(TRANSACTION => TRANSACTION.CYCLE_ID == cycleId && TRANSACTION.FROM_POOL_FLAG == "Y").ToList().Select(
                        TRANSACTION => new TransactionModel
             {
                 TransactionId = TRANSACTION.TRANSACTION_ID,
                 CycleId = TRANSACTION.CYCLE_ID,
                 EffectiveDate = TRANSACTION.EFFECTIVE_DATE,
                 GritCoin = TRANSACTION.COINS == null ? null : new GCMS.Oracle.DataTransferObjects.GritCoinModel
                 {
                     CoinId = TRANSACTION.COINS.GRITCOIN_ID,
                     CoinNumber = TRANSACTION.COINS.SERIAL_NUMBER
                 },
                 IsAnonymous = TRANSACTION.ANONYMOUS_FLAG == "Y" ? true : false,
                 Recipient = new EmployeeModel
                 {
                     DisplayName = TRANSACTION.EMPLOYEE_RECIPIENT.DISPLAY_NAME,
                     EmployeeId = TRANSACTION.EMPLOYEE_RECIPIENT.EMPLOYEE_ID
                 },
                 Sender = new EmployeeModel
                 {
                     DisplayName = TRANSACTION.EMPLOYEE_SENDER.DISPLAY_NAME,
                     EmployeeId = TRANSACTION.EMPLOYEE_SENDER.EMPLOYEE_ID,
                     IsAdmin = TRANSACTION.EMPLOYEE_SENDER.ADMIN_FLAG == "Y" ? true : false,
                     IsEligible = TRANSACTION.EMPLOYEE_SENDER.ELIGIBLE_FLAG == "Y" ? true : false,
                 },
                 SystemChangeDate = TRANSACTION.SYSTEM_CHANGE_DATE,
                 TransactionState = (TransactionState)Enum.Parse(typeof(TransactionState), TRANSACTION.TRANSACTION_STATE),
                 Comment = TRANSACTION.NOTE,
                 FromPool = TRANSACTION.FROM_POOL_FLAG == "Y" ? true : false,
                 SpentDate = TRANSACTION.SPENT_DATE,
                 SpendComment = TRANSACTION.SPENT_NOTE
             }).ToList());
         }
     }
     catch { throw; }
 }
예제 #22
0
 public List <DataTransferObjects.GritCoinModel> RetrieveCoins()
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             return(context.COINS.ToList().Select(COINS => new DataTransferObjects.GritCoinModel
             {
                 CoinNumber = COINS.SERIAL_NUMBER,
                 CoinId = COINS.GRITCOIN_ID
             }).ToList());
         }
     }
     catch
     {
         throw;
     }
 }
예제 #23
0
 public void UpdateBalanceToAward(long balanceId, long balance, DateTime effectiveDate, long cycleId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var BALANCE = context.BALANCE_TO_AWARD.FirstOrDefault(BALANCE_TO_AWARD => BALANCE_TO_AWARD.BALANCE_TO_AWARD_ID == balanceId);
             if (BALANCE != null)
             {
                 BALANCE.COUNT          = balance;
                 BALANCE.CYCLE_ID       = cycleId;
                 BALANCE.EFFECTIVE_DATE = effectiveDate;
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #24
0
 public void UpdateEmployee(long employeeId, bool isAdmin, bool isEligible, string displayName)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var EMPLOYEE = context.EMPLOYEE.FirstOrDefault(emp => emp.EMPLOYEE_ID == employeeId);
             if (EMPLOYEE != null)
             {
                 EMPLOYEE.DISPLAY_NAME  = displayName;
                 EMPLOYEE.ADMIN_FLAG    = isAdmin ? "Y" : "N";
                 EMPLOYEE.ELIGIBLE_FLAG = isEligible ? "Y" : "N";
                 context.SaveChanges();
             }
         }
     }
     catch { throw; }
 }
예제 #25
0
 public List <EmployeeModel> RetrieveEmployeeList()
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             return(context.EMPLOYEE.Select(
                        EMPLOYEE => new EmployeeModel
             {
                 EmployeeId = EMPLOYEE.EMPLOYEE_ID,
                 DisplayName = EMPLOYEE.DISPLAY_NAME,
                 Username = EMPLOYEE.USERNAME.ToLower(),
                 IsAdmin = EMPLOYEE.ADMIN_FLAG.Equals("Y", StringComparison.OrdinalIgnoreCase) ? true : false,
                 IsEligible = EMPLOYEE.ELIGIBLE_FLAG.Equals("Y", StringComparison.OrdinalIgnoreCase) ? true : false
             }).OrderBy(emp => emp.DisplayName).ToList());
         }
     }
     catch { throw; }
 }
예제 #26
0
        public long CreateCycle(DateTime startDate, DateTime endDate)
        {
            try
            {
                using (var context = new GritCoinEntities())
                {
                    var cycle = new CYCLES
                    {
                        CYCLE_ID   = GetSequenceNextValue(context, "GRITCOIN.CYCLES_SEQ"),
                        START_DATE = startDate,
                        END_DATE   = endDate
                    };

                    context.AddToCYCLES(cycle);
                    context.SaveChanges();
                    return(cycle.CYCLE_ID);
                }
            }
            catch { throw; }
        }
예제 #27
0
 public long GetOrCreateCoinId(long serialNumber)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var COIN = context.COINS.FirstOrDefault(CO => CO.SERIAL_NUMBER == serialNumber);
             if (COIN == null)
             {
                 COIN = new COINS
                 {
                     GRITCOIN_ID   = GetSequenceNextValue(context, "GRITCOIN.COINS_SEQ"),
                     SERIAL_NUMBER = serialNumber
                 };
                 context.AddToCOINS(COIN);
                 context.SaveChanges();
             }
             return(COIN.GRITCOIN_ID);
         }
     }
     catch { throw; }
 }
예제 #28
0
        public long CreateBalanceToAward(long balance, DateTime effectiveDate, long cycleId, long userId)
        {
            try
            {
                using (var context = new GritCoinEntities())
                {
                    var BALANCE_TO_AWARD = new BALANCE_TO_AWARD
                    {
                        BALANCE_TO_AWARD_ID = GetSequenceNextValue(context, "GRITCOIN.BALANCE_TO_AWARD_SEQ"),
                        COUNT          = balance,
                        EFFECTIVE_DATE = effectiveDate,
                        CYCLE_ID       = cycleId,
                        EMPLOYEE_ID    = userId
                    };

                    context.AddToBALANCE_TO_AWARD(BALANCE_TO_AWARD);
                    context.SaveChanges();
                    return(BALANCE_TO_AWARD.BALANCE_TO_AWARD_ID);
                }
            }
            catch { throw; }
        }
예제 #29
0
 public CycleModel RetrieveCycleById(long cycleId)
 {
     try
     {
         using (var context = new GritCoinEntities())
         {
             var CYCLE = context.CYCLES.FirstOrDefault(cyc => cyc.CYCLE_ID == cycleId);
             if (CYCLE != null)
             {
                 return(new CycleModel
                 {
                     CycleId = CYCLE.CYCLE_ID,
                     StartDate = CYCLE.START_DATE.Value,
                     EndDate = CYCLE.END_DATE.Value
                 });
             }
             else
             {
                 return(null);
             }
         }
     }
     catch { throw; }
 }