public bool SaveIndexTypeUser(SysUserViewModels model, string userCodeBy, string transactionType) { // Get package MstAccessPackageDAO accessPackageDAO = new MstAccessPackageDAO(this.mapper); IList<MstAccessPackageModels> packageList = accessPackageDAO.GetAccessPackageList(model.packageCode, null, -1, Constants.Status.Active); if (packageList == null || packageList.Count <= 0) { model.errorMessage = String.Format(Resource.MsgSuccess, new object[] { Resource.PackageCode, model.packageCode }); return true; } MstAccessPackageModels packageModel = packageList[0]; Dictionary<string, object> param = new Dictionary<string, object>(); // Get IndexTypeUser param.Add("indexTypeCode", model.indexTypeCode); param.Add("userCode", model.userCode); MstIndexTypeUserModels mstIndexTypeUser = mapper.QueryForObject<MstIndexTypeUserModels>("Master.selectIndexTypeUser", param); MstIndexTypeUserModels newModel = new MstIndexTypeUserModels(); newModel.userCode = model.userCode; newModel.indexTypeCode = model.indexTypeCode; newModel.viewFlg = Constants.Flag.HasRight; newModel.updatedDate = DateTime.Now; newModel.updatedBy = userCodeBy; DateTime? oldFromDate = null; DateTime? oldToDate = null; // If not exist -> Insert if (mstIndexTypeUser == null) { newModel.fromDate = DateUtils.getNowWithoutTime(); newModel.toDate = newModel.fromDate.AddDays(packageModel.duration); newModel.createdDate = DateTime.Now; newModel.createdBy = userCodeBy; mapper.Insert("Master.insertIndexTypeUser", newModel); } else // If exist -> Update { // If user has no right or to date < current date // Set To Date = New + duraction if (mstIndexTypeUser.viewFlg.Equals(Constants.Flag.NoRight) || mstIndexTypeUser.toDate < DateTime.Now) { newModel.toDate = DateUtils.getNowWithoutTime().AddDays(packageModel.duration); } else // Set To Date = To Date + duraction { newModel.toDate = mstIndexTypeUser.toDate.AddDays(packageModel.duration); } newModel.createdDate = mstIndexTypeUser.createdDate; newModel.createdBy = mstIndexTypeUser.createdBy; newModel.fromDate = mstIndexTypeUser.fromDate; mapper.Update("Master.updateIndexTypeUser", newModel); oldFromDate = mstIndexTypeUser.fromDate; oldToDate = mstIndexTypeUser.toDate; } // Insert into Transaction TraTransactionDAO transactionDAO = new TraTransactionDAO(this.mapper); transactionDAO.insertUserTypeUserTransaction( transactionType // string transactionType , model.indexTypeCode // string indexTypeCode , model.userCode // string userCode , model.packageCode // string packageCode , DateTime.Now // DateTime transactionDate , oldFromDate // DateTime oldFromDate , oldToDate // DateTime oldToDate , newModel.fromDate // DateTime newFromDate , newModel.toDate // DateTime newToDate , userCodeBy // string userCodeBy ); model.infoMessage = Resource.MsgSuccess; return true; }
public SysUserViewModels getUserView(string userCode, SysUserViewModels model) { SysUserViewModels temp = model; temp.userInfo = this.GetUserByUserCode(userCode); MstIndexTypeDAO mstIndexTypeDAO = new MstIndexTypeDAO(this.mapper); temp.indexTypeList = mstIndexTypeDAO.GetIndexTypeList(null, Constants.Status.Active); MstIndexTypeUserDAO mstIndexTypeUserDAO = new MstIndexTypeUserDAO(this.mapper); temp.indexTypeUserList = mstIndexTypeUserDAO.GetIndexTypeUserList(null, userCode, Constants.Flag.HasRight); MstAccessPackageDAO accessPackageDAO = new MstAccessPackageDAO(this.mapper); temp.packageList = accessPackageDAO.GetAccessPackageList(null, null, -1, Constants.Status.Active); temp.userCode = userCode; return temp; }