Example #1
0
            /// <summary>
            /// Removes the given item from the collection
            /// </summary>
            /// <returns>True, if the item was removed, otherwise False</returns>
            /// <param name="item">The item that should be removed</param>
            public override bool Remove(IModelElement item)
            {
                ITimeTariffInterval timeTariffIntervalItem = item.As <ITimeTariffInterval>();

                if (((timeTariffIntervalItem != null) &&
                     this._parent.TimeTariffIntervals.Remove(timeTariffIntervalItem)))
                {
                    return(true);
                }
                ITariff tariffItem = item.As <ITariff>();

                if (((tariffItem != null) &&
                     this._parent.Tariffs.Remove(tariffItem)))
                {
                    return(true);
                }
                IConsumptionTariffInterval consumptionTariffIntervalItem = item.As <IConsumptionTariffInterval>();

                if (((consumptionTariffIntervalItem != null) &&
                     this._parent.ConsumptionTariffIntervals.Remove(consumptionTariffIntervalItem)))
                {
                    return(true);
                }
                return(false);
            }
Example #2
0
 public Abonent(ITariff tariff, string phoneNumber, ITerminal terminal)
 {
     Balance     = 0;
     Tariff      = tariff;
     PhoneNumber = phoneNumber;
     Terminal    = terminal;
 }
 public void AddClient(PhoneNumber phoneNumber, ITariff tariff)
 {
     _tariffsMap.Add(phoneNumber, tariff);
     _canChangeTariffMap.Add(phoneNumber, true);
     _callsMap.Add(phoneNumber, new List<CallInfo>());
     _debtMap.Add(phoneNumber, 0);
 }
Example #4
0
 public Client(int id, ITariff tariff, Phone phone, decimal balance, ClientStatus status)
 {
     Id      = id;
     Tariff  = tariff;
     Phone   = phone;
     Balance = balance;
     Status  = status;
 }
Example #5
0
        public IOrganization Update(int id, string name, int tariffId)
        {
            ITariff tariff = Utility.Tariffs.GetTariff(tariffId);

            IOrganization organization = Update(id, name, tariff);

            return(organization);
        }
Example #6
0
 public Contract(IClient client, ITerminal terminal, ITariff tariff, string phoneNumber)
 {
     Id     = Guid.NewGuid();
     Client = client;
     Client.SetTerminal(terminal);
     Terminal    = terminal;
     Tariff      = tariff;
     PhoneNumber = phoneNumber;
 }
Example #7
0
        public bool ChangeTariff(ITariff tariff, DateTime dateToChanges)
        {
            if (dateToChanges - _tariffHistory.Last().DateAddTariff > new TimeSpan(30, 0, 0, 0))
            {
                _tariffHistory.Add(new TariffChange(tariff, dateToChanges));
                return(true);
            }

            return(false);
        }
Example #8
0
 public Call(CallEventArgs e, ITariff tariff)
 {
     CallerPhoneNumber = e.CallerPhoneNumber;
     TargetPhoneNumber = e.TargetPhoneNumber;
     ResponseCode      = e.ResponseCode;
     ErrorCode         = e.ErrorCode;
     DateTimeBegin     = e.DateTimeBeginCall;
     Duration          = (e.DataTimeEndCall - e.DateTimeBeginCall).TotalSeconds;
     Cost = Duration * (tariff.CostPerMinute / 10);
 }
Example #9
0
        public virtual bool ChangeTariff(IBilling billing, ITariff newTariff)
        {
            bool res = newTariff != null && (_dtHelper.Now - TariffStartDate).Days >= _daysToChangeContract && billing.Balance(this) >= 0;

            if (res)
            {
                Tariff          = newTariff;
                TariffStartDate = _dtHelper.Now;
            }
            return(res);
        }
Example #10
0
 public Client(string name, PhoneNumber number, ITariff tariff, ushort money)
 {
     Name           = name;
     _tariffHistory = new List <TariffChange>()
     {
         new TariffChange(tariff, DateTime.Now)
     };
     Port = new Port(number);
     AddMoney(money);
     PayDay = DateTime.Now;
 }
Example #11
0
        public int?GetAvailableBoardsCount(IOrganization organization)
        {
            ITariff tariff = GetTariff(organization.TariffId);

            if (tariff.BoardsCount.HasValue)
            {
                List <IBoard> boards = Utility.Boards.GetByOrganization(organization.Id);
                return(tariff.BoardsCount.Value - boards.Count);
            }
            return(null);
        }
Example #12
0
        /// <summary>
        /// Сколько пользователей можно еще добавить
        /// </summary>
        public int?GetAvailableUsersCount(IOrganization organization)
        {
            ITariff tariff = GetTariff(organization.TariffId);

            if (tariff.EmployeesCount.HasValue)
            {
                List <EmployeeSettings> employees = Utility.Organizations.GetEmployees(organization.Id);
                return(tariff.EmployeesCount.Value - employees.Count);
            }
            return(null);
        }
 public Contract(ICompany company, IPassport individualPassport, string phoneNumber, ITariff tariff,
                 IEquipment clientEquipment)
 {
     Company        = company;
     ContractNumber = Guid.NewGuid();
     DateOfContract = DateTime.Now;
     Passport       = individualPassport;
     PhoneNumber    = phoneNumber;
     Tariff         = tariff;
     Equipment      = clientEquipment;
 }
        public ITerminal SignContract(ITariff tariff)
        {
            ITerminal t1 = _station.GetPreparedTerminal();

            if (t1 != null)
            {
                _billingSystem.AddClient(t1.PhoneNumber, tariff);
            }

            return t1;
        }
        public void CalculateSingleShouldFail()
        {
            // Arrange
            _mockValidator.Setup(x => x.Validate(HardcodedConsumption)).Throws(new ArgumentException());
            _tariff = new PackagedTariff(new TariffValidator());

            // Act
            var result = _tariff.Calculate(new double[] { 0 });

            // Assert - Expects Exception
        }
        public bool TryChangeTariff(PhoneNumber phoneNumber, ITariff newTariff)
        {
            if (_tariffsMap[phoneNumber] == newTariff)
                return false;

            if (_canChangeTariffMap[phoneNumber])
            {
                _tariffsMap[phoneNumber] = newTariff;
                _canChangeTariffMap[phoneNumber] = false;
                return true;
            }

            return false;
        }
        public void CalculateSingleShouldSuccess()
        {
            // Arrange
            _mockValidator.Setup(x => x.Validate(HardcodedConsumption));
            _tariff = new PackagedTariff(_mockValidator.Object);

            // Act
            var result = _tariff.Calculate(HardcodedConsumption);

            // Assert
            _mockValidator.Verify(x => x.Validate(It.Is <double>(i => i == HardcodedConsumption)), Times.Once);
            Assert.AreEqual(result.Consumption, HardcodedConsumption);
            Assert.AreEqual(result.TariffType, TariffType.PackagedTariff);
            Assert.AreEqual(result.AnnualCost, 800);
        }
Example #18
0
        IOrganization Create(string name, ITariff tariff, int creatorId)
        {
            bool isFree = tariff.IsFree();

            if (isFree)
            {
                CheckOneFree(creatorId);
            }

            IOrganization organization = Repository.Organizations.Create(name, tariff.Id, isFree);

            Repository.Organizations.AddUser(organization.Id, creatorId, EmployeeRole.Administrator, true);

            return(organization);
        }
Example #19
0
        public ISubscriber Subscribe(string subscriberName, ITariff tariff)
        {
            if (_subscribersFee.Keys.Any(s => s.Name.Equals(subscriberName)))
            {
                return(null);
            }

            ITerminal terminal = new Terminal(_dtHelper);
            IContract contract = _contractFactory.CreateContract(tariff, _phoneExchange.CreatePort());

            contract.ContractStateChanging += BillingContractStateChanging;
            ISubscriber subscriber = _subscriberFactory.CreateSubscriber(subscriberName, contract, terminal);

            _subscribersFee.Add(new KeyValuePair <ISubscriber, double>(subscriber, 0));

            return(subscriber);
        }
        public IContract SignContract(IClient client, ITariff selectedTariff)
        {
            var company     = this;
            var passport    = client.Passport;
            var phoneNumber = GetUniquePhoneNumber();
            var tariff      = selectedTariff;
            var Equipment   = new Equipment(new Telephone(), new Port(phoneNumber));            // give personal equipment to new abonent with separate port and port status set as "SwitchedOff"

            var newContract = new Contract(company, passport, phoneNumber, tariff, Equipment);  // initialize new contract

            Contracts.Add(newContract);                                                         // Add new contract in company list

            AddNewClientToCompany(client);                                                      // add new client to list of clients if this client is not on the list

            OnReportBillingSystemOfNewClient(new ContractConclusionEvent(phoneNumber, tariff)); // initialize contract conclusion and invoke it

            return(newContract);
        }
