public void CreateNewBranch(CoreBranchView model) { try { db.CoreBranches.Add(ConvertViewToModel(model)); db.SaveChanges(); } catch (Exception e) { AuditLog.ErrorLog.LogError(db, e, 0); } }
public bool Update(CoreBranchView model, int CoreSystemUserId) { try { var data = (from a in db.CoreBranches where model.BranchId == a.BranchId select a).FirstOrDefault(); ChangeLog.ChangeLogService.tableName = "CoreBranch"; ChangeLog.ChangeLogService.tableKey = data.BranchId; ChangeLog.ChangeLogService.LoggedInUserId = CoreSystemUserId; if (model.CoreTeamLeaderId == null) { data.CoreTeamLeaderId = data.CoreTeamLeaderId; } else { ChangeLog.ChangeLogService.LogChange(data.CoreTeamLeaderId.ToString(), model.CoreTeamLeaderId.ToString(), "CoreTeamLeaderId"); data.CoreTeamLeaderId = model.CoreTeamLeaderId; } #region Edit Log ChangeLog.ChangeLogService.LogChange(data.BranchName, model.BranchName, "BranchName"); ChangeLog.ChangeLogService.LogChange(data.City, model.City, "City"); ChangeLog.ChangeLogService.LogChange(data.EmailAddress, model.EmailAddress, "EmailAddress"); ChangeLog.ChangeLogService.LogChange(data.IsActive.ToString(), model.IsActive.ToString(), "IsActive"); ChangeLog.ChangeLogService.LogChange(data.Phone, model.Phone, "Phone"); ChangeLog.ChangeLogService.LogChange(data.ProvinceId.ToString(), model.ProvinceId.ToString(), "ProvinceId"); ChangeLog.ChangeLogService.LogChange(data.StreetAddress, model.StreetAddress, "StreetAddress"); #endregion data.BranchName = model.BranchName; data.City = model.City; data.EmailAddress = model.EmailAddress; data.IsActive = model.IsActive; data.Phone = model.Phone; data.ProvinceId = model.ProvinceId; data.StreetAddress = model.StreetAddress; data.Suburb = model.Suburb; db.SaveChanges(); return(true); } catch (Exception e) { AuditLog.ErrorLog.LogError(db, e, 0); return(false); } }
private static DataAccess.CoreBranch ConvertViewToModel(CoreBranchView m) { DataAccess.CoreBranch a = new DataAccess.CoreBranch() { BranchId = m.BranchId, BranchName = m.BranchName, City = m.City, CoreTeamLeaderId = m.CoreTeamLeaderId, EmailAddress = m.EmailAddress, IsActive = m.IsActive, Phone = m.Phone, ProvinceId = m.ProvinceId, StreetAddress = m.StreetAddress, Suburb = m.Suburb }; return(a); }
public static UserBranchDetails GetBranchDetailsForUser(int CoreUserId, int coreUserType) { UserBranchDetails m = new UserBranchDetails(); //AGENT if (coreUserType == 4) { int GetAgentBranchId = 0; try { GetAgentBranchId = (int)db.CoreAgents.FirstOrDefault(x => x.CoreUserId == CoreUserId).CoreBranchId; } catch { GetAgentBranchId = 0; } //The agent has a branch assigned to them if (GetAgentBranchId > 0) { CoreBranchView model = CoreBranchService.DetailsNew(db, GetAgentBranchId).CoreBranchView; m.BranchName = model.BranchName; m.BranchId = model.BranchId; m.Province = model.ProvinceName; m.TeamLeader = model.TeamLeaderName; m.HasResult = true; } //if they do not, dont break the front end else { m.HasResult = false; } } //TeamLeader else if (coreUserType == 3) { int GetTeamLeaderBranch = 0; int GetBranchId = 0; try { GetTeamLeaderBranch = db.CoreTeamLeaders.FirstOrDefault(x => x.CoreUserId == CoreUserId).CoreTeamLeaderId; } catch { GetTeamLeaderBranch = 0; } if (GetTeamLeaderBranch != 0) { GetBranchId = db.CoreBranches.FirstOrDefault(x => x.CoreTeamLeaderId == GetTeamLeaderBranch).BranchId; CoreBranchView model = CoreBranchService.DetailsNew(db, GetBranchId).CoreBranchView; m.BranchName = model.BranchName; m.BranchId = model.BranchId; m.Province = model.ProvinceName; m.TeamLeader = model.TeamLeaderName; m.HasResult = true; } else { m.BranchName = "No Branch Assigned To Teamleader"; m.HasResult = false; } } return(m); }