Exemplo n.º 1
0
        private CalcViewModel updateCalcViewModel(CalcViewModel model)
        {
            model.Parts = _buildingPartRepository.GetAll();
            model.DefectDescriptions = _defectDescriptionRepository.GetAll();
            model.DefectImportances  = _defectImportanceRepository.GetAll();
            model.DefectIntencities  = _defectIntencityRepository.GetAll();
            model.DefectExtents      = _defectExtentRepository.GetAll();
            model.Actions            = _actionRepository.GetAll();

            // Eenh enum
            IEnumerable <Eenh> eenhsTypes = Enum.GetValues(typeof(Eenh)).Cast <Eenh>();

            model.EenhList = from eenh in eenhsTypes
                             select new SelectListItem
            {
                Text  = eenh.ToString(),
                Value = ((int)eenh).ToString()
            };

            // Taxes enum
            IEnumerable <Taxe> taxeTypes = Enum.GetValues(typeof(Taxe)).Cast <Taxe>();

            model.TaxeList = from taxe in taxeTypes
                             select new SelectListItem
            {
                Text  = taxe.ToString(),
                Value = ((int)taxe).ToString()
            };

            return(model);
        }
Exemplo n.º 2
0
        private CalcViewModel InitCalcViewModel()
        {
            var parts = new CalcViewModel {
                Parts = _buildingPartRepository.GetAll(),
                DefectDescriptions = _defectDescriptionRepository.GetAll(),
                DefectImportances  = _defectImportanceRepository.GetAll(),
                DefectIntencities  = _defectIntencityRepository.GetAll(),
                DefectExtents      = _defectExtentRepository.GetAll(),
                Actions            = _actionRepository.GetAll(),
                StartYear          = 2014
            };

            // Eenh enum
            IEnumerable <Eenh> eenhsTypes = Enum.GetValues(typeof(Eenh)).Cast <Eenh>();

            parts.EenhList = from eenh in eenhsTypes
                             select new SelectListItem
            {
                Text  = eenh.ToString(),
                Value = ((int)eenh).ToString()
            };

            // Taxes enum
            IEnumerable <Taxe> taxeTypes = Enum.GetValues(typeof(Taxe)).Cast <Taxe>();

            parts.TaxeList = from taxe in taxeTypes
                             select new SelectListItem
            {
                Text  = taxe.ToString(),
                Value = ((int)taxe).ToString()
            };

            return(parts);
        }
        public ActionResult CalcByDepartmentName(CalcViewModel model, bool isUseDepartment, int department)
        {
            User user = UserManager.FindById(User.Identity.GetUserId());

            ViewBag.StructuralDepartments = new SelectList(db.GetDepartments().FindAll(d => d.Id == user.DepartmentId), "Id", "Name");
            ViewBag.Departments           = new SelectList(db.GetDepartments(user.DepartmentId), "Id", "Name");
            CalcViewModel resultModel;

            if (!isUseDepartment)
            {
                resultModel = new CalcViewModel
                {
                    StructuralDepartmentId = db.GetDepartment(user.DepartmentId).Id,
                    PPIViewModel           = db.GetPPIViewModelByStructuralDepartment(db.GetDepartment(model.DepartmentId)),
                    DatabaseHelper         = db
                };
            }
            else
            {
                resultModel = new CalcViewModel
                {
                    StructuralDepartmentId = db.GetDepartment(user.DepartmentId).Id,
                    DepartmentId           = department,
                    PPIViewModel           = db.GetPPIViewModelByDepartment(db.GetDepartment(department)),
                    DatabaseHelper         = db
                };
            }
            return(View(resultModel));
        }