Example #21
0
        public int?GetAvailableProjectsCount(int boardId)
        {
            IBoard board = Utility.Boards.Get(boardId);

            if (!board.OrganizationId.HasValue)
            {
                return(null);
            }

            IOrganization organization = Utility.Organizations.Get(board.OrganizationId.Value);
            ITariff       tariff       = GetTariff(organization.TariffId);

            if (tariff.ProjectsPerBoard.HasValue)
            {
                List <IProject> projects = Utility.Projects.GetByBoard(boardId);
                return(tariff.ProjectsPerBoard.Value - projects.Count);
            }
            return(null);
        }
Example #22
0
        public void CalculateShouldSuccess()
        {
            // Arrange
            _mockValidator.Setup(x => x.Validate(HardcodedConsumption));
            _tariff = new BasicTariff(_mockValidator.Object);

            // Act
            var result = _tariff.Calculate(new double[] { HardcodedConsumption });

            // Assert
            _mockValidator.Verify(x => x.Validate(It.Is <double>(i => i == HardcodedConsumption)), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count(), 1);

            var first = result.First();

            Assert.AreEqual(first.Consumption, HardcodedConsumption);
            Assert.AreEqual(first.TariffType, TariffType.BasicTariff);
            Assert.AreEqual(first.AnnualCost, (5 * 12) + (0.22M * (decimal)HardcodedConsumption));
        }
        public void CalculateShouldSuccess()
        {
            // Arrange
            _mockValidator.Setup(x => x.Validate(4500));
            _tariff = new PackagedTariff(_mockValidator.Object);

            // Act
            var result = _tariff.Calculate(new double[] { 4500 });

            // Assert
            _mockValidator.Verify(x => x.Validate(It.Is <double>(i => i == 4500)), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count(), 1);

            var first = result.First();

            Assert.AreEqual(first.Consumption, 4500);
            Assert.AreEqual(first.TariffType, TariffType.PackagedTariff);
            Assert.AreEqual(first.AnnualCost, 800 + (500 * 0.3M));
        }
Example #24
0
            /// <summary>
            /// Adds the given element to the collection
            /// </summary>
            /// <param name="item">The item to add</param>
            public override void Add(IModelElement item)
            {
                ITimeTariffInterval timeTariffIntervalsCasted = item.As <ITimeTariffInterval>();

                if ((timeTariffIntervalsCasted != null))
                {
                    this._parent.TimeTariffIntervals.Add(timeTariffIntervalsCasted);
                }
                ITariff tariffsCasted = item.As <ITariff>();

                if ((tariffsCasted != null))
                {
                    this._parent.Tariffs.Add(tariffsCasted);
                }
                IConsumptionTariffInterval consumptionTariffIntervalsCasted = item.As <IConsumptionTariffInterval>();

                if ((consumptionTariffIntervalsCasted != null))
                {
                    this._parent.ConsumptionTariffIntervals.Add(consumptionTariffIntervalsCasted);
                }
            }
Example #25
0
        public Contract(ITariff tariff, IPort port, int paymentDay, int daysToChangeContract, IDateTimeHelper dtHelper = null)
        {
            if (tariff == null)
            {
                throw new ArgumentNullException("tariff", "tariff cannot be null.");
            }
            if (port == null)
            {
                throw new ArgumentNullException("port", "port cannot be null.");
            }

            _dtHelper = dtHelper ?? new DefaultDateTimeHelper();

            Tariff                = tariff;
            Port                  = port;
            PaymentDay            = paymentDay;
            Date                  = _dtHelper.Now;
            TariffStartDate       = Date;
            State                 = ContractStates.Active;
            _daysToChangeContract = daysToChangeContract;
        }
