Ejemplo n.º 1
0
        public async Task DeleteOTAsync(string id, DateTime date)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                dbContext.ChangeTracker.AutoDetectChangesEnabled = false;
                var result =
                    await dbContext.CheckRecord.FirstOrDefaultAsync(s => s.UserId == id && s.CheckedDate == date);

                if (result == null)
                {
                    return;
                }
                if (result.CheckInTime == null && result.CheckOutTime == null &&
                    string.IsNullOrWhiteSpace(result.OvertimeEndTime))
                {
                    dbContext.Entry(result).State = EntityState.Deleted;
                }
                else
                {
                    result.OvertimeEndTime             = null;
                    result.StatusOfApprovalForOvertime = StatusOfApprovalEnum.PENDING();
                    dbContext.Entry(result).State      = EntityState.Modified;
                }
                await dbContext.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> AddLeaveAsync(string id, OffRecordModel model)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                dbContext.ChangeTracker.AutoDetectChangesEnabled = false;
                var recordList = new List <CheckRecord>();
                var records    = dbContext.CheckRecord.Where(
                    s => s.UserId == id &&
                    s.CheckedDate >= model.CheckedDate &&
                    s.CheckedDate <= model.OffEndDate);
                for (var i = model.CheckedDate.Date;
                     model.OffEndDate != null && i <= model.OffEndDate.Value.Date;
                     i = i.AddDays(1))
                {
                    var record = records.FirstOrDefault(s => s.CheckedDate.Date == i.Date);
                    if (record == null)
                    {
                        recordList.Add(new CheckRecord
                        {
                            UserId       = id,
                            CheckedDate  = i,
                            OffEndDate   = model.OffEndDate,
                            OffType      = model.OffType,
                            OffReason    = model.OffReason,
                            OffTimeStart = model.OffTimeStart,
                            OffTimeEnd   = model.OffTimeEnd,
                            OffApplyDate = DateTime.Today
                        });
                    }
                    else
                    {
                        record.UserId                 = id;
                        record.OffEndDate             = model.OffEndDate;
                        record.OffTimeStart           = model.OffTimeStart;
                        record.OffTimeEnd             = model.OffTimeEnd;
                        record.OffReason              = model.OffReason;
                        record.OffType                = model.OffType;
                        record.StatusOfApproval       = StatusOfApprovalEnum.PENDING();
                        record.OffApplyDate           = DateTime.Today;
                        dbContext.Entry(record).State = EntityState.Modified;
                    }
                }
                await dbContext.CheckRecord.AddRangeAsync(recordList);

                await dbContext.SaveChangesAsync();

                return(true);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> DeleteLeaveAsync(string id, DateTime date)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                dbContext.ChangeTracker.AutoDetectChangesEnabled = false;
                var result =
                    await dbContext.CheckRecord.FirstOrDefaultAsync(s => s.UserId == id && s.CheckedDate == date);

                if (result == null)
                {
                    return(false);
                }
                if (result.StatusOfApproval == StatusOfApprovalEnum.APPROVED())
                {
                    var user = await dbContext.UserInfo.FirstOrDefaultAsync(s => s.Id == result.UserId);

                    user = TypeEnum.CalcLeaves(user, result.OffTimeStart, result.OffTimeEnd,
                                               result.OffType, inverseOp: true);
                    dbContext.Entry(user).State = EntityState.Modified;
                }
                if (result.CheckInTime == null && result.CheckOutTime == null &&
                    string.IsNullOrWhiteSpace(result.OvertimeEndTime))
                {
                    dbContext.Entry(result).State = EntityState.Deleted;
                }
                else
                {
                    result.OffApplyDate           = null;
                    result.OffTimeStart           = null;
                    result.OffTimeEnd             = null;
                    result.OffEndDate             = null;
                    result.OffReason              = null;
                    result.OffType                = null;
                    result.StatusOfApproval       = StatusOfApprovalEnum.PENDING();
                    dbContext.Entry(result).State = EntityState.Modified;
                }
                await dbContext.SaveChangesAsync();

                return(true);
            }
        }
Ejemplo n.º 4
0
        public async Task AddOTAsync(string id, DateTime d, string t)
        {
            using (var dbContext = new AppDbContext(builder.Options))
            {
                var record = await dbContext.CheckRecord.FirstOrDefaultAsync(s => s.UserId == id && s.CheckedDate == d);

                if (record != null)
                {
                    record.OvertimeEndTime             = t;
                    record.StatusOfApprovalForOvertime = StatusOfApprovalEnum.PENDING();
                }
                else
                {
                    await dbContext.CheckRecord.AddAsync(new CheckRecord
                    {
                        UserId                      = id,
                        CheckedDate                 = d,
                        OvertimeEndTime             = t,
                        StatusOfApprovalForOvertime = StatusOfApprovalEnum.PENDING(),
                    });
                }
                await dbContext.SaveChangesAsync();
            }
        }