public DataSaveResult Save() { this.IsCopy = false; Acc_Accounts dbAccount; try { NewAppsCnn newAppsCnn = new NewAppsCnn(AppSettings.CrAppSettings.NewAppsConnectionString); var dbAccounts = from u in newAppsCnn.Acc_Accounts where u.AccountID == this.AccountID select u; if (dbAccounts.Count() > 0) { dbAccount = dbAccounts.First(); if (this.AccountTypeId != dbAccount.AccountTypeId && (dbAccount.ParentId==null||dbAccount.ParentId=="")) { var dbAccountChilds = from u in newAppsCnn.Acc_Accounts where u.ParentId == this.AccountID select u; foreach (var itm in dbAccountChilds) { itm.AccountTypeId = this.AccountTypeId; } } this.ToDbAccount(dbAccount); dbAccount.AccountLevel = getNodeLevel(0, dbAccount.ParentId); } else { dbAccount = new Acc_Accounts(); this.ToDbAccount(dbAccount); dbAccount.AccountLevel = getNodeLevel(0, dbAccount.ParentId); newAppsCnn.Acc_Accounts.Add(dbAccount); } newAppsCnn.SaveChanges(); Audit.AddDataAudit(Audit.AuditActionTypes.AddNew, "Acc_Accounts", this); this.FromDbAccount(dbAccount); return new DataSaveResult() { SaveStatus = true }; } catch (Exception ex) { return new DataSaveResult() { SaveStatus = false,ErrorMessage=ex.Message }; } }
public void ToDbAccount(Acc_Accounts _dbAccount) { _dbAccount.AccountID = this.AccountID; _dbAccount.AccountName_Ar = this.AccountName_Ar; _dbAccount.AccountName_Eng = this.AccountName_Eng; _dbAccount.AccountRef1 = this.AccountRef1; _dbAccount.AccountRef2 = this.AccountRef2; _dbAccount.AccountTypeId = this.AccountTypeId; _dbAccount.AccountLevel = this.AccountLevel; _dbAccount.AccountCategoryId = this.AccountCategoryId; _dbAccount.IsSubAccount = this.IsSubAccount; _dbAccount.IsDisableAccount = this.IsDisableAccount; if (this.IsNew == true) { _dbAccount.ParentId = this.ParentId; } this.IsCopy = false; }
public void FromDbAccount(Acc_Accounts _dbAccount) { this.AccountID = _dbAccount.AccountID; this.AccountName_Ar = _dbAccount.AccountName_Ar; this.AccountName_Eng = _dbAccount.AccountName_Eng; this.AccountRef1 = _dbAccount.AccountRef1; this.AccountRef2 = _dbAccount.AccountRef2; this.AccountTypeId = _dbAccount.AccountTypeId; this.AccountLevel = _dbAccount.AccountLevel; this.AccountCategoryId = _dbAccount.AccountCategoryId; this.IsSubAccount = _dbAccount.IsSubAccount; this.IsDisableAccount = _dbAccount.IsDisableAccount; this.ParentId = _dbAccount.ParentId; this.IsNew = false; this.IsCopy = false; }