Example #26
0
        public IPort MakeContract(ITariff tariff, int id)
        {
            var item = Ports.Find(x => x.Id == id);

            if (item == null)
            {
                AddPort();
                Abonents.Contracts.Add(new Contract(Ports.Last().Id, tariff));
                Ports.Last().ChangeStatusOfContract();
                Ports.Last().EndingCall     += Abonents.FindContract(Ports.Last().Id).HandleCostOfCall;
                Ports.Last().GettingHistory += Abonents.HandleGetHistoryEvent;
                Ports.Last().GettingHistory += HandleGetHistoryEvent;
                Ports.Last().ChangingTariff += Abonents.FindContract(Ports.Last().Id).HandleChangeTariffEvent;
                return(Ports.Last());
            }
            else
            {
                IPort fail = new Port(-1, "");
                return(fail);
            }
        }
Example #27
0
        IOrganization Update(int id, string name, ITariff tariff)
        {
            IOrganization organization = Repository.Organizations.Get(id);

            bool isFree = tariff.IsFree();

            if (!organization.IsFree && isFree)
            {
                // при изменении тарифа на бесплатный
                // нужно проверять, состоят ли сотрудники в других бесплатных организациях
                Repository.Organizations.GetUsers(id)
                .ToList()
                .ForEach(x => CheckOneFree(x.UserId));
            }

            organization.Name     = name;
            organization.TariffId = tariff.Id;
            organization.IsFree   = isFree;
            Repository.SubmitChanges();

            return(organization);
        }
Example #28
0
 public TariffComparer(ITariff fistCompareTariff, ITariff secondTCompareariff)
 {
     _fistComparer    = fistCompareTariff;
     _secondTComparer = secondTCompareariff;
 }
