Beispiel #1
0
        public CompanyManagersViewModel(Company company, CompanyRights currentEntityRights)
        {
            Info = new CompanyInfoViewModel(company);
            NewManagersSelector = Select2AjaxViewModel.Create <CompanyController>(c => c.GetAppropriateManagers(null), "entityID", null, "");

            initManagers(company, currentEntityRights);
        }
Beispiel #2
0
        public ViewCompanyEmployeesViewModel(List <CompanyEmployeeViewModel> employees, bool showEmployeeStats, CompanyRights rights)
        {
            ShowEmployeeStats = showEmployeeStats;
            Rights            = rights;

            Employees = employees;
        }
 public ShortJobOfferViewModel(JobOffer jobOffer, CompanyRights companyRights)
 {
     Amount        = jobOffer.Amount;
     JobID         = jobOffer.ID;
     MinSkill      = (double)jobOffer.MinSkill;
     CompanyRights = companyRights;
 }
Beispiel #4
0
        public ManageEmployeeViewModel(CompanyEmployee employee, CompanyRights managerRights, bool isEmployeeManager)
        {
            CompanyInfo = new CompanyInfoViewModel(employee.Company);

            IsManager = isEmployeeManager;

            CitizenID   = employee.CitizenID;
            CitizenName = employee.Citizen.Entity.Name;
            Avatar      = new ImageViewModel(employee.Citizen.Entity.ImgUrl);
            MinimumHP   = employee.MinHP;
            Salary      = (double)employee.Salary;


            var countryID = employee.Company.Region.CountryID;

            var currency = Persistent.Countries
                           .First(c => c.ID == countryID)
                           .Currency;

            CurrencyImage = Images.GetCountryCurrency(currency).VM;

            ManagerRights = managerRights;

            var companyService = DependencyResolver.Current.GetService <ICompanyService>();

            Skill = employee.Citizen.GetWorkSkill(employee.Company);
        }
Beispiel #5
0
        public ManagerViewModel(CompanyManager manager)
        {
            var entity = manager.Entity;

            Avatar    = new SmallEntityAvatarViewModel(entity);
            Title     = "Manager";
            Rights    = new CompanyRights(manager);
            ManagerID = manager.ID;
        }
        public ManageContractEmployeeViewModel(CompanyEmployee employee, CompanyRights managerRights, bool isEmployeeManager) : base(employee, managerRights, isEmployeeManager)
        {
            var contract = employee.JobContract;

            RemainingLength     = contract.Length;
            MinimumSalary       = (double)contract.MinSalary;
            MinimumHPOnContract = contract.MinHP;
            SignedByName        = contract.Entity.Name;
            AbusedCompanyRules  = contract.AbusedByEmployee;
        }
        public void ModifyManager(CompanyManager manager, CompanyRights rights)
        {
            if (rights.HaveAnyRights == false)
            {
                companyManagerRepository.Remove(manager);
            }

            rights.FillEntity(ref manager);
            ConditionalSaveChanges(companyManagerRepository);
        }
Beispiel #8
0
        private void initManagers(Company company, CompanyRights currentEntityRights)
        {
            Managers.AddRange(
                company.CompanyManagers.ToList().Select(manager => new ManagerViewModel(manager))
                );

            Managers.Add(new ManagerViewModel(company.Owner));

            Managers = Managers.OrderByDescending(m => m.Rights.Priority).ToList();

            if (currentEntityRights.CanManageManagers)
            {
                Managers.Where(m => m.Rights.Priority < currentEntityRights.Priority)
                .ForEach(m => m.ReadOnly = false);
            }
        }
Beispiel #9
0
        public CompanyMarketOfferListViewModel(Entities.Company company, IQueryable <MarketOfferModel> marketOffers, PagingParam pagingParam,
                                               CompanyRights rights, IMarketService marketService)
        {
            Info          = new CompanyInfoViewModel(company);
            CompanyRights = rights;

            PagingParam = pagingParam;
            if (marketOffers.Count() > 0)
            {
                var filteredOffers = marketOffers.OrderByDescending(mo => mo.OfferID).Apply(PagingParam).ToList();

                foreach (var offer in filteredOffers)
                {
                    Offers.Add(new MarketOfferViewModel(SessionHelper.CurrentEntity, offer, marketService, deleteable: true, showDetails: true));
                }
            }
        }
Beispiel #10
0
        public void AddManager(Company company, Citizen citizen, CompanyRights rights)
        {
            CompanyManager manager = new CompanyManager()
            {
                EntityID  = citizen.ID,
                CompanyID = company.ID,
            };

            var companyLink = EntityLinkCreator.Create(company.Entity);

            var msg = $"From this day on you are new manager of {companyLink}";

            using (NoSaveChanges)
                warningService.AddWarning(citizen.ID, msg);

            rights.FillEntity(ref manager);
            companyManagerRepository.Add(manager);
            ConditionalSaveChanges(companyManagerRepository);
        }
Beispiel #11
0
        public MethodResult CanRemoveManager(CompanyManager manager, Entity byWho)
        {
            if (manager == null)
            {
                return(new MethodResult("Manager does not exist!"));
            }

            var managerRights = new CompanyRights(manager);
            var whoRights     = GetCompanyRights(manager.Company, byWho);

            if (whoRights.CanManageManagers == false)
            {
                return(new MethodResult("You cannot manage managers!"));
            }
            if (whoRights.Priority <= managerRights.Priority)
            {
                return(new MethodResult("You need to have higher priority to be able to remove manager!"));
            }

            return(MethodResult.Success);
        }
        public ViewCompanyViewModel(Company company, IProductRepository productRepository, ICompanyService companyService, CompanyRights companyRights, IRegionService regionService, IRegionRepository regionRepository)
        {
            IProductService productService = DependencyResolver.Current.GetService <IProductService>();

            Info              = new CompanyInfoViewModel(company);
            Quality           = company.Quality;
            Money             = MoneyViewModel.GetMoney(company.Entity.Wallet);
            ShowEmployeeStats = true;
            Queue             = (double)company.Queue;
            Rights            = companyRights;

            initializeEmployees(company, companyService);

            initializeRequiredProducts(company, productRepository, productService);

            initializeProducedStock(company, productRepository);

            if (Rights.HaveAnyRights)
            {
                Statistics = new CompanyStatisticsViewModel(company, companyService, regionService, regionRepository);
            }
        }
Beispiel #13
0
        public MethodResult CanModifyManager(Company company, Entity modifyingEntity, CompanyManager manager, CompanyRights newRights)
        {
            if (modifyingEntity == null)
            {
                return(new MethodResult("You do not exist!"));
            }
            if (manager == null)
            {
                return(new MethodResult("Manager does not exist!"));
            }
            if (company == null)
            {
                return(new MethodResult("Company does not exist!"));
            }

            var rights = GetCompanyRights(company, modifyingEntity);

            if (rights.CanManageManagers == false)
            {
                return(new MethodResult("You cannot manage managers!"));
            }

            foreach (CompanyRightsEnum right in Enum.GetValues(typeof(CompanyRightsEnum)).Cast <CompanyRightsEnum>())
            {
                if (rights[right] == false && newRights[right] == true)
                {
                    return(new MethodResult("You cannot give him more rights than you have!"));
                }
            }

            if (newRights.Priority > rights.Priority)
            {
                return(new MethodResult("New manager cannot have bigger priority than you!"));
            }

            return(MethodResult.Success);
        }
 public ShortContractJobOfferViewModel(ContractJobOffer contractOffer, CompanyRights companyRights)
     : base(contractOffer.JobOffer, companyRights)
 {
     MinSalary = (double)contractOffer.MinSalary;
 }
Beispiel #15
0
 public ManagerViewModel(Entity companyOwner)
 {
     Avatar = new SmallEntityAvatarViewModel(companyOwner);
     Title  = "CEO";
     Rights = new CompanyRights(fullRights: true);
 }
Beispiel #16
0
        public MethodResult CanAddManager(Company company, Entity addingEntity, Entity addedEntity, CompanyRights addedRights)
        {
            if (addingEntity == null)
            {
                return(new MethodResult("You do not exist!"));
            }
            if (addedEntity == null)
            {
                return(new MethodResult("Manager does not exist!"));
            }
            if (company == null)
            {
                return(new MethodResult("Company does not exist!"));
            }
            if (addedEntity.Is(EntityTypeEnum.Citizen) == false)
            {
                return(new MethodResult("Only citizens can be managers!"));
            }


            var addedCurrentRights = GetCompanyRights(company, addedEntity);

            if (addedCurrentRights.HaveAnyRights)
            {
                return(new MethodResult($"{addedEntity.Name} is actually a manager!"));
            }

            var rights = GetCompanyRights(company, addingEntity);


            if (rights.CanManageManagers == false)
            {
                return(new MethodResult("You cannot manage managers!"));
            }

            foreach (CompanyRightsEnum right in Enum.GetValues(typeof(CompanyRightsEnum)).Cast <CompanyRightsEnum>())
            {
                if (rights[right] == false && addedRights[right] == true)
                {
                    return(new MethodResult("You cannot give him more rights than you have!"));
                }
            }

            if (addedRights.Priority > rights.Priority)
            {
                return(new MethodResult("New manager cannot have bigger priority than you!"));
            }

            return(MethodResult.Success);
        }
        public ViewDevelopementCompanyViewModel(Company company, IProductRepository productRepository, ICompanyService companyService, CompanyRights companyRights,
                                                IRegionService regionService, IRegionRepository regionRepository) : base(company, productRepository, companyService, companyRights, regionService, regionRepository)
        {
            Infrastructure = string.Format("{0:0.000}", company.Region.Development);
            if (ProduceAmount > 0)
            {
                ProduceAmount = (double)Math.Round(companyService.CalculateCreatedDevelopementForCreatedItems((decimal)ProduceAmount), 4);
            }

            foreach (var emp in Employees.Employees)
            {
                if (emp.Production.HasValue)
                {
                    emp.Production = (double)Math.Round(companyService.CalculateCreatedDevelopementForCreatedItems((decimal)emp.Production.Value), 4);
                }
            }
        }
