public IEnumerable<Att_OvertimeModel> Post(Att_ComputeOvertimeModel model)
        {
            Att_WorkDayServices serviceWorkDay = new Att_WorkDayServices();
            var status = string.Empty;
            var lstWorkDay = serviceWorkDay.GetWorkDaysByInOut(model.DateFrom, model.DateTo);
            Cat_ShiftServices serviceShift = new Cat_ShiftServices();
            var lstShift = serviceShift.GetDataNotParam<Cat_ShiftEntity>(ConstantSql.hrm_cat_sp_get_Shift, UserLogin, ref status);

            //Cat_ShiftItemServices serviceShiftItem = new Cat_ShiftItemServices();
            //var lstShiftItem = serviceShiftItem.GetCatShiftItem();
            var lstShiftItem = new List<Cat_ShiftItemEntity>();
            Cat_DayOffServices servicesDayOff = new Cat_DayOffServices();
            var lstDayOff = servicesDayOff.GetAllUseEntity<Cat_DayOffEntity>(ref status).ToList();

            Cat_OvertimeTypeServices servicesOvertimeType = new Cat_OvertimeTypeServices();
            var lstOvertimeType = servicesOvertimeType.GetDataNotParam<Cat_OvertimeTypeEntity>(ConstantSql.hrm_cat_sp_get_OvertimeType, UserLogin, ref status);

            var Att_OvertimeInfoFillterAnalyze = new Att_OvertimeInfoFillterAnalyze()
            {
                isAllowGetAfterShift = model.isAllowGetAfterShift,
                isAllowGetBeforeShift = model.isAllowGetBeforeShift,
                isAllowGetInShift = model.isAllowGetInShift,
                isAllowGetOTOutterShift = model.isAllowGetOTOutterShift,
                isAllowGetTypeBaseOnActualDate = model.isAllowGetTypeBaseOnActualDate,
                isAllowGetTypeBaseOnBeginShift = model.isAllowGetTypeBaseOnBeginShift,
                isAllowGetTypeBaseOnEndShift = model.isAllowGetTypeBaseOnEndShift,
                MininumOvertimeHour = model.MininumOvertimeHour
            };

            var service = new Att_OvertimeServices();
            var result = service.AnalyzeOvertime(lstWorkDay, 
                                                lstShift, 
                                                lstShiftItem, 
                                                lstDayOff, 
                                                lstOvertimeType,
                                                Att_OvertimeInfoFillterAnalyze, UserLogin).ToList().Translate<Att_OvertimeModel>();
            return result;
        }
Exemple #2
0
        public CatDayOffModel Post([Bind]CatDayOffModel model)
        {
            ActionService service = new ActionService(UserLogin);

            #region Validate
            var type = "Cat_DayOff";
            if (model.ID != Guid.Empty)
            {
                type = "Cat_DayOff_Edit";
            }
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<CatDayOffModel>(model, type, ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            #endregion

            if (model.ID != Guid.Empty)
            {
                return service.UpdateOrCreate<Cat_DayOffEntity, CatDayOffModel>(model);
            }
            List<Cat_DayOffEntity> listDayOffInsert = new List<Cat_DayOffEntity>();
            List<Cat_DayOffEntity> listDayOff = getDayOff(model);
            List<Cat_DayOffEntity> listDayOffDelete = new List<Cat_DayOffEntity>();

            string status = string.Empty;
            Cat_DayOffServices dayOffService = new Cat_DayOffServices();
            var listDayOffExist = dayOffService.GetAll();

            foreach (Cat_DayOffEntity item in listDayOff)
            {
                item.IsLeaveDay = model.IsLeaveDay;
                item.Comments = model.Comments;
                item.OrgStructureID = model.OrgStructureID;
                item.UserCreate = model.UserCreate;
                item.DateUpdate = model.DateUpdate;

                DateTime _dateOff = item.DateOff.Date;
                listDayOffExist = listDayOffExist.Where(dOff => dOff.DateOff.Date == _dateOff).ToList();

                if (listDayOffExist.Count > 0)
                {
                    if (model.Overwite)
                    {
                        listDayOffDelete.AddRange(listDayOffExist);
                        item.ID = Guid.NewGuid();
                        listDayOffInsert.Add(item);
                    }
                    else
                        continue;
                }
                else
                {
                    item.ID = Guid.NewGuid();
                    listDayOffInsert.Add(item);
                }
            }
            if (listDayOffDelete.Count > 0)
            {
                List<Guid> lstDel = listDayOffDelete.Select(s => s.ID).ToList();
                foreach (var item in lstDel)
                {
                    dayOffService.Remove<Cat_DayOffEntity>(item);
                }
            }
            CatDayOffModel rs = new CatDayOffModel();
            rs.ActionStatus = dayOffService.Add<Cat_DayOffEntity>(listDayOffInsert);
            return rs;




            //if (model.ID == Guid.Empty && model.DateEnd.HasValue)
            //{
            //    CatDayOffModel modelReturn = model.CopyData<CatDayOffModel>();
            //    DateTime dtFrom = model.DateOff;
            //    while (dtFrom <= model.DateEnd.Value)
            //    {
            //        CatDayOffModel NewModel = new CatDayOffModel();
            //        NewModel.DateOff = dtFrom;
            //        NewModel.Type = model.Type;
            //        NewModel.Status = model.Status;
            //        NewModel.Comments = model.Comments;
            //        NewModel.OrgStructureID = model.OrgStructureID;
            //        NewModel.IsLeaveDay = model.IsLeaveDay;
            //        NewModel.OrgStructureName = model.OrgStructureName;
            //        NewModel.UserUpdate = model.UserUpdate;
            //        NewModel.DateUpdate = model.DateUpdate;
            //        modelReturn = service.UpdateOrCreate<Cat_DayOffEntity, CatDayOffModel>(NewModel);
            //        if (modelReturn.ActionStatus != NotificationType.Success.ToString())
            //            return modelReturn;
            //        dtFrom = dtFrom.AddDays(1);
            //    }
            //    return modelReturn;
            //}
            //else
            //{
            //    return service.UpdateOrCreate<Cat_DayOffEntity, CatDayOffModel>(model);
            //}
        }