Example #1
0
        public List <Route> GetRouteListOfCompany(string _routeNameTLA, User _userObj)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var company               = CompanyUserDB.GetInstance().GetCompanyByCompanyUserId(_userObj);
                    var companyRoutes         = context.CompanyRoute.Where(x => x.CompanyId == company.Id).ToList();
                    var companyRoutesRouteIds = companyRoutes.Select(x => x.RouteId).ToList();
                    var routes = context.Route.Where(x => companyRoutesRouteIds.Contains(x.Id) && x.Status == 1).ToList();
                    if (!String.IsNullOrEmpty(_routeNameTLA))
                    {
                        routes = routes.Where(x => x.Name.Trim().ToLower().StartsWith(_routeNameTLA.Trim().ToLower()) && x.Status > 0).ToList();
                    }

                    if (routes != null)
                    {
                        return(routes);
                    }
                    return(null);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        public List <UserReportInfo> GetUserReportByUser(User _userObj)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var userCompany    = CompanyUserDB.GetInstance().GetCompanyUserById(_userObj.Id);
                    var userReports    = context.UserReport.Where(x => x.UserId == _userObj.Id).ToList();
                    var userReportsIds = userReports.Select(x => x.ReportId).ToList();
                    var reports        = context.Report.ToList();

                    var userReportList = new List <UserReportInfo>();
                    foreach (var item in userReports)
                    {
                        var report = reports.FirstOrDefault(x => x.Id == item.ReportId);
                        userReportList.Add(new UserReportInfo()
                        {
                            UserReportId = item.Id,
                            ReportId     = report.Id,
                            Name         = report.Name,
                            ReportStatus = item.AutomaticReportingStatus == 1 ? "Aktif":"Pasif",
                            ReportType   = item.UserReportType == 2 ? "PDF":"EXCEL"
                        });
                    }
                    return(userReportList);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Example #3
0
 public List <Area> GetAreaListOfCompany(string _areaNameTLA, int _areaTypeTLA, User _userObj)
 {
     try
     {
         using (var context = new VeraEntities())
         {
             var company             = CompanyUserDB.GetInstance().GetCompanyByCompanyUserId(_userObj);
             var companyAreas        = context.CompanyArea.Where(x => x.CompanyId == company.Id).ToList();
             var companyAreasAreaIds = companyAreas.Select(x => x.AreaId).ToList();
             var areas = context.Area.Where(x => companyAreasAreaIds.Contains(x.Id) && x.Status == 1).ToList();
             if (!String.IsNullOrEmpty(_areaNameTLA))
             {
                 areas = areas.Where(x => x.Name.Trim().ToLower().Contains(_areaNameTLA.Trim().ToLower())).ToList();
             }
             if (_areaTypeTLA != 0)
             {
                 var areaIsRestricted = _areaTypeTLA == 1 ? true : false;
                 areas = areas.Where(x => x.IsRestricted == areaIsRestricted).ToList();
             }
             if (areas != null)
             {
                 return(areas);
             }
             return(null);
         }
     }
     catch (Exception exc)
     {
         throw exc;
     }
 }
 public List <Report> GetAllUserReportByUserIdToLeft(User _userObj)
 {
     try
     {
         using (var context = new VeraEntities())
         {
             var allReports  = ReportDB.GetInstance().GetAllReportes();
             var userCompany = CompanyUserDB.GetInstance().GetCompanyUserById(_userObj.Id);
             if (userCompany.IsCompanyAdmin)
             {
                 return(allReports);
             }
             else
             {
                 var myCompanyId = context.CompanyUser.FirstOrDefault(x => x.UserId == _userObj.Id).CompanyId;
                 var myDevices   = allReports.Where(x => x.Id == myCompanyId).ToList();
                 return(myDevices);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 public static CompanyUserDB GetInstance()
 {
     if (instance == null)
     {
         instance = new CompanyUserDB();
     }
     return(instance);
 }
 public List <Company> GetAllCompaniesByUserId(User _userObj)
 {
     try
     {
         using (var context = new VeraEntities())
         {
             var companyList = GetAllDBCompanies();
             var company     = CompanyUserDB.GetInstance().GetCompanyByCompanyUserId(_userObj);
             companyList = companyList.Where(x => x.MainCompanyId == company.Id || x.Id == company.Id).ToList();
             if (companyList != null)
             {
                 return(companyList);
             }
             return(null);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
        public List <RouteWithVehicle> GetroutesWithVehicles(User _userObj)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var company = CompanyUserDB.GetInstance().GetCompanyByCompanyUserId(_userObj);
                    var subCompaniesAndOwnCompanyIds = context.Company.Where(x => x.MainCompanyId == company.Id).Select(x => x.Id).ToList();
                    subCompaniesAndOwnCompanyIds.Add(company.Id);

                    var returnList = new List <RouteWithVehicle>();

                    var companyRoutesRouteIds = context.CompanyRoute.Where(x => subCompaniesAndOwnCompanyIds.Contains(x.CompanyId)).Select(x => x.RouteId).ToList();
                    var companyRoutesStatus1  = context.Route.Where(x => companyRoutesRouteIds.Contains(x.Id) && x.Status == 1).Select(x => x.Id).ToList();
                    var RouteDevices          = context.RouteDevice.Where(x => companyRoutesStatus1.Contains(x.RouteId)).ToList();

                    foreach (var item in RouteDevices)
                    {
                        var routeName            = context.Route.FirstOrDefault(x => x.Id == item.RouteId).Name;
                        var deviceCarPlateNumber = context.Device.FirstOrDefault(x => x.Id == item.DeviceId).CarPlateNumber;
                        returnList.Add(new RouteWithVehicle()
                        {
                            CarPlateNumber = deviceCarPlateNumber,
                            RouteName      = routeName
                        });
                    }
                    if (returnList != null)
                    {
                        return(returnList);
                    }
                    return(null);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Example #8
0
        public List <AreaWithVehicle> GetAreasWithVehicles(User _userObj)
        {
            try
            {
                using (var context = new VeraEntities())
                {
                    var company = CompanyUserDB.GetInstance().GetCompanyByCompanyUserId(_userObj);
                    var subCompaniesAndOwnCompanyIds = context.Company.Where(x => x.MainCompanyId == company.Id).Select(x => x.Id).ToList();
                    subCompaniesAndOwnCompanyIds.Add(company.Id);

                    var returnList = new List <AreaWithVehicle>();

                    var companyAreasAreaIds = context.CompanyArea.Where(x => subCompaniesAndOwnCompanyIds.Contains(x.CompanyId)).Select(x => x.AreaId).ToList();
                    var areaDevices         = context.AreaDevice.Where(x => companyAreasAreaIds.Contains(x.AreaId)).ToList();

                    foreach (var item in areaDevices)
                    {
                        var areaName             = context.Area.FirstOrDefault(x => x.Id == item.AreaId).Name;
                        var deviceCarPlateNumber = context.Device.FirstOrDefault(x => x.Id == item.DeviceId).CarPlateNumber;
                        returnList.Add(new AreaWithVehicle()
                        {
                            CarPlateNumber = deviceCarPlateNumber,
                            AreaName       = areaName
                        });
                    }
                    if (returnList != null)
                    {
                        return(returnList);
                    }
                    return(null);
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }