コード例 #1
0
        public async Task <IEnumerable <LicenceItem> > getLicencesAsync(string user)
        {
            var item1 = new LicenceItem()
            {
                Id        = Guid.NewGuid(),
                User      = "******",
                Key       = "123",
                ExpiresOn = DateTimeOffset.Now.AddDays(50)
            };

            var item2 = new LicenceItem()
            {
                Id        = Guid.NewGuid(),
                User      = "******",
                Key       = "abc",
                ExpiresOn = DateTimeOffset.Now.AddDays(60)
            };

            IEnumerable <LicenceItem> list = new List <LicenceItem>()
            {
                item1, item2
            };

            return(await Task.FromResult(list));
        }
コード例 #2
0
 public async Task <bool> addLicenceItemAsync(LicenceItem licenceItem, string user)
 {
     licenceItem.Id        = Guid.NewGuid();
     licenceItem.ExpiresOn = DateTimeOffset.Now.AddDays(365);
     licenceItem.AdminUser = user;
     _context.LicenceItems.Add(licenceItem);
     return(await _context.SaveChangesAsync() == 1);
 }
コード例 #3
0
        public async Task <IActionResult> AddLicenceItem(LicenceItem licenceItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var success = await _licenceService.addLicenceItemAsync(licenceItem, currentUser.UserName);

            if (!success)
            {
                return(BadRequest("Item could not be added!"));
            }
            return(RedirectToAction("Index"));
        }
コード例 #4
0
 public async Task <bool> addLicenceItemAsync(LicenceItem licenceItem, string user)
 {
     return(await Task.FromResult <bool>(true));
 }