Exemplo n.º 4
0
        public ActionResult Add(CalcViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newItem = new Matrix()
                {
                    BuildingPartId      = model.BuildingPartsId,
                    DefectDescriptionId = model.DefectDescriptionsId,
                    ImportanceId        = model.DefectImportancesId,
                    IntencityId         = model.DefectIntencitiesId,
                    ExtentId            = model.DefectExtentsId,
                    Condition           = model.Condition,
                    ActieId             = model.ActionId,
                    HvhId       = model.Hvh,
                    EenhId      = model.EenhId,
                    Percent     = (model.Percent == 0) ? 1 : (float)0.2,
                    Cost        = model.Cost,
                    Total       = model.Total,
                    BTW         = model.TaxeId,
                    Cycle       = model.Cycle,
                    StartYear   = model.StartYear,
                    UpdatedDate = DateTime.Now
                };

                // insert
                _matrixRepository.Insert(newItem);

                // redirect
                return(RedirectToAction("Index", "Page"));
            }

            model = updateCalcViewModel(model);
            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Manual()
        {
            if (this.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase))
            {
                String first  = this.Request.Form["First"];
                String second = this.Request.Form["Second"];

                if (!Int32.TryParse(first, out int number))
                {
                    this.ViewBag.FirstError = true;
                    return(this.View());
                }

                if (!Int32.TryParse(second, out number))
                {
                    this.ViewBag.SecondError = true;
                    return(this.View());
                }

                String action = this.Request.Form["Action"];
                var    calc   = new Int32();

                if (action.Equals("Add", StringComparison.OrdinalIgnoreCase))
                {
                    calc = this.calcService.Add(Convert.ToInt32(first), Convert.ToInt32(second));
                }

                if (action.Equals("Sub", StringComparison.OrdinalIgnoreCase))
                {
                    calc = this.calcService.Sub(Convert.ToInt32(first), Convert.ToInt32(second));
                }

                if (action.Equals("Mul", StringComparison.OrdinalIgnoreCase))
                {
                    calc = this.calcService.Mul(Convert.ToInt32(first), Convert.ToInt32(second));
                }

                if (action.Equals("Div", StringComparison.OrdinalIgnoreCase))
                {
                    if (second.Equals("0", StringComparison.OrdinalIgnoreCase))
                    {
                        this.ViewBag.DivisionError = true;
                        return(this.View());
                    }
                    calc = this.calcService.Div(Convert.ToInt32(first), Convert.ToInt32(second));
                }

                var model = new CalcViewModel()
                {
                    First    = first,
                    Second   = second,
                    Operator = action,
                    Result   = calc.ToString()
                };

                return(this.View(model));
            }

            return(this.View());
        }
Exemplo n.º 6
0
 private Calc()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Vm          = new CalcViewModel();
     this.DataContext = this.Vm;
     InitializeComponent();
     this.OnLoaded((window) => {
         window.BuildEventPath <CalcConfigSetInitedEvent>("收益计算器数据集刷新后刷新VM", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                          path: message => {
             foreach (var coinVm in Vm.CoinVms.AllCoins)
             {
                 coinVm.CoinIncomeVm.Refresh();
             }
         });
         window.BuildEventPath <Per1MinuteEvent>("当收益计算器页面打开着的时候周期刷新", LogEnum.None, location: this.GetType(), PathPriority.Normal,
                                                 path: message => {
             if (Vm.CoinVms.AllCoins.Count == 0)
             {
                 return;
             }
             if (Vm.CoinVms.AllCoins.Max(a => a.CoinIncomeVm.ModifiedOn).AddMinutes(10) < DateTime.Now)
             {
                 NTMinerContext.Instance.CalcConfigSet.Init(forceRefresh: true);
             }
         });
         NTMinerContext.Instance.CalcConfigSet.Init(forceRefresh: true);
     });
 }
Exemplo n.º 7
0
        public ActionResult ModelBindingInSeparateModel(CalcViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                if (model.Operator.Equals("Add", StringComparison.OrdinalIgnoreCase))
                {
                    model.Result = this.calcService.Add(Convert.ToInt32(model.First), Convert.ToInt32(model.Second)).ToString();
                }

                if (model.Operator.Equals("Sub", StringComparison.OrdinalIgnoreCase))
                {
                    model.Result = this.calcService.Sub(Convert.ToInt32(model.First), Convert.ToInt32(model.Second)).ToString();
                }

                if (model.Operator.Equals("Mul", StringComparison.OrdinalIgnoreCase))
                {
                    model.Result = this.calcService.Mul(Convert.ToInt32(model.First), Convert.ToInt32(model.Second)).ToString();
                }

                if (model.Operator.Equals("Div", StringComparison.OrdinalIgnoreCase))
                {
                    if (model.Second.Equals("0", StringComparison.OrdinalIgnoreCase))
                    {
                        this.ModelState.AddModelError("Second", "Division by zero is forbidden");
                        return(this.View(model));
                    }
                    model.Result = this.calcService.Div(Convert.ToInt32(model.First), Convert.ToInt32(model.Second)).ToString();
                }

                return(this.View(model));
            }

            return(this.View(model));
        }
Exemplo n.º 8
0
        public ActionResult Index()
        {
            var model = new CalcViewModel();

            model.CalcErrorCode = CalcErrorCode.None;
            model.Expression    = "";

            try
            {
                SetUpCurrentUser();

                try
                {
                    // Try to load user expressions history
                    model.Expressions = GetTodayExpressionsHistoryForUser(currentUser);
                }
                catch (Exception)
                {
                    // Unable to load history, preparing empty model

                    model.DataErrorCodes.Add(DataErrorCode.GettingHistoryFailure);
                    model.Expressions = new List <Expression>();
                    model.Expression  = "";
                }
            }
            catch (Exception)
            {
                // Unable to identify user
                model.DataErrorCodes.Add(DataErrorCode.UserIdentificationFailure);
            }

            return(View(model: model));
        }
Exemplo n.º 9
0
        public IActionResult Index(CalcViewModel model)
        {
            if (ModelState.IsValid)
            {
                switch (model.OperatorType)
                {
                case OperatorType.Addition:
                    model.Result = model.NumberA + model.NumberB;
                    break;

                case OperatorType.Subtraction:
                    model.Result = model.NumberA - model.NumberB;
                    break;

                case OperatorType.Division:
                    // Verkar gå bra med 'oändligt' svar => Bortkommenterad test av nämnare = 0
                    //if (model.NumberB == 0)
                    //    ModelState.AddModelError("NumberB", "Det går inte att dividera med 0.");
                    //else
                    model.Result = model.NumberA / model.NumberB;
                    break;

                case OperatorType.Multiplication:
                    model.Result = model.NumberA * model.NumberB;
                    break;
                }

                // *
                TempData[prgKey] = JsonConvert.SerializeObject(model);
                return(RedirectToAction("Index"));
            }

            PopulateDDLs(model);
            return(View(model));
        }
        public ActionResult Divide(CalcViewModel model)
        {
            var cs     = new CalcService();
            var result = cs.SafeDivide(model.Number1, model.Number2);

            model.Result = result;
            return(View("Process", model));
        }
        public ActionResult Multiply(CalcViewModel model)
        {
            var cs     = new CalcService();
            var result = cs.MultiplyNumbers(model.Number1, model.Number2);

            model.Result = result;
            return(View("Process", model));
        }
        public ActionResult Process(CalcViewModel model)
        {
            var cs     = new CalcService();
            var result = cs.AddNumbers(model.Number1, model.Number2);

            model.Result = result;
            return(View(model));
        }
Exemplo n.º 13
0
 private void PopulateDDLs(CalcViewModel model)
 {
     model.ValidOperators = new List <OperatorType>()
     {
         OperatorType.Addition,
         OperatorType.Subtraction,
         OperatorType.Multiplication,
         OperatorType.Division
     };
 }
Exemplo n.º 14
0
        public MainWindow()
        {
            InitializeComponent();

            cvm = (CalcViewModel)DataContext;


            var uri = new Uri("light.xaml", UriKind.Relative);
            ResourceDictionary resourceDict = Application.LoadComponent(uri) as ResourceDictionary;

            Application.Current.Resources.Clear();
            Application.Current.Resources.MergedDictionaries.Add(resourceDict);
        }
Exemplo n.º 15
0
        public CalcViewModel BuildViewModel()
        {
            var clats      = _context.Clats.OrderBy(x => x.From).ThenBy(x => x.To).ToList();
            var properties = _context.CostProperties.ToList();

            var model = new CalcViewModel()
            {
                ClatList           = clats,
                CostPropertiesList = properties
            };

            return(model);
        }
        public ActionResult CalcByStructuralDepartmentName(CalcViewModel model)
        {
            User user = UserManager.FindById(User.Identity.GetUserId());

            InitDepartmentsOnViewBag();
            CalcViewModel resultModel = new CalcViewModel
            {
                DepartmentId = model.DepartmentId,
                PPIViewModel = db.GetPPIViewModelByDepartment(db.GetDepartment(model.DepartmentId))
            };

            return(View(resultModel));
        }
Exemplo n.º 17
0
        public IActionResult Index()
        {
            CalcViewModel model = new CalcViewModel();

            // *
            if (TempData[prgKey] != null)
            {
                model = JsonConvert.DeserializeObject <CalcViewModel>(TempData[prgKey].ToString());
            }

            PopulateDDLs(model);
            return(View(model));
        }
        public ActionResult CalcByPPIName(CalcViewModel model)
        {
            User user = UserManager.FindById(User.Identity.GetUserId());

            ViewBag.PersonalProtectiveItems = new SelectList(db.GetPPIByDepartment(db.GetDepartment(user.DepartmentId)), "Id", "Name");
            CalcViewModel resultModel = new CalcViewModel
            {
                DeparmentsViewModel = db.GetDeparmentsViewModelByDepartmentAndPPIId(db.GetDepartment(user.DepartmentId), model.PPIId),
                DatabaseHelper      = db
            };

            return(View(resultModel));
        }
