Пример #1
0
        public IHttpActionResult ChamCong([FromBody] ThongTinChamCong obj)
        {
            Employee emp = obj._token;

            var nowTime = DateTime.Now;

            var fromDate = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 00, 00, 00);
            var toDate   = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, 23, 59, 59);



            var checkExist            = db.Attendance_Header.Where(w => w.RowIDEmployee == emp.RowID && w.AttendanceShortDate.Value >= fromDate && w.AttendanceShortDate.Value <= toDate).Count();
            int rowIDAttendanceHeader = 0;

            if (checkExist == 0)
            {
                Attendance_Header hd = new Attendance_Header();
                hd.AttendanceShortDate = nowTime;
                hd.CreatedDate         = nowTime;
                hd.RowIDEmployee       = emp.RowID;
                db.Attendance_Header.Add(hd);
                db.SaveChanges();
                rowIDAttendanceHeader = hd.RowID;
            }
            else
            {
                rowIDAttendanceHeader = db.Attendance_Header.Where(w => w.RowIDEmployee == emp.RowID && w.AttendanceShortDate.Value >= fromDate && w.AttendanceShortDate.Value <= toDate).FirstOrDefault().RowID;
            }



            Attendance_Detail a = new Attendance_Detail();

            a.RowIDAttendanceReason = obj.LyDoChamCong;
            a.RowIDEmployee         = emp.RowID;
            if (obj.LoaiChamCong == "IN")
            {
                a.Type   = "IN";
                a.Reason = obj.LyDoChamVao;
            }
            else
            {
                a.Type   = "OUT";
                a.Reason = obj.LyDoChamRa;
            }

            if (rowIDAttendanceHeader != 0)
            {
                a.RowIDAttendanceHeader = rowIDAttendanceHeader;
            }

            a.CreatedDate = nowTime;
            db.Attendance_Detail.Add(a);
            db.SaveChanges();

            return(Ok());
        }
Пример #2
0
        public IHttpActionResult ThemThoiGianChamcong([FromBody] ThongTinChamCong obj)
        {
            Employee emp = obj._token;



            var fromDate = new DateTime(obj.NgayDangKy.Year, obj.NgayDangKy.Month, obj.NgayDangKy.Day, 00, 00, 00);
            var toDate   = new DateTime(obj.NgayDangKy.Year, obj.NgayDangKy.Month, obj.NgayDangKy.Day, 23, 59, 59);



            var checkExistHeader = db.Attendance_Header.Where(w => w.AttendanceShortDate == fromDate && w.RowIDEmployee == obj.IDNguoiDuocChamCong).FirstOrDefault();


            if (checkExistHeader != null)
            {
                Attendance_Detail dt = new Attendance_Detail();
                dt.RowIDAttendanceHeader = checkExistHeader.RowID;
                dt.Type          = obj.LoaiChamCong;
                dt.RowIDEmployee = obj.IDNguoiDuocChamCong;
                dt.CreatedDate   = obj.NgayDangKy;

                if (obj.LoaiChamCong == "IN")
                {
                    dt.RowIDAttendanceReason = 3;
                }
                else
                {
                    dt.RowIDAttendanceReason = 4;
                }

                dt.RowIDEmployeeEdited = emp.RowID;


                db.Attendance_Detail.Add(dt);
                var affectedRow = db.SaveChanges();


                if (affectedRow > 0)
                {
                    return(Ok("Chỉnh sửa thành công !"));
                }
                else
                {
                    return(BadRequest("Chỉnh sửa AttendanceDetail không thành công !"));
                }
            }
            else
            {
                Attendance_Header hd = new Attendance_Header();
                hd.AttendanceShortDate  = fromDate;
                hd.RowIDEmployee        = obj.IDNguoiDuocChamCong;
                hd.RowIDEmployeeCreated = emp.RowID;


                db.Attendance_Header.Add(hd);
                int affectedRow = db.SaveChanges();

                if (affectedRow > 0)
                {
                    Attendance_Detail dt = new Attendance_Detail();
                    dt.RowIDAttendanceHeader = hd.RowID;
                    dt.Type          = obj.LoaiChamCong;
                    dt.RowIDEmployee = obj.IDNguoiDuocChamCong;
                    dt.CreatedDate   = obj.NgayDangKy;

                    if (obj.LoaiChamCong == "IN")
                    {
                        dt.RowIDAttendanceReason = 3;
                    }
                    else
                    {
                        dt.RowIDAttendanceReason = 4;
                    }

                    dt.RowIDEmployeeEdited = emp.RowID;


                    db.Attendance_Detail.Add(dt);
                    affectedRow = db.SaveChanges();


                    if (affectedRow > 0)
                    {
                        return(Ok("Chỉnh sửa thành công !"));
                    }
                    else
                    {
                        return(BadRequest("Chỉnh sửa AttendanceDetail không thành công !"));
                    }
                }
                else
                {
                    return(BadRequest("Chỉnh sửa AttendanceHeader không thành công !"));
                }
            }
        }