Exemplo n.º 1
0
        public TblEmployeeShift UpdateAndInsertTblEmployeeShift(TblEmployeeShift row, int index, int userIserial, out int outindex)
        {
            if (!Att.AttService.EmpCanEdit(row.TransDate, row.EmpId))
            {
                throw new Exception("Cannot edit a transaction because this period is already closed");
            }
            outindex = index;
            IEnumerable <string> changedList = null;
            bool save = row.Iserial == 0;

            using (var db = new TimeAttEntities())
            {
                var oldRow = (from e in db.TblEmployeeShifts
                              where e.EmpId == row.EmpId &&
                              e.TransDate == row.TransDate
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    if (row.CreationDate == DateTime.MinValue)
                    {
                        row.CreatedBy = userIserial;

                        row.CreationDate = DateTime.Now;
                    }
                    row.CreatedBy = userIserial;
                    row.Iserial   = oldRow.Iserial;
                    changedList   = GenericUpdate(oldRow, row, db);
                }
                else
                {
                    row.CreatedBy    = userIserial;
                    row.CreationDate = DateTime.Now;
                    db.TblEmployeeShifts.AddObject(row);
                }

                if (row.Status == 1)
                {
                    //    var srv = new EmployeePayrollServiceClient();

                    //    var listOfEmployeeShifts = new List<ServiceReference1.TblEmployeeShift>
                    //{
                    //    new ServiceReference1.TblEmployeeShift().InjectFrom(row) as ServiceReference1.TblEmployeeShift
                    //};

                    //    try
                    //    {
                    //        if (listOfEmployeeShifts.Count != 0)
                    //        {
                    //            srv.InsertEmpCalendarDeviation(listOfEmployeeShifts);
                    //        }
                    //    }
                    //    catch (Exception)
                    //    {

                    //    }
                }
                db.SaveChanges();
            }
            return(row);
        }
Exemplo n.º 2
0
        private int DeleteTblEmployeeShift(TblEmployeeShift row)
        {
            if (!Att.AttService.EmpCanEdit(row.TransDate, row.EmpId))
            {
                throw new Exception("Cannot edit a transaction because this period is already closed");
            }

            using (var context = new TimeAttEntities())
            {
                var oldRow = (from e in context.TblEmployeeShifts.Include("TblEmployeeShiftLookup1")
                              where
                              e.EmpId == row.EmpId &&
                              e.TransDate == row.TransDate

                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    //if (oldRow.Status == 1)
                    //{
                    //    var srv = new EmployeePayrollServiceClient();
                    //    srv.DeleteEmpCalendarDeviation(row.EmpId, row.TransDate, oldRow.TblEmployeeShiftLookup1.CalendarId);
                    //}

                    context.DeleteObject(oldRow);
                }

                context.SaveChanges();
            }
            return(row.Iserial);
        }