Exemplo n.º 19
0
        public ActionResult ModelBindingInParameters(String first, String second, String action)
        {
            if (!Int32.TryParse(first, out int number))
            {
                this.ViewBag.FirstError = true;
                return(this.View());
            }

            if (!Int32.TryParse(second, out number))
            {
                this.ViewBag.SecondError = true;
                return(this.View());
            }

            var calc = new Int32();

            if (action.Equals("Add", StringComparison.OrdinalIgnoreCase))
            {
                calc = this.calcService.Add(Convert.ToInt32(first), Convert.ToInt32(second));
            }

            if (action.Equals("Sub", StringComparison.OrdinalIgnoreCase))
            {
                calc = this.calcService.Sub(Convert.ToInt32(first), Convert.ToInt32(second));
            }

            if (action.Equals("Mul", StringComparison.OrdinalIgnoreCase))
            {
                calc = this.calcService.Mul(Convert.ToInt32(first), Convert.ToInt32(second));
            }

            if (action.Equals("Div", StringComparison.OrdinalIgnoreCase))
            {
                if (second.Equals("0", StringComparison.OrdinalIgnoreCase))
                {
                    this.ViewBag.DivisionError = true;
                    return(this.View());
                }
                calc = this.calcService.Div(Convert.ToInt32(first), Convert.ToInt32(second));
            }

            var model = new CalcViewModel()
            {
                First    = first,
                Second   = second,
                Operator = action,
                Result   = calc.ToString()
            };

            return(this.View(model));
        }
        public void ShowsCorrectProcessView(int x, int y, int expectedResult)
        {
            var cc        = new CalcController();
            var calcModel = new CalcViewModel()
            {
                Number1 = x,
                Number2 = y
            };


            var result = cc.Process(calcModel) as ViewResult;

            Assert.Equal(expectedResult, calcModel.Result);
        }
Exemplo n.º 21
0
 public IActionResult Index([Bind("NettoValue,BruttoValue,CalcTypeId")] CalcViewModel calcViewModel)
 {
     if (calcViewModel.CalcTypeId == 0)
     {
         calcViewModel.BruttoValue = calcViewModel.NettoValue * (decimal)1.23;
         calcViewModel.BruttoValue = Tools.decimalRound(calcViewModel.BruttoValue);
     }
     else if (calcViewModel.CalcTypeId == 1)
     {
         calcViewModel.NettoValue = calcViewModel.BruttoValue * 100 / 123;
         calcViewModel.NettoValue = Tools.decimalRound(calcViewModel.NettoValue);
     }
     ViewData["CalcType"] = new SelectList(CalcTypes, "Key", "Value");
     return(RedirectToAction("Index", new { nettoVal = calcViewModel.NettoValue, bruttoVal = calcViewModel.BruttoValue }));
 }
Exemplo n.º 22
0
        public ActionResult ProcessWithService(CalcViewModel model)
        {
            bool isSuccess = ExternalService.DoGreatThings();

            if (isSuccess)
            {
                var cs     = new CalcService();
                var result = cs.AddNumbers(model.Number1, model.Number2);
                model.Result = result;
                return(View(model));
            }
            {
                throw new Exception();
            }
        }
Exemplo n.º 23
0
        public void FirstMock()
        {
            //Calcクラスのモックを作成
            var mock = new Mock <ICalc>();

            //Addメソッドが1と2で呼ばれたら「3」を返す設定
            mock.Setup(m => m.Add(1, 2)).Returns(3);
            //Addメソッドが2と3で呼ばれたら「5」を返す設定
            mock.Setup(m => m.Add(2, 3)).Returns(5);

            CalcViewModel cvm = new CalcViewModel(mock.Object);

            Assert.Equal(3, cvm.DoCalculation(1, 2));

            //モックの振る舞いが呼び出されたかを確認
            //mock.VerifyAll();
        }
Exemplo n.º 24
0
        public IActionResult Index(CalcViewModel model)
        {
            switch (model.Operation)
            {
            case "SUM": model.Result = model.N1 + model.N2;
                break;

            case "SUBTRACT": model.Result = model.N1 - model.N2;
                break;

            case "MULTIPLY": model.Result = model.N1 * model.N2;
                break;

            case "DIVIDE": model.Result = model.N1 / model.N2;
                break;
            }
            return(View(model));
        }
