public CatShiftItemModel Post([Bind] CatShiftItemModel model) { #region Validate string message = string.Empty; string status = string.Empty; var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <CatShiftItemModel>(model, "Cat_ShiftItem", ref message); if (!checkValidate) { model.ActionStatus = message; return(model); } #endregion ActionService service = new ActionService(UserLogin); var entity = service.GetByIdUseStore <Cat_ShiftEntity>(model.ShiftID, ConstantSql.hrm_cat_sp_get_ShiftById, ref status); if (model.OvertimeTypeID != null) { if (model.From.Value.Day > entity.InTime.Day) { DateTime temp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, entity.InTime.Hour, entity.InTime.Minute, entity.InTime.Second); model.From.Value.AddDays(1); model.CoFrom = model.From.Value.Subtract(temp).TotalHours; } if (model.To.Value.Day > entity.InTime.Day) { DateTime temp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, entity.InTime.Hour, entity.InTime.Minute, entity.InTime.Second); model.To.Value.AddDays(1); model.CoTo = model.To.Value.Subtract(temp).TotalHours; } } // double d = model.From.Value.Hour + model.From.Value.Minute / 100; if (model.From != null || model.To != null) { DateTime temp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, entity.InTime.Hour, entity.InTime.Minute, entity.InTime.Second); model.CoFrom = model.From.Value.Subtract(temp).TotalHours; model.CoTo = model.To.Value.Subtract(temp).TotalHours; } return(service.UpdateOrCreate <Cat_ShiftItemEntity, CatShiftItemModel>(model)); }
/// <summary> /// [Son.Vo] - Lấy dữ liệu ShiftItem(Cat_ShiftItem) theo Id /// </summary> /// <param name="id"></param> /// <returns></returns> public CatShiftItemModel GetById(Guid id) { string status = string.Empty; var model = new CatShiftItemModel(); ActionService service = new ActionService(UserLogin); var entity = service.GetByIdUseStore <Cat_ShiftItemEntity>(id, ConstantSql.hrm_cat_sp_get_ShiftItemById, ref status); if (entity != null && entity.ID != Guid.Empty) { model = entity.CopyData <CatShiftItemModel>(); DateTime temp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, model.Intime.Value.Hour, model.Intime.Value.Minute, model.Intime.Value.Second); // model.From = SqlDateTime.MinValue.Value; model.From = temp.AddHours(model.CoFrom); // model.To = SqlDateTime.MinValue.Value; model.To = temp.AddHours(model.CoTo); } model.ActionStatus = status; return(model); }