static void Main(string[] args) { //CriarProduto com tag //Criar Cliente //Criar Notas Fiscais //Transcations //Buscar Nota por Id //Bucar Nota Por numero //Ordenação //Skip take var tagDao = new BaseDao <Tag>(); tagDao.IniciarTransacao(); var tag = new Tag() { Nome = "Genérico" }; tagDao.CriarOuAlterar(tag); tagDao.SalvarAlteracoes(); tagDao.Commit(); var firstTag = tagDao.Query().FirstOrDefault(); Console.WriteLine("Nome cadastrado: " + firstTag.Nome); tag.Nome = "Genérico alterado"; tagDao.CriarOuAlterar(tag); tagDao.SalvarAlteracoes(); firstTag = tagDao.Query().FirstOrDefault(); Console.WriteLine("Nome alterado: " + firstTag.Nome); tagDao.Excluir(tag); firstTag = tagDao.Query().FirstOrDefault(); Console.WriteLine("Tag apagada: " + firstTag is null); Console.ReadKey(); }
public int DeleteData(List <IDto> listDto) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { context.BeginTransaction(); foreach (SYS_UserDetailDTO _UserDeleteDto in listDto) { #region Delete GroupAssign var _groupsassign = context.ms_groupsassign.AsQueryable(); _groupsassign = _groupsassign.Where(ga => ga.UserCode.Equals(_UserDeleteDto.UserName)); foreach (var ga in _groupsassign) { context.DeleteObject(ga); context.Saves(); } if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } #endregion Delete GroupAssign #region Delete User var _user = context.ms_users.FirstOrDefault(u => u.Code.Equals(_UserDeleteDto.UserName)); //_user = _user.Where(u => u.Code.Equals(_UserDeleteDto.UserName)); if (returnCode == CommonData.DbReturnCode.Succeed) { context.DeleteObject(_user); //context.Saves(); returnCode = context.Saves(CommonData.FunctionGr.SY_Users, CommonData.Action.Delete, new { _user.Code, _user.DisplayName }, typeof(ms_users).Name); } if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } } //Commit to database if (returnCode == CommonData.DbReturnCode.Succeed) { context.Commit(); } #endregion Delete User } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
public int InsertData(SYS_UserDetailDTO insertUserDto) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { context.BeginTransaction(); #region Insert data to User Table //table user ms_users _users = new ms_users(); _users.Code = insertUserDto.UserName; _users.DisplayName = insertUserDto.FullName; _users.Password = insertUserDto.Password; _users.Profile = insertUserDto.Profile; _users.Status = insertUserDto.Status; _users.SystemData = "0"; //Add user context.ms_users.AddObject(_users); //Save to database //returnCode = context.Saves(); returnCode = context.Saves(CommonData.FunctionGr.SY_Users, CommonData.Action.Insert, new { _users.Code, _users.DisplayName, _users.Password, _users.Profile, _users.Status, _users.SystemData }, typeof(ms_users).Name); if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } #endregion Insert data to User Table #region Insert data to GroupAssign Table ms_groupsassign _groupsassign = null; foreach (var item in insertUserDto.UserGroups) { _groupsassign = new ms_groupsassign(); _groupsassign.UserCode = insertUserDto.UserName; _groupsassign.GroupCode = item.Code; _groupsassign.SystemData = "0"; context.ms_groupsassign.AddObject(_groupsassign); returnCode = context.Saves(); } if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } //Commit to database if (returnCode == CommonData.DbReturnCode.Succeed) { context.Commit(); } #endregion Insert data to GroupAssign Table } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
public int UpdateData(SYS_UserDetailDTO _UserUpdateDto) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { context.BeginTransaction(); #region Update User ms_users _users = context.ms_users.FirstOrDefault(u => u.ID.Equals(_UserUpdateDto.ID)); if (_users != null) { _users.ID = _UserUpdateDto.ID; _users.Code = _UserUpdateDto.UserName; _users.DisplayName = _UserUpdateDto.FullName; _users.Status = _UserUpdateDto.Status; _users.Password = _UserUpdateDto.Password; //Save to database //returnCode = context.Saves(); returnCode = context.Saves(CommonData.FunctionGr.SY_Users, CommonData.Action.Update, new { _users.Code, _users.DisplayName, _users.Status }, typeof(ms_users).Name); //Check if error occur if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } } else { returnCode = CommonData.DbReturnCode.DataNotFound; } #endregion Update User #region Delete GroupAssign var _groupsassign = context.ms_groupsassign.AsQueryable(); _groupsassign = _groupsassign.Where(ga => ga.UserCode.Equals(_UserUpdateDto.UserName)); foreach (var ga in _groupsassign) { context.DeleteObject(ga); } #endregion Delete GroupAssign #region Insert data to GroupAssign Table ms_groupsassign groupsassign = null; foreach (var item in _UserUpdateDto.UserGroups) { groupsassign = new ms_groupsassign(); groupsassign.UserCode = _UserUpdateDto.UserName; groupsassign.GroupCode = item.Code; groupsassign.SystemData = "0"; context.ms_groupsassign.AddObject(groupsassign); returnCode = context.Saves(); } if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } //Commit to database if (returnCode == CommonData.DbReturnCode.Succeed) { context.Commit(); } #endregion Insert data to GroupAssign Table } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
public int InsertPermissionData(SYS_UserGroupsDto permissionDto) { int returnCode = CommonData.DbReturnCode.Succeed; using (BaseDao context = new BaseDao()) { try { context.BeginTransaction(); ms_usergroups userGroup = context.ms_usergroups.FirstOrDefault(ig => ig.Code.Equals(permissionDto.GroupCode)); if (userGroup != null) { #region Assign function #region Remove old permission //Remove function assign IQueryable <ms_permissionsassign> lstFunctionPermission = context.ms_permissionsassign.Where(p => p.GroupCode.Equals(userGroup.Code)); foreach (ms_permissionsassign permission in lstFunctionPermission) { //Delete from database context.ms_permissionsassign.DeleteObject(permission); } #endregion Remove old permission #region Insert new permission //insert function assign foreach (SYS_PermissionAssignDto mappingDto in permissionDto.Mappings) { ms_permissionsassign permissionsAssign = new ms_permissionsassign(); permissionsAssign.GroupCode = userGroup.Code; permissionsAssign.MappingID = mappingDto.MappingId; permissionsAssign.SystemData = CommonData.Status.Disable; //Create insert infomation this.CreateInsertHistory(permissionsAssign, CommonData.FunctionGr.SY_UserGroups); //Add to database context.ms_permissionsassign.AddObject(permissionsAssign); } #endregion Insert new permission #endregion Assign function #region Assign warehouse #region Remove old warehouse //Remove warehouse assign IQueryable <ms_warehouseassign> lstWHPermission = context.ms_warehouseassign.Where(p => p.GroupCode.Equals(userGroup.Code)); foreach (ms_warehouseassign whAssign in lstWHPermission) { //Delete from database context.ms_warehouseassign.DeleteObject(whAssign); } #endregion Remove old warehouse #region Insert new warehouse //insert warehouse assign foreach (MS_WarehouseAssignDto mappingDto in permissionDto.WHMappings) { if (!CommonMethod.IsNullOrEmpty(mappingDto.WarehouseCode)) { ms_warehouseassign whAssign = new ms_warehouseassign(); whAssign.GroupCode = userGroup.Code; whAssign.WarehouseCode = mappingDto.WarehouseCode; //whAssign.OperID = mappingDto.OperID; //whAssign.SystemData = CommonData.Status.Disable; //Create insert infomation this.CreateInsertHistory(whAssign, CommonData.FunctionGr.SY_UserGroups); //Add to database context.ms_warehouseassign.AddObject(whAssign); } } #endregion Insert new warehouse #endregion Assign warehouse returnCode = context.Saves(); if (returnCode == 0) { returnCode = context.Commit(); } else { context.Rollback(); } } else { context.Rollback(); returnCode = CommonData.DbReturnCode.DataNotFound; } } catch (Exception ex) { context.Rollback(); returnCode = this.ProcessDbException(ex); } } return(returnCode); }