private void AssignRecord(Boolean IsSave) { try { if (IsSave) { usrgrp.UserGroupCode = mtxtGroupCode.Text; usrgrp.UserGroupDesc = mtxtGroupDesc.Text; usrgrp.Remarks = mtxtRemarks.Text; usrgrp.IsActive = mcbActive.Checked; } else { usrgrp = usrgrpbal.GetByID(groupid); RefreshList(); if (usrgrp != null) { mtxtGroupCode.Text = usrgrp.UserGroupCode; mtxtGroupDesc.Text = usrgrp.UserGroupDesc; mtxtRemarks.Text = usrgrp.Remarks; mcbActive.Checked = usrgrp.IsActive; } else { throw new Exception("Record doesn't exist!"); } } } catch (Exception ex) { throw ex; } }
public frmUserGroup() { InitializeComponent(); usrgrpbal = new UserGroupBAL(); usrgrp = new tbl_000_USERGROUP(); err = new ErrorProviderExtended(); }
public tbl_000_USERGROUP GetByID(string usergroupcode) { try { tbl_000_USERGROUP record = new tbl_000_USERGROUP(); record = db.UserGroupList.Where(m => m.UserGroupCode == usergroupcode).FirstOrDefault(); record.MenuList = db.UserGroupMenuList.Where(n => n.UserGroupCode == usergroupcode).ToList(); return(record); } catch (Exception ex) { throw ex; } }
public Boolean Update(tbl_000_USERGROUP record) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { //get new instance of context Renew(); tbl_000_USERGROUP existrecord = GetByID(record.UserGroupCode); db.Entry(existrecord).CurrentValues.SetValues(record); List <tbl_000_USERGROUP_MENUS> usermenus = db.UserGroupMenuList.Where(m => m.UserGroupCode == record.UserGroupCode).ToList(); //insert new menus foreach (var newmenu in record.MenuList) { if (usermenus.SingleOrDefault(m => m.MenuID == newmenu.MenuID) == null) { InsertSub(newmenu, record.UserGroupCode); } } //edit or remove existing foreach (var existmenu in usermenus) { var newusermenu = record.MenuList.SingleOrDefault(m => m.MenuID == existmenu.MenuID); if (newusermenu != null) { //edit existing db.Entry(existmenu).CurrentValues.SetValues(newusermenu); } else { //remove existing db.UserGroupMenuList.Remove(existmenu); } } db.SaveChanges(); dbContextTransaction.Commit(); return(true); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } }
public Boolean Update(tbl_000_USERGROUP record) { try { if (record == null) { throw new Exception("Invalid Parameter"); } if (!compdal.IsExistID(record.UserGroupCode)) { throw new Exception("Record does not exist!"); } return(compdal.Update(record)); } catch (Exception ex) { throw ex; } }
public tbl_000_USERGROUP GetByUserGroupDesc(string usergroupdesc) { try { if (usergroupdesc == null) { throw new Exception("Invalid Parameter!"); } tbl_000_USERGROUP exist = new tbl_000_USERGROUP(); exist = compdal.GetByUserGroupDesc(usergroupdesc); if (exist == null) { throw new Exception("Record does not exist!"); } return(exist); } catch (Exception ex) { throw ex; } }
public Boolean Delete(tbl_000_USERGROUP record) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { Renew(); var existrecord = GetByID(record.UserGroupCode); var existmenus = db.UserGroupMenuList.Where(m => m.UserGroupCode == record.UserGroupCode).ToList(); db.UserGroupMenuList.RemoveRange(existmenus); db.UserGroupList.Remove(existrecord); db.SaveChanges(); dbContextTransaction.Commit(); return(true); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } }
public Boolean Save(tbl_000_USERGROUP record) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { Renew(); db.UserGroupList.Add(record); foreach (var usrgrpmnu in record.MenuList) { InsertSub(usrgrpmnu, record.UserGroupCode); } db.SaveChanges(); dbContextTransaction.Commit(); return(true); } catch (Exception ex) { dbContextTransaction.Rollback(); throw ex; } } }
public Boolean Save(tbl_000_USERGROUP record) { try { if (record == null) { throw new Exception("Invalid Parameter"); } if (compdal.IsExistUserGroupDesc(record.UserGroupDesc)) { throw new Exception("Description already taken!"); } if (compdal.IsExistID(record.UserGroupCode)) { throw new Exception("Code already taken!"); } return(compdal.Save(record)); } catch (Exception ex) { throw ex; } }