Beispiel #18
0
        public ViewHospitalCompanyViewModel(Company company, IProductRepository productRepository, ICompanyService companyService, IHospitalService hospitalService, CompanyRights companyRights,
                                            IRegionService regionService, IRegionRepository regionRepository, IHospitalRepository hospitalRepository) : base(company, productRepository, companyService, companyRights, regionService, regionRepository)
        {
            var hospital = company.Hospital;

            Heal = new HospitalHealViewModel(hospital, hospitalService, hospitalRepository);
        }
        public static ViewCompanyViewModel GetViewModel(Company company, IProductRepository productRepository, ICompanyService companyService, CompanyRights rights, IRegionRepository regionRepository, IRegionService regionService, IHospitalRepository hospitalRepository)
        {
            switch (company.GetCompanyType())
            {
            case CompanyTypeEnum.Construction:
                return(new ViewConstructionCompanyViewModel(company, productRepository, companyService, rights, regionService, regionRepository));

            case CompanyTypeEnum.Developmenter:
                return(new ViewDevelopementCompanyViewModel(company, productRepository, companyService, rights, regionService, regionRepository));
            }

            switch (company.GetProducedProductType())
            {
            case ProductTypeEnum.MedicalSupplies:
                var hospitalService = DependencyResolver.Current.GetService <IHospitalService>();
                return(new ViewHospitalCompanyViewModel(company, productRepository, companyService, hospitalService, rights, regionService, regionRepository, hospitalRepository));
            }

            return(new ViewCompanyViewModel(company, productRepository, companyService, rights, regionService, regionRepository));
        }
Beispiel #20
0
        private ShortJobOfferViewModel createShortJobOffer(JobOffer jobOffer, WorkTypeEnum workType, CompanyRights companyRights)
        {
            ShortJobOfferViewModel vm;

            switch ((JobTypeEnum)jobOffer.TypeID)
            {
            case JobTypeEnum.Normal:
                vm = new ShortNormalJobOfferViewModel(jobOffer.NormalJobOffer, companyRights);
                break;

            case JobTypeEnum.Contracted:
                vm = new ShortContractJobOfferViewModel(jobOffer.ContractJobOffer, companyRights);
                break;

            default:
                throw new ArgumentException();
            }

            vm.CanWork = true;
            if (SessionHelper.CurrentEntity.GetEntityType() == EntityTypeEnum.Citizen)
            {
                switch (workType)
                {
                case WorkTypeEnum.Construction:
                    vm.CanWork = SessionHelper.CurrentEntity.Citizen.Construction >= jobOffer.MinSkill;
                    if (!vm.CanWork)
                    {
                        vm.CannotWorkReason = "Your skill is not good enough";
                    }
                    break;

                case WorkTypeEnum.Manufacturing:
                    vm.CanWork = SessionHelper.CurrentEntity.Citizen.Manufacturing >= jobOffer.MinSkill;
                    if (!vm.CanWork)
                    {
                        vm.CannotWorkReason = "Your skill is not good enough";
                    }
                    break;

                case WorkTypeEnum.Raw:
                    vm.CanWork = SessionHelper.CurrentEntity.Citizen.Raw >= jobOffer.MinSkill;
                    if (!vm.CanWork)
                    {
                        vm.CannotWorkReason = "Your skill is not good enough";
                    }
                    break;
                }
            }
            else
            {
                vm.CanWork          = false;
                vm.CannotWorkReason = "Only citizens can work";
            }

            vm.Amount = jobOffer.Amount;
            vm.JobID  = jobOffer.ID;
            return(vm);
        }
Beispiel #21
0
 public ShortNormalJobOfferViewModel(NormalJobOffer normalJobOffer, CompanyRights companyRights)
     : base(normalJobOffer.JobOffer, companyRights)
 {
     Salary = (double)normalJobOffer.Salary;
 }
        public ViewConstructionCompanyViewModel(Company company, IProductRepository productRepository, ICompanyService companyService, CompanyRights companyRights, IRegionService regionService, IRegionRepository regionRepository) : base(company, productRepository, companyService, companyRights, regionService, regionRepository)
        {
            var constructionService = DependencyResolver.Current.GetService <IConstructionService>();
            var construction        = company.Construction;

            Progress    = construction.Progress;
            MaxProgress = constructionService.GetProgressNeededToBuild(construction.GetProductType(), company.Quality);

            Stock.ShowQuantity = construction.GetProductType().CanShowStockQuantityInCompanies();

            IsOneTimeConstruction = construction.GetProductType().IsOneTimeConstruction();
        }