Example #29
0
        public void OrganizationTest()
        {
            FormCollection        collection = new FormCollection();
            ViewResult            result;
            RedirectToRouteResult redirectToRouteResult;

            OrganizationController organizationController = Base.GetController <OrganizationController>();
            PartialViewResult      partialViewResult      = organizationController.Edit(null);

            List <ITariff> tariffs = partialViewResult.ViewData.Get <List <ITariff> >("tariffs");

            Assert.IsNotNull(tariffs);
            ITariff freeTariff = tariffs.Single(x => x.IsFree());

            Assert.IsNotNull(freeTariff);
            Main.Registation(Email0);

            // создали тестовую организацию
            collection.Clear();
            organizationController = Base.GetController <OrganizationController>();
            collection.Add("Name", "test");
            collection.Add("TariffId", freeTariff.Id.ToString());
            partialViewResult = organizationController.Edit(null, collection);
            IOrganization organization = ((List <EmployeeSettings>)partialViewResult.Model).Single().Organization;

            Assert.IsNotNull(organization);
            int organizationId = organization.Id;

            #region Приглашения

            InviteController inviteController = Base.GetController <InviteController>();

            // через мыло незареганного
            collection.Clear();
            collection.Add("Email", Email3);
            inviteController.NewInvite(organizationId, collection);
            List <IUsersInvite> invites = inviteController.Utility.Invites.GetInvites(organizationId);
            IUsersInvite        invite  = invites.FirstOrDefault(x => x.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(invite);
            Main.Registation(Email3, out result, out redirectToRouteResult, invite.InviteCode);
            ViewResultBase   resultBase = organizationController.EmployeeList(organizationId);
            EmployeeSettings emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(emeil3User);
            collection.Clear();
            collection.Add("delete", "true");
            organizationController.EmployeeEdit(organizationId, emeil3User.User.Id, collection);

            // через мыло зареганного
            inviteController.Dispose();
            inviteController = Base.GetController <InviteController>();
            collection.Clear();
            collection.Add("Email", Email3);
            inviteController.NewInvite(organizationId, collection);
            invites = organizationController.Utility.Invites.GetInvites(organizationId);
            invite  = invites.FirstOrDefault(x => x.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(invite);
            Base.GetController <AdminController>().ClearCache();
            resultBase = organizationController.EmployeeList(organizationId);
            emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(emeil3User);
            var userController = Base.GetController <UserController>();
            userController.Login(null, Email3, Email3, true, null);
            inviteController.AcceptInvite(organizationId);
            emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsTrue(emeil3User.Settings.UserRole == (int)EmployeeRole.Employee);

            // через ссылку незареганного пользователя
            userController.Dispose();
            userController = Base.GetController <UserController>();
            userController.SignOut();
            redirectToRouteResult = (RedirectToRouteResult)userController.Invite(organization.InviteCode);
            Assert.IsTrue(redirectToRouteResult.RouteValues["action"].ToString() == "Register");
            collection.Clear();
            Main.Registation(Email4, out result, out redirectToRouteResult, organization.InviteCode);
            resultBase = inviteController.List();
            var           organizations = (IEnumerable <IOrganization>)resultBase.Model;
            IOrganization first         = organizations.FirstOrDefault();
            Assert.IsTrue(first != null && first.Id == organizationId);
            inviteController.AcceptInvite(first.Id);
            resultBase = organizationController.EmployeeList(organizationId);
            EmployeeSettings emeil4User = ((List <EmployeeSettings>)resultBase.Model).FirstOrDefault(x => x.User.EMail.ToUpper() == Email4.ToUpper());
            Assert.IsNotNull(emeil4User);
            collection.Clear();
            collection.Add("delete", "true");
            organizationController.EmployeeEdit(organizationId, emeil4User.User.Id, collection);

            // через ссылку зареганного пользователя
            userController.Dispose();
            userController        = Base.GetController <UserController>();
            redirectToRouteResult = (RedirectToRouteResult)userController.Invite(organization.InviteCode);
            Assert.IsTrue(redirectToRouteResult.RouteValues["action"].ToString() == "Index");
            collection.Clear();
            inviteController.Dispose();
            inviteController = Base.GetController <InviteController>();
            resultBase       = inviteController.List();
            organizations    = (IEnumerable <IOrganization>)resultBase.Model;
            first            = organizations.FirstOrDefault();
            Assert.IsTrue(first != null && first.Id == organizationId);
            inviteController.AcceptInvite(first.Id);
            resultBase = organizationController.EmployeeList(organizationId);
            emeil4User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email4.ToUpper());
            Assert.IsNotNull(emeil4User);

            #endregion

            #region Удаление

            userController.Dispose();
            userController = Base.GetController <UserController>();
            userController.Login(null, Email3, Email3, true, null);

            BoardsController boardsController = Base.GetController <BoardsController>();
            collection.Clear();
            collection.Add("name", "t1");
            collection.Add("OrganizationId", organizationId.ToString());
            boardsController.Create(collection);

            collection.Clear();
            collection.Add("name", "t2");
            collection.Add("OrganizationId", organizationId.ToString());
            boardsController.Create(collection);

            collection.Clear();
            organizationController = Base.GetController <OrganizationController>();
            organizationController.Delete(organizationId);

            boardsController  = Base.GetController <BoardsController>();
            partialViewResult = boardsController.List(null);
            Assert.IsFalse((partialViewResult.Model as List <IBoard>).Single().OrganizationId.HasValue);            // остается только личная доска

            #endregion
        }
Example #30
0
 public IndividualClient(int id, ITariff tariff, Phone phone, decimal balance, ClientStatus status, string name)
     : base(id, tariff, phone, balance, status)
 {
     Name    = name;
     Balance = balance;
 }
Example #31
0
        public ContractConclusionEvent(string phoneNumber, ITariff tariff)
        {
            PhoneNumber = phoneNumber;

            Tariff = tariff;
        }
Example #32
0
 public void ChangeTariff(ITariff tariffPlan)
 {
     OnChangeTariffEvent(new ChangeTariffEventArgs(Port, tariffPlan));
 }
Example #33
0
 public bool SetTariffForTerminal(PhoneNumber number, ITariff tariff)
 {
     bool isChanged = false;
     if (!_tariffMaping.Keys.Contains(number)) { _tariffMaping.Add(number, tariff); isChanged = true; }
     else
     {
         if ((DateTime.Now -_tariffMaping[number].DateOfSet).Days >= DateTime.DaysInMonth(_tariffMaping[number].DateOfSet.Year, (_tariffMaping[number].DateOfSet).Month))
         {
             _tariffMaping[number] = tariff;
             isChanged = true;
         }
         else { isChanged = false; }
     }
     if (isChanged) { OnTerminalChangedTariff(this, number); }
     return isChanged;
 }
Example #34
0
        public IOrganization Create(string name, int tariffId)
        {
            ITariff tariff = Utility.Tariffs.GetTariff(tariffId);

            return(Create(name, tariff, Authentication.UserId));
        }
 public bool TryChangeTariff(PhoneNumber phoneNumber, ITariff newTariff)
 {
     return _billingSystem.TryChangeTariff(phoneNumber, newTariff);
 }