Exemplo n.º 1
0
        public ActionResult MakeOperation([FromForm] string input)
        {
            double     newResult = 0;
            Operations operation = new Operations();

            if (input != null)
            {
                newResult = operation.Addition(input);
            }

            Convert.ToDecimal(newResult);


            _context.Operations.Add(new Operations {
                Result = newResult
            });

            _context.SaveChanges();

            var AllResults = _context.Operations.ToList();


            IndexViewModel passResults = new IndexViewModel
            {
                AllResults = (AllResults),
                NewResult  = newResult
            };



            if (_context.Operations.ToList().Capacity > 5)
            {
                var rows = from o in _context.Operations
                           select o;
                foreach (var row in rows)
                {
                    _context.Operations.Remove(row);
                }
                _context.SaveChanges();
            }

            return(View("resView", passResults));
        }
 public void Delete(int id)
 {
     using (var ctx = new CalculatorDbContext())
     {
         var calculatorItem = ctx.ContentsCalculatorItems.FirstOrDefault(x => x.Id == id);
         if (calculatorItem != null)
         {
             ctx.ContentsCalculatorItems.Remove(calculatorItem);
             ctx.SaveChanges();
         }
     }
 }
        public void Update(int id, string name, double value, string category)
        {
            using (var ctx = new CalculatorDbContext())
            {
                var categoryType = ctx.ContentsCategoryTypes.FirstOrDefault(x => x.Name == category);
                if (categoryType != null)
                {
                    var contentsCalculatorItem = ctx.ContentsCalculatorItems.FirstOrDefault(x => x.Id == id);

                    if (contentsCalculatorItem != null)
                    {
                        contentsCalculatorItem.Name  = name;
                        contentsCalculatorItem.Value = value;
                        contentsCalculatorItem.ContentsCategoryTypeId = categoryType.Id;

                        ctx.SaveChanges();
                    }
                }
            }
        }
        public int?Create(string name, double value, string category)
        {
            using (var ctx = new CalculatorDbContext())
            {
                var categoryType = ctx.ContentsCategoryTypes.FirstOrDefault(x => x.Name == category);
                if (categoryType != null)
                {
                    var contentsCalculatorItem = new ContentsCalculatorItem
                    {
                        Name = name, ContentsCategoryTypeId = categoryType.Id, Value = value
                    };

                    ctx.ContentsCalculatorItems.Add(contentsCalculatorItem);
                    ctx.SaveChanges();

                    return(contentsCalculatorItem.Id);
                }

                return(null);
            }
        }