public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] RiskType riskType)
        {
            if (id != riskType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(riskType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RiskTypeExists(riskType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(riskType));
        }
        public async Task <IActionResult> PutRiskType([FromRoute] int id, [FromBody] RiskType riskType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != riskType.Id)
            {
                return(BadRequest());
            }

            _context.Entry(riskType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RiskTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public Goal SetNew(int userId, int goalOptionId, int timeframe, int risk, double?targetAmount, double startingAmount, double monthlyContribution)
        {
            GoalOptionsBusiness.Get(goalOptionId);
            RiskType riskType = RiskType.Get(risk);

            if (timeframe <= 0)
            {
                throw new ArgumentException("Invalid timeframe for goal.");
            }
            if ((startingAmount == 0 && monthlyContribution == 0) || startingAmount < 0 || monthlyContribution < 0)
            {
                throw new ArgumentException("Invalid contribution.");
            }

            var goal = new Goal();

            goal.UserId              = userId;
            goal.GoalOptionId        = goalOptionId;
            goal.CreationDate        = DateTime.UtcNow;
            goal.MonthlyContribution = monthlyContribution;
            goal.StartingAmount      = startingAmount;
            goal.TargetAmount        = targetAmount;
            goal.Timeframe           = timeframe;
            goal.Risk = riskType.Value;
            return(goal);
        }
 /// <summary>
 /// DL20140603HJFE232MDWKL09WD
 /// </summary>
 public override int riskscore_fromfactors(int[] factors, RiskType riskType)
 {
     /* [ahirov 20190315] */
     return(riskType == RiskType.estimation
         ? riskestimationscore_fromfactors(factors)
         : riskassesment_fromfactors(factors));
 }
示例#5
0
        public virtual int _GetUniqueIdentifier()
        {
            var hashCode = 399326290;

            hashCode = hashCode * -1521134295 + (WayPointVisibilityID?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Waypoint?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (From?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (To?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ConveyanceId?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ConveyanceRef?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (ShippingAgent?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (TotalConsignments?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (DirectConsignments?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (TransshipmentConsignments?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (TotalCargos?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (FullCargos?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (EmptyCargos?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (TotalRiskDetected?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Consignment?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (CargoId?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (RiskType?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (RiskScore?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Severity?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Details?.GetHashCode() ?? 0);
            hashCode = hashCode * -1521134295 + (Suggestions?.GetHashCode() ?? 0);
            return(hashCode);
        }
示例#6
0
        public Insurance(string name, string description, DateTime start, int coveragePeriod, double cost, RiskType risk)
            : this()
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new InsuranceDomainException($"{nameof(name)} is required.");
            }

            if (start < DateTime.UtcNow)
            {
                throw new InsuranceDomainException("Invalid start date.");
            }

            if (coveragePeriod == default(int))
            {
                throw new InsuranceDomainException("Invalid coverage period.");
            }

            if (cost <= 0)
            {
                throw new InsuranceDomainException("Invalid insurance cost.");
            }

            _name           = name;
            _description    = description;
            _startDate      = start;
            _coveragePeriod = coveragePeriod;
            _cost           = cost;
            _risk           = risk;
            _creationDate   = DateTime.UtcNow;
        }
示例#7
0
 //update a type
 public static bool UpdateType(RiskType type)
 {
     MySqlParameter[] parms = new MySqlParameter[] {
         new MySqlParameter(PARAM_TYPENUMBER, type.TypeNumber),
         new MySqlParameter(PARAM_TYPENAME, type.TypeName)
     };
     return(MySqlHelper.ExecuteNonQuery(MySqlHelper.CONN_STR, CommandType.Text, UPDATE_TYPE, parms));
 }
 public void The_method_check_should_return_RiskType_by_stake(int customerId, int stake, RiskType type)
 {
     var history = new Dictionary<int, SettledBetReport>
     {
         {2, new SettledBetReport {AvgStake = 1}},
     };
     var svc = new UnusualBetDetector();
     Assert.AreEqual(type, svc.Check(new UnsettledBet { CustomerId = customerId, Stake = stake }, history));
 }
示例#9
0
        public ActionResult RiskTypeDeleteConfirmed(int id)
        {
            RiskType type    = db.RiskTypes.Single(p => p.RiskTypeId == id);
            var      groupId = type.RiskGroupId;

            db.RiskTypes.Remove(type);
            db.SaveChanges();
            return(RedirectToAction("RiskTypeList", new { groupId = groupId }));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            RiskType riskType = await db.RiskTypes.FindAsync(id);

            db.RiskTypes.Remove(riskType);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
 public void The_method_check_should_return_BigBet_for_bet_with_towin_gt_1000(int customerId, RiskType type)
 {
     var history = new Dictionary<int, SettledBetReport>
     {
         {2, new SettledBetReport {IsUnusual = false}},
         {3, new SettledBetReport {IsUnusual = true}}
     };
     var svc = new RiskyBetDetector();
     Assert.AreEqual(type, svc.Check(new UnsettledBet { CustomerId = customerId }, history));
 }
        public async Task <ActionResult> Edit([Bind(Include = "IdRiskType,Name")] RiskType riskType)
        {
            if (ModelState.IsValid)
            {
                db.Entry(riskType).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(riskType));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] RiskType riskType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(riskType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(riskType));
        }
        public IEnumerable <RiskType> Get(RiskType entity)
        {
            List <Models.RiskType> riskTypes = null;

            if (entity == null)
            {
                riskTypes = _context.RiskTypes.ToList();
            }

            return(mapping.Map <IEnumerable <RiskType> >(riskTypes));
        }
        public async Task <ActionResult> Create([Bind(Include = "IdRiskType,Name")] RiskType riskType)
        {
            if (ModelState.IsValid)
            {
                db.RiskTypes.Add(riskType);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(riskType));
        }
示例#16
0
        public DomainObjects.Portfolio.Portfolio GetByRisk(int roboAdvisorId, RiskType riskType)
        {
            string defaultPortfoliosKey = "DefaultPortfolios";
            List <DomainObjects.Portfolio.Portfolio> portfolios = null;

            if (roboAdvisorId == AdvisorBusiness.DefaultAdvisorId)
            {
                portfolios = MemoryCache.Get <List <DomainObjects.Portfolio.Portfolio> >(defaultPortfoliosKey);
            }
            if (portfolios == null)
            {
                portfolios = List(roboAdvisorId).Where(c => c.Advisor.Type == DomainObjects.Advisor.AdvisorType.Robo.Value).ToList();
                if (roboAdvisorId == AdvisorBusiness.DefaultAdvisorId)
                {
                    MemoryCache.Set <List <DomainObjects.Portfolio.Portfolio> >(defaultPortfoliosKey, portfolios);
                }
            }

            if (portfolios.Count == 1)
            {
                return(portfolios.First());
            }

            var sameRisk = portfolios.SingleOrDefault(c => c.Projection.RiskType == riskType);

            if (sameRisk != null)
            {
                return(sameRisk);
            }

            var littleLower = portfolios.SingleOrDefault(c => c.Projection.RiskType.Value == (riskType.Value - 1));

            if (littleLower != null)
            {
                return(littleLower);
            }

            var littleHigher = portfolios.SingleOrDefault(c => c.Projection.RiskType.Value == (riskType.Value + 1));

            if (littleHigher != null)
            {
                return(littleHigher);
            }

            var lower = portfolios.SingleOrDefault(c => c.Projection.RiskType.Value == (riskType.Value - 2));

            if (lower != null)
            {
                return(lower);
            }

            return(portfolios.Single(c => c.Projection.RiskType.Value == (riskType.Value + 2)));
        }
        public async Task <IActionResult> PostRiskType([FromBody] RiskType riskType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.RiskTypes.Add(riskType);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRiskType", new { id = riskType.Id }, riskType));
        }
示例#18
0
 public ActionResult Create(RiskType riskType, IFormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         _riskType.AddRiskType(riskType);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
示例#19
0
 public ActionResult Edit(int id, RiskType riskType, IFormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         _riskType.UpdateRiskType(id, riskType);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
        // GET: RiskTypes/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RiskType riskType = await db.RiskTypes.FindAsync(id);

            if (riskType == null)
            {
                return(HttpNotFound());
            }
            return(View(riskType));
        }
示例#21
0
        public RiskType Get(int id)
        {
            RiskType         riskType = new RiskType();
            OracleConnection con      = new OracleConnection(ConnectionString);
            OracleDataReader dr       = null;
            string           sql      = "";


            sql = "SELECT t.RISK_TYPE_ID,t.RISK_TYPE     FROM MNB_RISK_TYPE t WHERE t.RISK_TYPE_ID=:V_RISK_TYPE_ID ";

            OracleCommand cmd = new OracleCommand(sql, con);

            cmd.Parameters.Add(new OracleParameter("V_RISK_TYPE_ID", id));

            con.Open();
            try
            {
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();

                    riskType.RiskTypeId   = Convert.ToInt32(dr["RISK_TYPE_ID"]);
                    riskType.RiskTypeName = dr["RISK_TYPE"].ToString();

                    dr.Close();
                    con.Close();
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception exception)
            {
                if (dr != null || con.State == ConnectionState.Open)
                {
                    dr.Close();
                    con.Close();
                }
            }
            finally
            {
                con.Close();
            }

            return(riskType);
        }
示例#22
0
        public int UpdateRiskType(int id, RiskType riskType)
        {
            var _getRiskType = GetRiskType(id);

            if (_getRiskType != null)
            {
                var _existingRiskType = _getRiskType;
                _existingRiskType.Name = riskType.Name;

                _riskRegisterDbContext.RiskTypes.Update(_existingRiskType);
                _riskRegisterDbContext.SaveChanges();

                return(_existingRiskType.Id);
            }
            return(0);
        }
示例#23
0
 public int AddRiskType(RiskType riskType)
 {
     try
     {
         if (riskType != null)
         {
             _riskRegisterDbContext.RiskTypes.Add(riskType);
             _riskRegisterDbContext.SaveChanges();
             return(riskType.Id);
         }
         return(0);
     }
     catch (Exception)
     {
         return(-1);
     }
 }
示例#24
0
        public Projection SetNew(int portfolioId, double projectionValue, RiskType risk, double? optimisticProjection, double? pessimisticProjection)
        {
            if (projectionValue <= 0)
                throw new ArgumentException("Invalid projection value.");
            if (optimisticProjection.HasValue && optimisticProjection.Value < projectionValue)
                throw new ArgumentException("Invalid optimistic projection value.");
            if (pessimisticProjection.HasValue && (pessimisticProjection.Value < 0 || pessimisticProjection.Value > projectionValue))
                throw new ArgumentException("Invalid pessimistic projection value.");

            var projection = new Projection();
            projection.PortfolioId = portfolioId;
            projection.Date = DateTime.UtcNow;
            projection.Risk = risk.Value;
            projection.ProjectionValue = projectionValue;
            projection.OptimisticProjectionValue = optimisticProjection;
            projection.PessimisticProjectionValue = pessimisticProjection;
            return projection;
        }
示例#25
0
        //Get type by id from database
        public static bool GetTypeByNumber(String TypeNumber, out RiskType type)
        {
            MySqlParameter parm = new MySqlParameter(PARAM_TYPENUMBER, MySqlDbType.VarChar, 45);

            parm.Value = TypeNumber;
            using (MySqlDataReader sdr = MySqlHelper.ExecuteReader(MySqlHelper.CONN_STR, CommandType.Text, SELECT_TYPE_BY_TYPENAME, parm))
            {
                if (sdr.Read())
                {
                    type = new RiskType(sdr.GetString(0), sdr.GetString(1));
                    return(true);
                }
                else
                {
                    type = null;
                    return(false);
                }
            }
        }
示例#26
0
        private double GetRiskFee(int Insurance, RiskType type)
        {
            double insuranceFee = 0;

            switch (type)
            {
            case RiskType.Low:
                insuranceFee = Insurance > 3000 ? Insurance * 0.005 : 0;
                break;

            case RiskType.Middle:
                insuranceFee = Insurance * 0.01;
                break;

            case RiskType.High:
                insuranceFee = Insurance * 0.03;
                break;
            }
            return(insuranceFee);
        }
示例#27
0
        public Projection Create(string email, int portfolioId, double projectionValue, RiskType risk, double? optimisticProjection,
            double? pessimisticProjection, Dictionary<int, double> distribution)
        {
            var user = UserBusiness.GetValidUser(email);
            var portfolio = PortfolioBusiness.GetValidByOwner(user.Id, portfolioId);
            if (portfolio == null)
                throw new ArgumentException("Invalid portfolio.");

            return Create(portfolio, projectionValue, risk, optimisticProjection, pessimisticProjection, distribution);
        }
        public void The_method_check_should_return_RiskType_by_stake(int customerId, int stake, RiskType type)
        {
            var history = new Dictionary <int, SettledBetReport>
            {
                { 2, new SettledBetReport {
                      AvgStake = 1
                  } },
            };
            var svc = new UnusualBetDetector();

            Assert.AreEqual(type, svc.Check(new UnsettledBet {
                CustomerId = customerId, Stake = stake
            }, history));
        }
示例#29
0
 private IRiskType CreateRiskTypeInstance(DataRow row)
 {
     RiskType r = new RiskType()
     {
         Id = Convert.ToInt32(row["Id"]),
         Title = row["Title"].ToString()
     };
     return r;
 }
 public void AddToRiskTypes(RiskType riskType)
 {
     base.AddObject("RiskTypes", riskType);
 }
 public static RiskType CreateRiskType(int ID, string typeOfRisk, bool inUse, byte[] rowVersion)
 {
     RiskType riskType = new RiskType();
     riskType.Id = ID;
     riskType.TypeOfRisk = typeOfRisk;
     riskType.InUse = inUse;
     riskType.RowVersion = rowVersion;
     return riskType;
 }
示例#32
0
 public Projection CreateProjection(string email, int portfolioId, double projection, int risk, double?optimisticProjection,
                                    double?pessimisticProjection, Dictionary <int, double> distribution)
 {
     return(ProjectionBusiness.Create(email, portfolioId, projection, RiskType.Get(risk), optimisticProjection, pessimisticProjection, distribution));
 }
 public override int risk_lcaption_fromfactors(int[] factors, bool may_see_score, RiskType riskType)
 {
     if (riskType == RiskType.estimation)
     {
         var score = riskestimationscore_fromfactors(factors);
         var level = riskestimationlevel_fromscore(score);
         return(riskestimation_lcaptionfromlevel(level));
     }
     else
     {
         var score = riskassesment_fromfactors(factors);
         var level = risklevel_fromscore(score);
         return(risk_lcaptionfromlevel(level));
     }
 }
示例#34
0
        internal Projection Create(DomainObjects.Portfolio.Portfolio portfolio, double projectionValue, RiskType risk, 
            double? optimisticProjection, double? pessimisticProjection, Dictionary<int, double> distribution)
        {
            var projection = SetNew(portfolio.Id, projectionValue, risk, optimisticProjection, pessimisticProjection);
            using (var transaction = new TransactionalDapperCommand())
            {
                transaction.Insert(projection);
                var distributions = DistributionBusiness.SetNew(projection.Id, distribution);
                foreach (Distribution dist in distributions)
                    transaction.Insert(dist);

                portfolio.ProjectionId = projection.Id;
                transaction.Update(portfolio);
                projection.Distribution = distributions;
                transaction.Commit();
            }
            return projection;
        }
示例#35
0
        public KeyValuePair <int, IEnumerable <Model.Portfolio> > ListRoboAdvisors(string email, int goalOptionId, int risk)
        {
            var user         = UserBusiness.GetValidUser(email);
            var purchases    = Task.Factory.StartNew(() => BuyBusiness.ListPurchases(user.Id));
            var goalOption   = GoalOptionsBusiness.Get(goalOptionId);
            var riskType     = RiskType.Get(risk, goalOption.Risk);
            var riskPriority = RiskType.GetRiskPriority(riskType);
            var advisors     = Data.ListRobosAvailable();
            var portfolios   = Task.Factory.StartNew(() => PortfolioBusiness.List(advisors.Select(c => c.Id)));

            Task.WaitAll(portfolios);

            var portfolioQty = Task.Factory.StartNew(() => BuyBusiness.ListPortfoliosPurchases(portfolios.Result.SelectMany(c => c.Value.Select(x => x.Id))));

            List <Task <List <PortfolioHistory> > > histories = new List <Task <List <PortfolioHistory> > >();

            foreach (DomainObjects.Portfolio.Portfolio portfolio in portfolios.Result.SelectMany(c => c.Value))
            {
                histories.Add(Task.Factory.StartNew(() => PortfolioHistoryBusiness.ListHistory(portfolio.Id)));
            }

            Task.WaitAll(purchases, portfolioQty);
            Task.WaitAll(histories.ToArray());

            List <Model.Portfolio> portfolioWithSameRisk         = new List <Model.Portfolio>();
            List <Model.Portfolio> portfolioWithLittleLowerRisk  = new List <Model.Portfolio>();
            List <Model.Portfolio> portfolioWithLittleHigherRisk = new List <Model.Portfolio>();
            List <Model.Portfolio> portfolioWithLowerRisk        = new List <Model.Portfolio>();
            List <Model.Portfolio> portfolioWithHigherRisk       = new List <Model.Portfolio>();
            List <Model.Portfolio> portfolioWithVeryLowerRisk    = new List <Model.Portfolio>();
            List <Model.Portfolio> portfolioWithVeryHigherRisk   = new List <Model.Portfolio>();

            foreach (KeyValuePair <int, List <DomainObjects.Portfolio.Portfolio> > advisorPortfolios in portfolios.Result)
            {
                var advisor = advisors.Single(c => c.Id == advisorPortfolios.Key);
                advisorPortfolios.Value.ForEach(c => c.PortfolioHistory = histories.SelectMany(x => x.Result.Where(g => g.PortfolioId == c.Id)).ToList());
                foreach (var r in riskPriority)
                {
                    var riskFound = advisorPortfolios.Value.SingleOrDefault(c => c.Projection.RiskType == r);
                    if (riskFound != null)
                    {
                        var port       = PortfolioBusiness.FillPortfolioModel(riskFound, advisor, user, purchases.Result, portfolioQty.Result);
                        var difference = riskFound.Projection.RiskType.Value - riskType.Value;
                        if (difference == 0)
                        {
                            portfolioWithSameRisk.Add(port);
                        }
                        else if (difference == 1)
                        {
                            portfolioWithLittleHigherRisk.Add(port);
                        }
                        else if (difference == -1)
                        {
                            portfolioWithLittleLowerRisk.Add(port);
                        }
                        else if (difference == 2)
                        {
                            portfolioWithHigherRisk.Add(port);
                        }
                        else if (difference == -2)
                        {
                            portfolioWithLowerRisk.Add(port);
                        }
                        else if (difference > 2)
                        {
                            portfolioWithVeryHigherRisk.Add(port);
                        }
                        else
                        {
                            portfolioWithVeryLowerRisk.Add(port);
                        }
                        break;
                    }
                }
            }
            var result = portfolioWithSameRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent).ToList();

            result.AddRange(portfolioWithLittleLowerRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent));
            result.AddRange(portfolioWithLittleHigherRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent));
            result.AddRange(portfolioWithLowerRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent));
            result.AddRange(portfolioWithHigherRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent));
            result.AddRange(portfolioWithVeryLowerRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent));
            result.AddRange(portfolioWithVeryHigherRisk.OrderByDescending(c => c.PurchaseQuantity).ThenByDescending(c => c.ProjectionPercent));

            return(new KeyValuePair <int, IEnumerable <Model.Portfolio> >(riskType.Value, result));
        }