Esempio n. 1
0
        //
        // POST: /Labs/Lab4
        public ActionResult Lab4()
        {
            Lab4DataAccess dataAccess = new Lab4DataAccess(RavenSession);
            PrintingCalculator item = dataAccess.RetrieveFromSession();
            Lab4ViewModel model = new Lab4ViewModel();

            if(item != null)
            {
                model.InjectFrom(item);
            }

            return View("Lab4", model);
        }
Esempio n. 2
0
        public ActionResult Lab4(string add, string subtract, string multiply, string divide, string clearmemory, string execute, Lab4ViewModel model)
        {
            int value = 0;
            Lab4DataAccess dataAccess = new Lab4DataAccess(RavenSession);
            PrintingCalculator item = dataAccess.RetrieveFromSession();

            if(!string.IsNullOrEmpty(model.CalculatedValue) && int.TryParse(model.CalculatedValue, out value))
            {
                if(!string.IsNullOrEmpty(add))
                {
                    item.Add(value);
                }
                else if(!string.IsNullOrEmpty(subtract))
                {
                    item.Subtract(value);
                }
                else if(!string.IsNullOrEmpty(multiply))
                {
                    item.Multiply(value);
                }
                else if(!string.IsNullOrEmpty(divide))
                {
                    item.Divide(value);
                }

                //Save to store
                RavenSession.Store(item);
                RavenSession.SaveChanges();

                //Map changes to model
                model.InjectFrom(item);

                ModelState.Remove("CalculatedValue");
                model.CalculatedValue = string.Empty;
            }
            else
            {
                if(!string.IsNullOrEmpty(clearmemory))
                {
                    ModelState.Clear();
                    ModelState.Remove("CalculatedValue");
                    model.CalculatedValue = string.Empty;

                    dataAccess.ClearFromSession();

                    //Clear Model
                    model = new Lab4ViewModel();
                }
                else if(!string.IsNullOrEmpty(execute))
                {
                    ModelState.Clear();
                    ModelState.Remove("CalculatedValue");
                    model.CalculatedValue = string.Empty;
                }
                else
                {
                    //Map changes to model
                    model.InjectFrom(item);
                }
            }

            return View("Lab4", model);
        }