public string GetAeCompaniesJson([FromBody] AccountExecutiveData accountExecutive) { SetTimeout(); var dataAccess = new CompaniesRepository(); dynamic response = CompaniesRepository.GetCompanies(); var aeCompanies = new List <CompanyData>(); foreach (JObject companyRecord in response.companies) { var company = companyRecord.ToObject <CompanyData>(); if (company == null) { continue; } var companyAe = company.AccountExecutive; if (string.Equals(companyAe, accountExecutive.AccountExecutive, StringComparison.CurrentCultureIgnoreCase)) { aeCompanies.Add(company); } } var output = JsonConvert.SerializeObject( aeCompanies, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); return(output); }
private bool?CompanyCanAddUsers() { int companyUserCount = 0; int companyUserLimit = 0; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { try { companyUserCount = usersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId && x.IsActive).Count() + pendingUsersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count(); companyUserLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; } catch { return(null); } } return(companyUserCount < companyUserLimit); }
public async System.Threading.Tasks.Task <OperationResult <Company> > DeleteCompany(int id) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() => { OperationResult <Company> result = new OperationResult <Company>(); try { if (IsInCompany(id)) { Company company = CompaniesRepository.Read(id); if (company != null) { if (company.OwnerId == CurrentUser.Id) { result.Result = CompaniesRepository.Delete(id); if (result.Result) { UserStore.RemoveFromRoleAsync(CurrentUser, RoleNames.CompanyOwner); } } } } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public JobListingsController(DBApplicationContext context) { _dbContext = context; _jobListingsRepository = new JobListingsRepository(context); _companiesRepository = new CompaniesRepository(context); _categoriesRepository = new CategoriesRepository(context); _templatesRepository = new TemplatesRepository(context); }
public AccountManagerController(DBApplicationContext context, IConfiguration configuration) { _dbContext = context; _usersRepository = new UsersRepository(context); _applicationsRepository = new ApplicationsRepository(context); _companiesRepository = new CompaniesRepository(context); _companyUsersRepository = new CompanyUsersRepository(context); _appsettingsConfiguration = configuration; }
public void CleanData() { using (var context = new TechnicalTestDbContext()) { var repository = new CompaniesRepository(context); var allItems = repository.Get().ToList(); allItems.ForEach(repository.Delete); context.SaveChanges(); } }
public string GetCompaniesJson() { SetTimeout(); var dataAccess = new CompaniesRepository(); dynamic companies = CompaniesRepository.GetCompanies(); string output = JsonConvert.SerializeObject(companies.companies); return(output); }
public UnitOfWork(BillsContext context) { _context = context; Companies = new CompaniesRepository(_context); Customers = new CustomersRepository(_context); OrderDetails = new OrderDetailsRepository(_context); Orders = new OrdersRepository(_context); Products = new ProductsRepository(_context); Users = new UsersRepository(_context); }
public bool DeleteCompanyById(int ID) { try { bool isSuccess; using (var repo = new CompaniesRepository()) { isSuccess = repo.DeletedById(ID); } return(isSuccess); } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("BusinessLogic:CompaniesBusiness::DeleteCompanyById::Error occured.", ex); } }
public bool InsertCompany(Companies entity) { try { bool isSuccess; using (var repo = new CompaniesRepository()) { isSuccess = repo.Insert(entity); } return(isSuccess); } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("BusinessLogic:CompaniesBusiness::InsertCompany::Error occured.", ex); } }
public async System.Threading.Tasks.Task <OperationResult <Company> > UpdateCompany(Company company) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() => { OperationResult <Company> result = new OperationResult <Company>(); try { if (IsInCompany(company.Id)) { result.Result = CompaniesRepository.Update(company); } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public void GivenIHaveTheFollowingCompaniesWithDefaultInformation(Table table) { var items = table.CreateSet <CompanyDetailsSpecflowItem>(); using (var context = new TechnicalTestDbContext()) { var repository = new CompaniesRepository(context); var allItems = repository.Get().ToList(); allItems.ForEach(repository.Delete); items.ForEach(x => { repository.Insert(new Company { Name = x.CompanyName }); }); context.SaveChanges(); } }
public async System.Threading.Tasks.Task <OperationResult <OrderResponse> > GetCompanyForOrder(int id) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <OrderResponse> >(() => { OperationResult <OrderResponse> result = new OperationResult <OrderResponse>(); try { var company = CompaniesRepository.Read(id); if (company != null) { company.OwnerId = Guid.Empty; company.Description = ""; company.LogoImage = ""; var playgrounds = PlaygroundsRepository.Search("CompanyId = @CompanyId", new { PageNumber = 1, PageSize = 100, CompanyId = company.Id }); var gameTypes = GameTypesRepository.Search("CompanyId = @CompanyId", new { PageNumber = 1, PageSize = 100, CompanyId = company.Id }); var equipment = EquipmentsRepository.Search("CompanyId = @CompanyId", new { PageNumber = 1, PageSize = 100, CompanyId = company.Id }); foreach (var equip in equipment) { equip.State = ""; } result.SingleResult = new OrderResponse { Company = company, Playgrounds = playgrounds, GameTypes = gameTypes, Equipment = equipment }; result.Result = true; } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <Company> > ReadCompany(int id) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() => { OperationResult <Company> result = new OperationResult <Company>(); try { Company company = CompaniesRepository.Read(id); if (company != null) { result.SingleResult = company; result.Result = true; } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public async System.Threading.Tasks.Task <OperationResult <Company> > GetCompanies(int pageSize, int pageNumber, bool descending) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() => { OperationResult <Company> result = new OperationResult <Company>(); try { result.Count = CompaniesRepository.Count(); if (result.Count > 0) { result.MultipleResult = CompaniesRepository.GetAll(pageSize, pageNumber, descending); } result.Result = true; } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public List <Companies> SelectAllCompanies() { var responseEntities = new List <Companies>(); try { using (var repo = new CompaniesRepository()) { foreach (var entity in repo.SelectAll()) { responseEntities.Add(entity); } } return(responseEntities); } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("BusinessLogic:CompaniesBusiness::SelectAllCompanies::Error occured.", ex); } }
public ActionResult Index(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_ORDER) { if (!Authorized(RoleType.UsersManager)) { return(Error(Loc.Dic.error_no_permission)); } AllUsersModel model = new AllUsersModel(); IEnumerable <User> activeUsersQuery; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { activeUsersQuery = usersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId && x.IsActive).ToList(); activeUsersQuery = Pagination(activeUsersQuery, page, sortby, order).ToList(); model.NonActiveUsers = usersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId && !x.IsActive).ToList(); Company company = companiesRep.GetEntity(CurrentUser.CompanyId); if (model.NonActiveUsers == null) { return(Error(Loc.Dic.error_users_get_error)); } if (activeUsersQuery == null) { return(Error(Loc.Dic.error_users_get_error)); } if (company == null) { return(Error(Loc.Dic.error_database_error)); } model.ActiveUsers = activeUsersQuery.ToList(); model.ActiveUsersCount = activeUsersQuery.Count(); model.CanceledUsersCount = model.NonActiveUsers.Count(); model.UsersLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; return(View(model)); } }
public static void Initialize(TestContext testContext) { IDbContext context = new DbContext(); IRepository <Certificate, int> certificatesRepository = new CertificateRepository(context); IRepository <Company, int> companiesRepository = new CompaniesRepository(context); IRepository <Equipment, int> equipmentsRepository = new EquipmentRepository(context); IRepository <Event, int> eventsRepository = new EventsRepository(context); IRepository <Game, int> gamesRepository = new GamesRepository(context); IRepository <GameType, int> gameTypesRepository = new GameTypesRepository(context); IRepository <News, int> newsRepository = new NewsRepository(context); IRepository <Operation, int> operationsRepository = new OperationsRepository(context); IRepository <Playground, int> playgroundsRepository = new PlaygroundsRepository(context); IRepository <Task, int> tasksRepository = new TasksRepository(context); IRepository <EquipmentOrder, int> equipmentOrdersRepository = new EquipmentOrdersRepository(context); UserStore <IdentityUser> userStore = new UserStore <IdentityUser>(context); RoleStore <IdentityRole> roleStore = new RoleStore <IdentityRole>(context); _loggingService = new TestLoggingService(); _manager = new PaintballManager(context, certificatesRepository, companiesRepository, equipmentsRepository, eventsRepository, gamesRepository, gameTypesRepository, newsRepository, operationsRepository, playgroundsRepository, equipmentOrdersRepository, tasksRepository, userStore, roleStore, _loggingService ); _firstUser = _manager.UserStore.Users.FirstOrDefault(); }
public Companies SelectCompanyById(int customerId) { try { Companies responseEntitiy; using (var repo = new CompaniesRepository()) { responseEntitiy = repo.SelectedById(customerId); responseEntitiy.Vehicles = new VehiclesRepository().SelectAll().Where(x => x.CompanyID.Equals(responseEntitiy.CompanyID)).ToList(); if (responseEntitiy == null) { throw new NullReferenceException("Customer doesnt exists!"); } } return(responseEntitiy); } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("BusinessLogic:CompaniesBusiness::SelectCompanyById::Error occured.", ex); } }
public async System.Threading.Tasks.Task <OperationResult <Company> > CreateCompany(Company company) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Company> >(() => { OperationResult <Company> result = new OperationResult <Company>(); try { company.OwnerId = CurrentUser.Id; Company created = CompaniesRepository.CreateOrUpdate(company); if (created.Id > 0) { UserStore.AddToRoleAsync(CurrentUser, RoleNames.CompanyOwner); result.SingleResult = created; result.Result = true; } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new WebScrappingContext( serviceProvider.GetRequiredService < DbContextOptions <WebScrappingContext> >())) { // Look for any movies. if (context.Company.Any()) { //context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Company]"); return; // DB has been seeded } string urlForSearchAllCompanies = @"https://staff.am/en/companies?CompaniesFilter%5BkeyWord%5D=&CompaniesFilter%5Bindustries%5D=&CompaniesFilter%5Bindustries%5D%5B%5D=2&CompaniesFilter%5Bemployees_number%5D=&CompaniesFilter%5Bsort_by%5D=&CompaniesFilter%5Bhas_job%5D="; context.Company.AddRange( CompaniesRepository.SearchURLForAllCompaniesAsync(urlForSearchAllCompanies).GetAwaiter().GetResult() ); context.SaveChanges(); } }
public ContractorAppController(AccountantsRepository accountant, CarRepository car, ChequesRepository cheaque, CompaniesRepository companies, ContactsLoanRepository contactLoans, ExpensesRepository expenses, ExpensesTypes expensesTypes, FinancialcustodyRepository finacialCustody, InventoryprojectreleaseRepository inventoryprojectrelease, InventoryRepository inventory, InvoicesitemsRepository invoiceItem, InvoicesRepository invoice, LoansItemsRepository loanItems, LoansRepository loans, ProjectItemsRepository projectItems, UsersRepository userRepository ) { _userRepository = userRepository; _accountant = accountant; _car = car; _cheaque = cheaque; _companies = companies; _contactLoans = contactLoans; _expenses = expenses; _expensesTypes = expensesTypes; _finacialCustody = finacialCustody; _inventoryprojectrelease = inventoryprojectrelease; _inventory = inventory; _invoiceItem = invoiceItem; _invoice = invoice; _loanItems = loanItems; _loans = loans; _projectItems = projectItems; }
public ActionResult OrdersToExport(List<int> selectedOrder = null) { if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); if (selectedOrder == null || selectedOrder.Count == 0) return Error(Loc.Dic.error_no_selected_orders); StringBuilder builder = new StringBuilder(); List<Order> ordersToExport = new List<Order>(); Company userCompany; using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId)) using (CompaniesRepository companiesRep = new CompaniesRepository()) { ordersToExport = ordersRep.GetList("Orders_Statuses", "Supplier", "User") .Where(x => selectedOrder.Contains(x.Id)) .ToList(); userCompany = companiesRep.GetEntity(CurrentUser.CompanyId); if (ordersToExport == null) return Error(Loc.Dic.error_database_error); if (userCompany == null) return Error(Loc.Dic.error_database_error); if (String.IsNullOrEmpty(userCompany.ExternalCoinCode) || String.IsNullOrEmpty(userCompany.ExternalExpenseCode)) return Error(Loc.Dic.error_insufficient_company_info_for_export); int numberOfOrders = 0; builder.AppendLine(numberOfOrders.ToString().PadRight(180)); foreach (var order in ordersToExport) { decimal orderPrice; if (order.Price.HasValue) { if (order.Price.Value > 999999999) return Error(String.Format("({0}: {1}) {2}", Loc.Dic.Order, order.OrderNumber, Loc.Dic.error_order_price_too_high)); orderPrice = order.Price.Value; } else { orderPrice = 0; } if (String.IsNullOrEmpty(order.Supplier.ExternalId)) return Error(String.Format("({0}: {1}) {2}", Loc.Dic.Supplier, order.Supplier.Name, Loc.Dic.error_insufficient_supplier_info_for_export)); if (String.IsNullOrEmpty(order.InvoiceNumber) || order.InvoiceDate == null) return Error(String.Format("({0}: {1}) {2}", Loc.Dic.Order, order.OrderNumber, Loc.Dic.error_insufficient_order_info_for_export)); List<Orders_OrderToAllocation> orderAllocations = order.Orders_OrderToAllocation.ToList(); List<Budgets_Allocations> distinctOrderAllocations = orderAllocations.Select(x => x.Budgets_Allocations).Distinct().ToList(); if (!orderAllocations.Any()) return Error(String.Format("({0}: {1}) {2}", Loc.Dic.Order, order.OrderNumber, Loc.Dic.error_order_has_no_allocations)); foreach (var allocation in distinctOrderAllocations) { if (String.IsNullOrEmpty(allocation.ExternalId)) return Error(String.Format("({0}: {1}) {2}", Loc.Dic.BudgetAllocation, allocation.DisplayName, Loc.Dic.error_insufficient_allocation_info_for_export)); decimal allocationSum = orderAllocations.Where(x => x.AllocationId == allocation.Id).Sum(a => a.Amount); builder.AppendLine( String.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}", String.Empty.PadLeft(3), order.InvoiceNumber.Substring(Math.Max(0, order.InvoiceNumber.Length - 5)).PadLeft(5), order.InvoiceDate.Value.ToString("ddMMyy"), String.Empty.PadLeft(5), order.ValueDate.Value.ToString("ddMMyy"), userCompany.ExternalCoinCode.PadLeft(3), String.Empty.PadLeft(22), allocation.ExternalId.ToString().PadLeft(8), String.Empty.PadLeft(8), String.Empty.PadLeft(8), //order.Supplier.ExternalId.ToString().PadLeft(8), String.Empty.PadLeft(8), allocationSum.ToString("0.00").PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12) ) ); } builder.AppendLine( String.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}", String.Empty.PadLeft(3), order.InvoiceNumber.PadLeft(5), order.InvoiceDate.Value.ToString("ddMMyy"), String.Empty.PadLeft(5), order.ValueDate.Value.ToString("ddMMyy"), userCompany.ExternalCoinCode.PadLeft(3), String.Empty.PadLeft(22), String.Empty.PadLeft(8), String.Empty.PadLeft(8), order.Supplier.ExternalId.ToString().PadLeft(8), String.Empty.PadLeft(8), String.Empty.PadLeft(12), String.Empty.PadLeft(12), orderPrice.ToString("0.00").PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12), String.Empty.PadLeft(12) ) ); order.StatusId = (int)StatusType.InvoiceExportedToFile; if (ordersRep.Update(order) == null) return Error(Loc.Dic.error_database_error); int? historyActionId = null; historyActionId = (int)HistoryActions.ExportedToFile; Orders_History orderHistory = new Orders_History(); using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, order.Id)) if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value); } //FileStream fileStream = new FileStream(//SystemFile.("", FileMode.Open()); byte[] fileBytes = Encoding.UTF8.GetBytes(builder.ToString()); string fileName = "MOVEIN.DAT"; //Stream stream = new MemoryStream(fileBytes); SendNotifications.OrdersExported(CurrentUser, Url, ordersToExport.Count, fileBytes); Response.AppendHeader("Refresh", "1"); Response.AppendHeader("Location", Url.Action("OrdersToExport", "Orders", null, "http")); return File(fileBytes, "text/plain", fileName); } }
public CompaniesController(CompaniesRepository repository) { _repository = repository; }
public UnitOfWork(TestBackendDevContext dbContext) { _dbContext = dbContext ?? throw new ArgumentException(nameof(TestBackendDevContext)); CompaniesRepository = new CompaniesRepository(dbContext); EmployeesRepository = new EmployeesRepository(dbContext); }
public ActionResult Create(User user, string[] roleNames) { if (!ModelState.IsValid) { List<string> allRoleNames = GetRoleNames(); List<SelectListItemDB> ApprovalRoutesList = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.NoApprovalRoute } }; SelectList languagesList; using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRep = new LanguagesRepository()) { ApprovalRoutesList.AddRange( routesRep.GetList() .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name }) ); languagesList = new SelectList(languagesRep.GetList().ToList(), "Id", "Name"); } ViewBag.RolesList = allRoleNames; ViewBag.RoutesList = new SelectList(ApprovalRoutesList, "Id", "Name"); ViewBag.LanguagesList = languagesList; return View(user); } if (user.DefaultApprovalRouteId == -1) user.DefaultApprovalRouteId = null; if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); int companyUserCount = 0; int companyUserLimit = 0; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { if (user.DefaultApprovalRouteId.HasValue) { var route = routesRep.GetEntity(user.DefaultApprovalRouteId.Value); if (route == null) return Error(Loc.Dic.error_invalid_form); } try { companyUserCount = usersRep.GetList().Where(x => x.IsActive).Count() + pendingUsersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count(); companyUserLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; } catch { return Error(Loc.Dic.error_database_error); } bool userExists = usersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); bool pendingUserExists = pendingUsersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); if (userExists || pendingUserExists) return Error(Loc.Dic.error_users_exist_error); } if (companyUserCount >= companyUserLimit) return Error(Loc.Dic.error_users_limit_reached); user.CompanyId = CurrentUser.CompanyId; user.CreationTime = DateTime.Now; RoleType combinedRoles = RoleType.None; List<RoleType> forbiddenRoles = GetForbiddenRoles(); if (roleNames == null || roleNames.Count() == 0) return Error(Loc.Dic.error_invalid_form); foreach (string roleName in roleNames) { RoleType role; if (!Enum.TryParse(roleName, out role) || forbiddenRoles.Contains(role)) return Error(Loc.Dic.error_invalid_form); combinedRoles = Roles.CombineRoles(combinedRoles, role); } user.Roles = (int)combinedRoles; user.DefaultApprovalRouteId = user.DefaultApprovalRouteId.HasValue && user.DefaultApprovalRouteId.Value == -1 ? null : user.DefaultApprovalRouteId; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) { if (!usersRep.Create(user)) return Error(Loc.Dic.error_users_create_error); } return RedirectToAction("Index"); }
public CompaniesController(DBApplicationContext context) { _dbContext = context; _companiesRepository = new CompaniesRepository(context); }
public ActionResult Index(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_ORDER) { if (!Authorized(RoleType.UsersManager)) return Error(Loc.Dic.error_no_permission); AllUsersModel model = new AllUsersModel(); IEnumerable<User> activeUsersQuery; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { activeUsersQuery = usersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId && x.IsActive).ToList(); activeUsersQuery = Pagination(activeUsersQuery, page, sortby, order).ToList(); model.NonActiveUsers = usersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId && !x.IsActive).ToList(); Company company = companiesRep.GetEntity(CurrentUser.CompanyId); if (model.NonActiveUsers == null) return Error(Loc.Dic.error_users_get_error); if (activeUsersQuery == null) return Error(Loc.Dic.error_users_get_error); if (company == null) return Error(Loc.Dic.error_database_error); model.ActiveUsers = activeUsersQuery.ToList(); model.ActiveUsersCount = activeUsersQuery.Count(); model.CanceledUsersCount = model.NonActiveUsers.Count(); model.UsersLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; return View(model); } }
public CompaniesService(CompaniesRepository repo) { _repo = repo; }
private bool? CompanyCanAddUsers() { int companyUserCount = 0; int companyUserLimit = 0; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { try { companyUserCount = usersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId && x.IsActive).Count() + pendingUsersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count(); companyUserLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; } catch { return null; } } return companyUserCount < companyUserLimit; }
public ActionResult Create(User user, string[] roleNames) { if (!ModelState.IsValid) { List <string> allRoleNames = GetRoleNames(); List <SelectListItemDB> ApprovalRoutesList = new List <SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.NoApprovalRoute } }; SelectList languagesList; using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRep = new LanguagesRepository()) { ApprovalRoutesList.AddRange( routesRep.GetList() .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name }) ); languagesList = new SelectList(languagesRep.GetList().ToList(), "Id", "Name"); } ViewBag.RolesList = allRoleNames; ViewBag.RoutesList = new SelectList(ApprovalRoutesList, "Id", "Name"); ViewBag.LanguagesList = languagesList; return(View(user)); } if (user.DefaultApprovalRouteId == -1) { user.DefaultApprovalRouteId = null; } if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } int companyUserCount = 0; int companyUserLimit = 0; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { if (user.DefaultApprovalRouteId.HasValue) { var route = routesRep.GetEntity(user.DefaultApprovalRouteId.Value); if (route == null) { return(Error(Loc.Dic.error_invalid_form)); } } try { companyUserCount = usersRep.GetList().Where(x => x.IsActive).Count() + pendingUsersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count(); companyUserLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; } catch { return(Error(Loc.Dic.error_database_error)); } bool userExists = usersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); bool pendingUserExists = pendingUsersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); if (userExists || pendingUserExists) { return(Error(Loc.Dic.error_users_exist_error)); } } if (companyUserCount >= companyUserLimit) { return(Error(Loc.Dic.error_users_limit_reached)); } user.CompanyId = CurrentUser.CompanyId; user.CreationTime = DateTime.Now; RoleType combinedRoles = RoleType.None; List <RoleType> forbiddenRoles = GetForbiddenRoles(); if (roleNames == null || roleNames.Count() == 0) { return(Error(Loc.Dic.error_invalid_form)); } foreach (string roleName in roleNames) { RoleType role; if (!Enum.TryParse(roleName, out role) || forbiddenRoles.Contains(role)) { return(Error(Loc.Dic.error_invalid_form)); } combinedRoles = Roles.CombineRoles(combinedRoles, role); } user.Roles = (int)combinedRoles; user.DefaultApprovalRouteId = user.DefaultApprovalRouteId.HasValue && user.DefaultApprovalRouteId.Value == -1 ? null : user.DefaultApprovalRouteId; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) { if (!usersRep.Create(user)) { return(Error(Loc.Dic.error_users_create_error)); } } return(RedirectToAction("Index")); }
public CompaniesController() { repository = new CompaniesRepository(); }
public virtual async Task <IQueryable <CompanyDto> > GetAll(CancellationToken cancellationToken) { return(DtoEntityMapper.FromEntityQueryToDtoQuery(await CompaniesRepository.GetAllAsync(cancellationToken))); }