public IActionResult Put([FromBody] ControlledEntry item)
        {
            _logger.LogDebug("GET api/ControlledEntry/Put");
            IActionResult ret = null;

            if (item == null)
            {
                ret = BadRequest();
            }

            else
            {
                var updatedId = _iRepo.Update(item.id, item);

                if (updatedId == 0)
                {
                    ret = NotFound();
                }
                else
                {
                    ret = new ObjectResult(updatedId);
                }
            }
            _logger.LogDebug("GET api/ControlledEntry/put returned : {0}", ret);
            return(ret);
        }
Пример #2
0
        public void Initialize(MyAppContext context)
        {
            context.Database.EnsureCreated();

            // Check for Data
            if (context.ControlledEntries.Any())
            {
                _logger.LogWarning(string.Format("{0} : DataBase already seeded", System.Reflection.MethodBase.GetCurrentMethod()));
                return;   // DB has been seeded
            }

            _logger.LogInformation(string.Format("{0} : Preparing to seed database", System.Reflection.MethodBase.GetCurrentMethod()));

            var ControlledEntries = new ControlledEntry[]
            {
                new ControlledEntry {
                    name = "My Building Gate", description = "Access to my building gate", lastModified = DateTime.Now
                },
                new ControlledEntry {
                    name = "My Building", description = "Access to my building", lastModified = DateTime.Now
                },
                new ControlledEntry {
                    name = "My Door", description = "Access to my door", lastModified = DateTime.Now
                },
                new ControlledEntry {
                    name = "My Room", description = "Access to my room", lastModified = DateTime.Now
                },
            };

            foreach (ControlledEntry seed in ControlledEntries)
            {
                context.ControlledEntries.Add(seed);
            }

            //var computers = new Computer[]
            //{
            //new Computer{ ConfiguracionName = "The Basic", HardDrive = "512GB HDD", Memory = Memories[0], Processor = "AMD", LastModified=DateTime.Now},
            //new Computer{ ConfiguracionName = "The Internet", HardDrive = "128GB SDD", Memory = Memories[1], Processor = "Intel i3", LastModified=DateTime.Now},
            //new Computer{ ConfiguracionName = "The Gamer", HardDrive = "1TB HDD", Memory = Memories[2], Processor = "Intel i5", LastModified=DateTime.Now},
            //new Computer{ ConfiguracionName = "The Beast", HardDrive = "512GB SDD", Memory = Memories[3], Processor = "Intel i7", LastModified=DateTime.Now}
            //};
            //foreach (Computer c in computers)
            //{
            //    context.Computers.Add(c);
            //}

            try
            {
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} : DataBase seeding error", System.Reflection.MethodBase.GetCurrentMethod()), ex);
            }

            _logger.LogInformation(string.Format("{0} : Seeded Database with {1} {2}", System.Reflection.MethodBase.GetCurrentMethod(), ControlledEntries.Count(), "ControlledEntries"));
            _logger.LogInformation(string.Format("{0} : DataBase Initializing Complete", System.Reflection.MethodBase.GetCurrentMethod()));
        }
        public IActionResult Post([FromBody] ControlledEntry item)
        {
            _logger.LogDebug("GET api/ControlledEntry/post");
            IActionResult ret = null;

            if (item == null)
            {
                ret = BadRequest();
            }
            else
            {
                var id = _iRepo.Add(item);
                ret = CreatedAtRoute("GetControlledEntry", new { id = item.id }, item);
            }

            _logger.LogDebug("GET api/ControlledEntry/post returned : {0}", ret);
            return(ret);
        }