Exemplo n.º 1
0
        public async Task <List <AbsenceModel> > GetMonthlyOffRecordAsync(string y, string m)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                var      year     = Int32.Parse(y);
                var      month    = Int32.Parse(m);
                DateTime fromTime = new DateTime(year, month, 1);
                DateTime toTime   = new DateTime(year, month + 1, 1).AddSeconds(-1);
                var      data     = await(from record in dbContext.CheckRecord
                                          join user in dbContext.UserInfo on record.UserId equals user.Id
                                          where record.CheckedDate >= fromTime && record.CheckedDate <= toTime &&
                                          !string.IsNullOrWhiteSpace(record.OffType) &&
                                          record.StatusOfApproval != StatusOfApprovalEnum.REJECTED()
                                          select new AbsenceModel
                {
                    UserName         = user.UserName,
                    CheckedDate      = record.CheckedDate.ToString("yyyy-MM-dd"),
                    OffType          = record.OffType,
                    OffTimeStart     = record.OffTimeStart.ToString(),
                    OffTimeEnd       = record.OffTimeEnd.ToString(),
                    OffReason        = record.OffReason,
                    StatusOfApproval = record.StatusOfApproval
                }).ToListAsync();

                return(data);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> SetStatusOfApprovalAsync(string recordId, string status, bool OT = false)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                try
                {
                    dbContext.ChangeTracker.AutoDetectChangesEnabled = false;
                    var record = await dbContext.CheckRecord.FirstOrDefaultAsync(s => s.Id == recordId);

                    if (record == null)
                    {
                        return(false);
                    }
                    if (status == StatusOfApprovalEnum.APPROVED())
                    {
                        if (OT)
                        {
                            record.StatusOfApprovalForOvertime = status;
                        }
                        else
                        {
                            var user = await dbContext.UserInfo.FirstOrDefaultAsync(s => s.Id == record.UserId);

                            user = TypeEnum.CalcLeaves(user, record.OffTimeStart, record.OffTimeEnd, record.OffType);
                            if (user == null)
                            {
                                record.StatusOfApproval = StatusOfApprovalEnum.REJECTED();
                            }
                            else
                            {
                                dbContext.Entry(user).State = EntityState.Modified;
                                record.StatusOfApproval     = status;
                            }
                        }
                    }
                    else
                    {
                        if (OT)
                        {
                            record.StatusOfApprovalForOvertime = status;
                        }
                        else
                        {
                            record.StatusOfApproval = status;
                        }
                    }
                    dbContext.Entry(record).State = EntityState.Modified;
                    await dbContext.SaveChangesAsync();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }