示例#1
0
        static void Main(string[] args)
        {
            // Container registration
            var container = new Container();

            container.Register <IStampantiRepository, StampantiDbRepository>();
            container.Register <IConfigurationService, ConfigurationService>();
            container.Verify();

            //string _connectionString = ConfigurationManager.ConnectionStrings["dbStampanti"].ConnectionString;
            var stampante1 = new Stampante();

            stampante1.Nome = "DadPrinter";
            stampante1.IP   = "3.3.33.3";
            stampante1.Port = 9100;
            stampante1.Id   = 8;
            var stampantiRepository = container.GetInstance <IStampantiRepository>();

            try
            {
                stampantiRepository.UpdateStampante(stampante1);
                ElencoStampanti(stampantiRepository);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.Read();
        }
 public void UpdateStampante(Stampante x)
 {
     try
     {
         using (var connection = new SqlConnection(_connectionString))
         {
             connection.Update(x);
         }
     }
     catch (Exception e)
     {
         throw new Exception("Errore nell'Update", e);
     }
 }
示例#3
0
        public void UpdateStampante(Stampante x)
        {
            var printer = GetStampanteById(x.Id);


            if (printer != null)
            {
                printer.Nome = x.Nome;
                printer.IP   = x.IP;
                printer.Port = x.Port;

                SaveStampanti();
            }
        }
 public void AddStampante(Stampante stampante)
 {
     try
     {
         using (var connection = new SqlConnection(_connectionString))
         {
             connection.Insert <Stampante>(stampante);
         }
         ReadStampanti();
     }
     catch (Exception e)
     {
         throw new Exception("Errore nell'Add", e);
     }
 }
示例#5
0
        public void AddStampante(Stampante stampante)
        {
            var printer = GetStampanteByNome(stampante.Nome);

            if (printer == null)
            {
                var ids = (from s in _stampanti
                           select s.Id).ToList();

                var nextID = ids.Any() ? ids.Max() + 1 : 1;
                stampante.Id = nextID;

                _stampanti.Add(stampante);
                SaveStampanti();
            }
        }
示例#6
0
        public ActionResult Update(Stampante printer)
        {
            var validator = new StampantiValidator();

            ValidationResult result = validator.Validate(printer);

            if (result.IsValid)
            {
                _stampantiRepository.UpdateStampante(printer);

                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (ValidationFailure failer in result.Errors)
                {
                    ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage);
                }
            }
            return(View(printer));
        }
示例#7
0
        public ActionResult Create(Stampante model)
        {
            var validator = new StampantiValidator();

            ValidationResult result = validator.Validate(model);

            if (result.IsValid)
            {
                _stampantiRepository.AddStampante(model);

                string message = "Stampante aggiunta con successo";
                ViewBag.Message = message;
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (ValidationFailure failer in result.Errors)
                {
                    ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage);
                }
            }
            return(View(model));
        }