public Model.Person GetPersonById(Guid id) { using (var context = SCMSEntities.Define()) { return(context.People.Where(p => p.Id == id).FirstOrDefault()); } }
/// <summary> /// Gets a permission /// </summary> /// <param name="systemName">Permission system name</param> /// <returns>Permission</returns> public virtual PermissionRecord GetPermissionRecordBySystemName(string systemName, bool userCache = false) { if (String.IsNullOrWhiteSpace(systemName)) { return(null); } using (var context = SCMSEntities.Define()) { if (userCache) { return(m_CacheService.Get(m_PermissionCacheKeyPattern.F(systemName), CacheTimeSpan.Infinite, () => (from pr in context.PermissionRecords orderby pr.Id where pr.SystemName == systemName select pr).FirstOrDefault())); } var query = from pr in context.PermissionRecords orderby pr.Id where pr.SystemName == systemName select pr; var permission = query.FirstOrDefault(); return(permission); } }
public List<Project> GetProjects(Guid countryProgId) { using (var context = SCMSEntities.Define()) { return context.Projects.Where(p => p.CountryProgrammeId == countryProgId).ToList(); } }
public List <FinanceLimit> GetFinanceLimits(Guid countryProgId) { using (var context = SCMSEntities.Define()) { return(context.FinanceLimits.Where(f => f.CountryProgrammeId == countryProgId).OrderBy(f => f.Limit).ToList()); } }
public void AssignRoles(SystemUser user, params Guid[] roleIds) { roleIds = roleIds ?? Enumerable.Empty <Guid>().ToArray(); var userRoles = GetUserRoles(user.Id, false); using (var context = SCMSEntities.Define()) { var toDelete = userRoles.Where(p => !roleIds.Contains(p.RoleId)).ToArray(); var roleIdsToAdd = roleIds.Select(p => p).Delete <Guid>(userRoles.Select(p => p.RoleId)); toDelete.ForEach(DeleteUserRole); roleIdsToAdd.ForEach(p => context.SystemUserRoles .Add(new SystemUserRole { Id = Guid.NewGuid(), Created = DateTime.Now, Modified = DateTime.Now, RoleId = p, SystemUserId = user.Id, })); context.SaveChanges(); } }
public ActionResult SystemUserList(GridCommand command) { if (!m_PermissionService.Authorize(StandardPermissionProvider.SystemUsersManage)) { return(AccessDeniedView()); } using (var context = SCMSEntities.Define()) { var gridModel = GetSystemUsersQuery(context).ToGridModel(command.Page, command.PageSize, command.SortDescriptors, command.FilterDescriptors, command.GroupDescriptors); var data = gridModel.Data.Cast <GridSystemUserModel>().ToArray(); data.ForEach(p => { p.FinancialLimitName = p.FinancialLimitName ?? Resources.SystemUser_ViewProfile_NotSet; p.OfficialEmail = p.OfficialEmail ?? Resources.SystemUser_ViewProfile_NotSet; p.FirstName = p.FirstName ?? Resources.SystemUser_ViewProfile_NotSet; p.OtherNames = p.OtherNames ?? Resources.SystemUser_ViewProfile_NotSet; }); gridModel.Data = data; return(new JsonResult { Data = gridModel, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public void InsertPerson(Model.Person person) { using (var context = SCMSEntities.Define()) { context.People.Add(person); context.SaveChanges(); } }
public void InsertStaff(Model.Staff staff) { using (var context = SCMSEntities.Define()) { context.Staffs.Add(staff); context.SaveChanges(); } }
public List <StaffView> GetStaffByFinanceLimit(Guid FLId, Guid countryProgId) { try { using (var context = SCMSEntities.Define()) { var finlimit = context.FinanceLimits.FirstOrDefault(p => p.Id == FLId); if (finlimit.Limit > 0) { var staffList = (from sysUser in context.SystemUsers where sysUser.Staff.FinanceLimit.Limit >= finlimit.Limit && sysUser.Staff.CountrySubOffice.CountryProgrammeId == countryProgId orderby sysUser.Staff.FinanceLimit.Limit, sysUser.Staff.Person.FirstName, sysUser.Staff.Person.OtherNames select new StaffView { Id = sysUser.Id, StaffId = (Guid)sysUser.StaffId, StaffName = sysUser.Staff.Person.FirstName + " " + sysUser.Staff.Person.OtherNames, StaffDesignation = sysUser.Staff.Designation.Name }).ToList <StaffView>(); var unlimitedStaff = (from sysUser in context.SystemUsers where sysUser.Staff.FinanceLimit.Limit == 0 && sysUser.Staff.CountrySubOffice.CountryProgrammeId == countryProgId orderby sysUser.Staff.FinanceLimit.Limit select new StaffView { Id = sysUser.Id, StaffId = (Guid)sysUser.StaffId, StaffName = sysUser.Staff.Person.FirstName + " " + sysUser.Staff.Person.OtherNames, StaffDesignation = sysUser.Staff.Designation.Name }).ToList <StaffView>(); foreach (var staff in unlimitedStaff) { staffList.Add(staff); } return(staffList); } else { return((from sysUser in context.SystemUsers where sysUser.Staff.FinanceLimit.Limit == finlimit.Limit && sysUser.Staff.CountrySubOffice.CountryProgrammeId == countryProgId orderby sysUser.Staff.FinanceLimit.Limit, sysUser.Staff.Person.FirstName, sysUser.Staff.Person.OtherNames select new StaffView { Id = sysUser.Id, StaffId = (Guid)sysUser.StaffId, StaffName = sysUser.Staff.Person.FirstName + " " + sysUser.Staff.Person.OtherNames, StaffDesignation = sysUser.Staff.Designation.Name }).ToList <StaffView>()); } } } catch (Exception ex) { return(new List <StaffView>()); } }
/// <summary> /// Gets all permissions /// </summary> /// <returns>Permissions</returns> public virtual IList <PermissionRecord> GetAllPermissionRecords() { using (var context = SCMSEntities.Define()) { return((from cr in context.PermissionRecords.Include("RolePermissionRecords") orderby cr.Name select cr).ToArray().ToList()); } }
public IList <Role> GetAllRoles(bool activeOnly) { using (var context = SCMSEntities.Define()) { return(m_CacheService.Get(AllRolesCacheKey.F(activeOnly), CacheTimeSpan.Infinite, () => context.Roles.Where(r => (!activeOnly) || r.Active) .OrderBy(r => r.Name).ToList())); } }
public void InsertRole(Role role) { using (var context = SCMSEntities.Define()) { context.Roles.Add(role); context.SaveChanges(); m_CacheService.RemoveByPattern(RoleCacheKeyPattern); } }
public void UpdatePerson(Model.Person person) { using (var context = SCMSEntities.Define()) { context.People.Attach(person); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(person, System.Data.EntityState.Modified); context.SaveChanges(); } }
public void DeleteDocPreparerById(Guid id) { using (var context = SCMSEntities.Define()) { var dp = context.DocumentPreparers.FirstOrDefault(d => d.Id == id); context.DocumentPreparers.Remove(dp); context.SaveChanges(); } }
public void UpdateStaff(Model.Staff staff) { using (var context = SCMSEntities.Define()) { context.Staffs.Attach(staff); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(staff, System.Data.EntityState.Modified); context.SaveChanges(); } }
public SystemUser GetUserById(Guid id, bool userCache) { using (var context = SCMSEntities.Define()) { return(userCache ? m_CacheService.Get(UserByIdCacheKey.F(id), CacheTimeSpan.FiveMinutes, () => context.SystemUsers.Where(p => p.Id == id).IncludeRoles().IncludePerson().FirstOrDefault()) : context.SystemUsers.Where(p => p.Id == id).IncludeRoles().IncludePerson().FirstOrDefault()); } }
public IEnumerable <SystemUserRole> GetUserRoles(Guid userId, bool userCache) { using (var context = SCMSEntities.Define()) { return(userCache ? m_CacheService.Get(UserRoleCacheKey.F(userId), CacheTimeSpan.FiveMinutes, () => context.SystemUserRoles.Where(p => p.SystemUserId == userId).IncludeRole().ToArray()) : context.SystemUserRoles.Where(p => p.SystemUserId == userId).IncludeRole().ToArray()); } }
public void InsertUser(SystemUser user) { using (var context = SCMSEntities.Define()) { context.SystemUsers.Add(user); context.SaveChanges(); } }
public SystemUser GetUserByEmail(String email, bool userCache) { using (var context = SCMSEntities.Define()) { return(userCache ? m_CacheService.Get(UserByEmailCacheKey.F(email), CacheTimeSpan.FiveMinutes, () => context.SystemUsers.Where(p => p.Staff.Person.OfficialEmail == email).IncludeRoles().IncludePerson().IncludeCountry().IncludeCurrency().IncludeDesignation().FirstOrDefault()) : context.SystemUsers.Where(p => p.Staff.Person.OfficialEmail == email).IncludeRoles().IncludePerson().IncludeCountry().IncludeCurrency().IncludeDesignation().FirstOrDefault()); } }
public void InsertRolePermissionRecord(RolePermissionRecord rolePermissionRecord) { using (var context = SCMSEntities.Define()) { context.RolePermissionRecords.Add(rolePermissionRecord); context.SaveChanges(); } ClearCache(); }
/// <summary> /// Returns StaffView list with Staff.Id as Id /// </summary> /// <param name="documentCode"></param> /// <param name="countryProgId"></param> /// <returns></returns> public List <Staff> GetStaffByApprovalDoc(string documentCode, Guid countryProgId) { using (var context = SCMSEntities.Define()) { var staffList = context.Staffs.Include("Person").Where(s => (s.SystemUsers.FirstOrDefault(u => u.StaffId == s.Id && u.IsAvailable == true).Approvers.Where(a => a.ActivityCode == documentCode).Count() > 0 || s.SystemUsers.FirstOrDefault(u => u.StaffId == s.Id && u.IsAvailable == true).Approvers1.Where(a => a.ActivityCode == documentCode).Count() > 0) && s.CountrySubOffice.CountryProgrammeId == countryProgId).ToList(); return(staffList); } }
public Model.Staff GetStaffById(Guid id) { using (var context = SCMSEntities.Define()) { var staff = context.Staffs.Where(p => p.Id == id).FirstOrDefault(); var person = staff.Person; var desg = staff.Designation; return(staff); } }
public void UpdateRole(Role role) { using (var context = SCMSEntities.Define()) { context.Roles.Attach(role); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(role, System.Data.EntityState.Modified); context.SaveChanges(); m_CacheService.RemoveByPattern(RoleCacheKeyPattern); } }
public void InsertUserRole(SystemUserRole userRole) { var userId = userRole.SystemUserId; using (var context = SCMSEntities.Define()) { context.SystemUserRoles.Add(userRole); context.SaveChanges(); ClearUserCache(userId, null); } }
public void DeleteRolePermissionRecord(RolePermissionRecord rolePermission) { using (var context = SCMSEntities.Define()) { context.RolePermissionRecords.Attach(rolePermission); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(rolePermission, System.Data.EntityState.Modified); context.RolePermissionRecords.Remove(rolePermission); context.SaveChanges(); } ClearCache(); }
public void UpdateUser(SystemUser user) { var userId = user.Id; using (var context = SCMSEntities.Define()) { context.SystemUsers.Attach(user); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(user, System.Data.EntityState.Modified); context.SaveChanges(); ClearUserCache(userId, null); } }
public SystemUser GetPasswordResetUser(string Email, Guid PasswordResetCode) { using (var context = SCMSEntities.Define()) { var user = context.SystemUsers.FirstOrDefault(s => s.Staff.Person.OfficialEmail == Email && s.PasswordResetCode == PasswordResetCode); if (user != null) { var person = user.Staff.Person; } return(user); } }
private IEnumerable <PermissionRecord> GetRolePermissions(Guid roleId) { using (var context = SCMSEntities.Define()) { return(m_CacheService.Get(m_RolePermissionsCacheKey.F(roleId), CacheTimeSpan.Infinite, () => context. RolePermissionRecords.Where( p => p.RoleId == roleId). Select(p => p.PermissionRecord).ToArray())); } }
public bool EffectPosting(PaymentRequest rfp, Staff poster) { using (var context = SCMSEntities.Define()) { using (TransactionScope scope = new TransactionScope()) { try { var rfpCommits = context.BudgetCommitments.Where(b => b.PaymentRequestBudgetLine.PaymentRequestId == rfp.Id).ToList(); foreach (var rfpCommit in rfpCommits) { var pb = rfpCommit.ProjectBudget; pb.TotalCommitted -= rfpCommit.AmountCommitted; var posting = new BudgetPosting(); posting.AmountPosted = rfpCommit.AmountCommitted; posting.DatePosted = DateTime.Now; posting.Id = Guid.NewGuid(); posting.PostedBy = poster.Id; posting.RFPBudgetLineId = rfpCommit.RFPBudgetLineId; pb.TotalPosted += posting.AmountPosted; //Delete commitment and add posting context.BudgetCommitments.Remove(rfpCommit); context.BudgetPostings.Add(posting); } var paymentRequest = context.PaymentRequests.FirstOrDefault(a => a.Id == rfp.Id); paymentRequest.FundsPosted = true; paymentRequest.PostedBy = poster.Id; paymentRequest.PostedOn = DateTime.Now; //SAVE ALL CHANGES if (context.SaveChanges() > 0) { scope.Complete(); return(true); } else { scope.Dispose(); return(false); } } catch (Exception ex) { scope.Dispose(); throw ex; } } } }
/// <summary> /// Gets a setting by identifier /// </summary> /// <param name="settingId">Setting identifer</param> /// <returns>Setting</returns> public virtual Setting GetSettingById(Guid settingId) { if (settingId == Guid.Empty) { return(null); } using (var context = SCMSEntities.Define()) { var setting = context.Settings.Where(p => p.Id == settingId).FirstOrDefault(); return(setting); } }