示例#1
0
 public void AddToPaycheckTotal(DateTime date, string id, decimal amount)
 {
     if (Paychecks.TryGetValue(id, out var paycheck))
     {
         paycheck.Total += amount;
         AddNotice(date, $"Paycheck Update({paycheck.Name} to {paycheck.Total:C2})");
     }
 }
示例#2
0
        public static async System.Threading.Tasks.Task <Paychecks> GetEmployeePaychecksFromTempworksAsync(int id)
        {
            using (HttpClient client = new HttpClient())
            {
                // Call asynchronous network methods in a try/catch block to handle exceptions
                client.DefaultRequestHeaders.Add("x-tw-token", APIKey);
                var result = await client.GetAsync("https://api.ontempworks.com/Employees/" + id.ToString() + "/paychecks?take=1&skip=0&OrderBy=checkDate&orderByAscending=false");

                Paychecks custs = await result.Content.ReadFromJsonAsync <Paychecks>();

                return(custs);
            }
        }
        public bool CreatePaychecks(PaychecksCreate model, int moneyFlowID)
        {
            var entity =
                new Paychecks()
            {
                OwnerID     = _userID,
                MoneyFlowID = moneyFlowID,
                Name        = model.Name,
                AmountPaid  = model.AmountPaid,
                CreatedUtc  = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Paychecks.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#4
0
        public async Task <IActionResult> GetEmployeePaychecksAsync()
        {
            var emps = _context.GetEmployeeListAsync().Result;

            string conStr = ConnectionString;

            using (SqlConnection con = new SqlConnection(conStr))
            {
                try
                {
                    con.Open();
                    foreach (DataLayer.Models.TempWorksDB.EmployeeList e in emps)
                    {
                        try
                        {
                            Paychecks docs = await TempWorksAPI.GetEmployeePaychecksFromTempworksAsync(e.EmployeeId);

                            if (docs.TotalCount > 0)
                            {
                                foreach (Paycheck doc in docs.data)
                                {
                                    DataLayer.TempWorks.SetLastPayCheckProc(con, e.EmployeeId, Convert.ToDateTime(doc.checkDate));
                                }
                                _context.SaveErrorProc(con, "Set LastPaycheck for employee " + e.EmployeeId.ToString(), "");
                            }
                        }
                        catch (Exception ex)
                        {
                            _context.SaveErrorProc(con, "Error Updating Employee LastPayCheck " + e.EmployeeId.ToString(), ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _context.SaveErrorProc(con, "Error updating employee checkdate", ex.Message);
                    return(BadRequest(ex.Message));
                }
            }
            return(Ok());
        }