Exemplo n.º 25
0
        public ActionResult Edit(CalcViewModel model)
        {
            model = updateCalcViewModel(model);

            if (ModelState.IsValid)
            {
                var matrixEntity = new Matrix()
                {
                    Id                  = model.Id,
                    BuildingPartId      = model.BuildingPartsId,
                    DefectDescriptionId = model.DefectDescriptionsId,
                    ImportanceId        = model.DefectImportancesId,
                    IntencityId         = model.DefectIntencitiesId,
                    ExtentId            = model.DefectExtentsId,
                    Condition           = model.Condition,
                    ActieId             = model.ActionId,

                    HvhId       = model.Hvh,
                    EenhId      = model.EenhId,
                    Percent     = (model.Percent == 0) ? 1 : (float)0.2,
                    Cost        = model.Cost,
                    Total       = model.Total,
                    BTW         = model.TaxeId,
                    Cycle       = model.Cycle,
                    StartYear   = model.StartYear,
                    UpdatedDate = DateTime.Now
                };

                // update
                _matrixRepository.Update(matrixEntity);

                // back to home page
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 26
0
        public CalcViewModel BuildViewModel(string viewPrice, string viewOwnership)
        {
            var     clats      = _context.Clats.OrderBy(x => x.To).ThenBy(x => x.To).ToList();
            var     properties = _context.CostProperties.ToList();
            decimal price;

            decimal.TryParse(viewPrice, out price);


            var modelView = new CalcView()
            {
                Price         = price,
                OwnershipForm = viewOwnership
            };

            var model = new CalcViewModel()
            {
                ModelCalcView      = modelView,
                ClatList           = clats,
                CostPropertiesList = properties
            };

            return(model);
        }
Exemplo n.º 27
0
        public ActionResult PassUsingModel()
        {
            var a     = this.rngService.Number(-1000, 1001);
            var b     = this.rngService.Number(-1000, 1001);
            var model = new CalcViewModel
            {
                A   = a,
                B   = b,
                Add = this.calcService.Add(a, b),
                Sub = this.calcService.Sub(a, b),
                Mul = this.calcService.Mul(a, b),
            };

            if (b == 0)
            {
                model.Div = "Division by zero";
            }
            else
            {
                model.Div = this.calcService.Div(a, b);
            }

            return(this.View(model));
        }
Exemplo n.º 28
0
 public CalcPage()
 {
     InitializeComponent();
     BindingContext = new CalcViewModel();
 }
Exemplo n.º 29
0
        public ActionResult Index(CalcViewModel model)
        {
            try
            {
                SetUpCurrentUser();
            }
            catch (Exception)
            {
                // Unable to identify user
                model.DataErrorCodes.Add(DataErrorCode.UserIdentificationFailure);
            }

            if (ModelState.IsValid)
            {
                expressionResult = model.Expression;
                // Parse expression, get history, update db
                try
                {
                    expressionResult    = ExpressionParser.ParseString(model.Expression).ToString();
                    model.CalcErrorCode = CalcErrorCode.Success;

                    // If user identified
                    if (!model.DataErrorCodes.Contains(DataErrorCode.UserIdentificationFailure))
                    {
                        // Make changes in entites for current user/expression
                        try
                        {
                            SetUpCurrentExpression(model.Expression);
                            UpdateLink();
                            UpdateDatabase();
                        }
                        catch (Exception)
                        {
                            // Failure while performing db update
                            model.DataErrorCodes.Add(DataErrorCode.DatabaseUpdateFailure);
                        }
                    }
                }
                catch (DivideByZeroException)
                {
                    model.CalcErrorCode = CalcErrorCode.DivideByZero;
                }

                catch (Exception)
                {
                    // Failure while calculating
                    model.CalcErrorCode = CalcErrorCode.ParseFailure;
                }

                model.Expression = expressionResult;
            }
            else
            {
                // Model not valid
                model.CalcErrorCode = CalcErrorCode.InvalidModel;
            }

            try
            {
                // Try to get expressions history for user
                model.Expressions = GetTodayExpressionsHistoryForUser(currentUser);
            }
            catch (Exception)
            {
                // Unable to get history, setting up empty history
                model.DataErrorCodes.Add(DataErrorCode.GettingHistoryFailure);
            }

            return(View(model: model));
        }
Exemplo n.º 30
0
 public void SetUp()
 {
     _math = new MathOperations();
     _cvm = new CalcViewModel();
 }
Exemplo n.º 31
0
 public void Setup()
 {
     _viewModel = new CalcViewModel();
 }