Exemplo n.º 1
0
        public void saveAbsensiEmployee(string dataDetail, int employeeId)
        {
            int dataInput = 0;
            string[] RowData = dataDetail.Split('|');

            for (int i = 0; i < (RowData.Count() - 1); i++)
            {
                string[] value = RowData[i].Split(';');
                DateTime dateAbsensi = Convert.ToDateTime(value[0].ToString());
                TimeSpan? hourIn = null;
                TimeSpan? hourOut = null;
                int? absensiType = null;
                string remark = null;

                try
                {
                    var getDataBefore = db.absensiEmployees.Where(x => x.employeeID == employeeId && x.date == dateAbsensi.Date).ToList();

                    var id = 0;
                    if (getDataBefore.Count > 0)
                    {
                        id = getDataBefore[0].id;
                    }

                    if (id != 0 && value[1].ToString() == string.Empty && value[2].ToString() == string.Empty && value[3].ToString() == string.Empty && value[4].ToString() == string.Empty)
                    {
                        absensiEmployee ae = db.absensiEmployees.Find(id);
                        db.absensiEmployees.Remove(ae);
                        db.SaveChanges();
                    }
                    else
                    {
                        if(value[3].ToString() == "")
                        {
                            hourIn = TimeSpan.Parse(value[1].ToString());
                            hourOut = TimeSpan.Parse(value[2].ToString());
                        }
                        else
                        { 
                            absensiType = int.Parse(value[3].ToString());
                            remark = value[4].ToString();
                        }

                
                        absensiEmployee ae = db.absensiEmployees.Find(id);
                        if (ae != null)
                        {
                            ae.checkIn = hourIn;
                            ae.checkOut = hourOut;
                            ae.typeAbsensiID = absensiType;
                            ae.remarks = remark;
                            db.Entry(ae).State = EntityState.Modified;
                        }
                        else
                        {
                            absensiEmployee abe = new absensiEmployee();
                            abe.employeeID = employeeId;
                            abe.date = dateAbsensi.Date;
                            abe.checkIn = hourIn;
                            abe.checkOut = hourOut;
                            abe.typeAbsensiID = absensiType;
                            abe.remarks = remark;
                            db.absensiEmployees.Add(abe);
                        }
                        db.SaveChanges();
                    }
                }
                catch(Exception exc)
                {
                    string a = exc.Message;
                }
            }

            if (dataInput > 0)
                db.SaveChanges();
        }
Exemplo n.º 2
0
        public void loadAbsensiEmployee(int year, int month, int employeeID)
        {
            int maxDate = DateTime.DaysInMonth(year, month);
            var start = new DateTime(year, month, 1);
            var end = new DateTime(year, month, maxDate);

            var empAbsensi = db.absensiEmployees.Where(x=>x.date >= start.Date && x.date <= end.Date && x.employeeID == employeeID).ToList();

            var model = new absensiEmployee();
            for (int i = 0; i < empAbsensi.Count; i++)
            {
                var editor = new absensiEmployee.absensiEmployeeDetail()
                {
                    id = empAbsensi[0].id,
                    employeeID = empAbsensi[0].employeeID,
                    date = empAbsensi[0].date,
                    checkIn = empAbsensi[0].checkIn,
                    checkOut = empAbsensi[0].checkOut,
                    typeAbsensiID = empAbsensi[0].typeAbsensiID,
                    remarks = empAbsensi[0].remarks
                };
                model.detailEmployeeAbsensi.Add(editor);
            }
            ViewBag.detailAbsensiEmployee = model.detailEmployeeAbsensi.ToList();
        }