Beispiel #1
0
        public override void AddNewSystem(CreateExternalSystemRequestDto request)
        {
            if (_context.Systems
                .AsNoTracking()
                .Any(x => x.ExternalId == request.ExternalId || x.Name == request.Name))
            {
                throw new SystemExistsException($"System '{request.ExternalId}' already exists.", request.ExternalId, request.Name);
            }

            base.AddNewSystem(request);
        }
Beispiel #2
0
 public override void AddNewSystem(CreateExternalSystemRequestDto request)
 {
     try
     {
         base.AddNewSystem(request);
     }
     catch (Exception ex)
     {
         _log.LogError(ex.Message, ex);
         throw;
     }
 }
Beispiel #3
0
 public virtual void AddNewSystem(CreateExternalSystemRequestDto request)
 {
     _inner.AddNewSystem(request);
 }
 public void AddExternalSystem([FromBody] CreateExternalSystemRequestDto request)
 {
     _systemBusiness.AddNewSystem(request);
 }
        public void AddNewSystem(CreateExternalSystemRequestDto request)
        {
            var newExternalSystem = new ExternalSystem(request.Name, request.ExternalId, request.CallbackUrl);

            //Add users
            var lowestLevel = newExternalSystem.Levels
                              .OrderBy(x => x.XpThreshold)
                              .FirstOrDefault();

            if (lowestLevel == null)
            {
                var newDefaultLevel = new Level("Default level", 0);

                newExternalSystem.Levels.Add(newDefaultLevel);
            }

            foreach (var user in request.Users)
            {
                var newUser = new User(user.Username, user.ExternalId);
                newUser.SetLevel(lowestLevel);
                newExternalSystem.AddUser(newUser);
            }

            //Add pages
            foreach (var page in request.Pages)
            {
                var newPage    = new ContentPage(page.Title);
                var newEdition = new Edition(page.Contents, page.AwardedXp, "Initial");
                newPage.AddEdition(newEdition);

                //Add categories
                foreach (var category in page.Categories)
                {
                    var existingCategory = newExternalSystem.Categories.FirstOrDefault(x => x.Name == category.Name);
                    var badge            = category.Badge != null
                        ? newExternalSystem.Badges.FirstOrDefault(x => x.Name == category.Badge.Name)
                        : null;

                    if (existingCategory == null)
                    {
                        var newCategory = new Category(category.Name);

                        if (badge == null && category.Badge != null)
                        {
                            badge = new Badge(category.Badge.Name, category.Badge.Description, category.Badge.SymbolUrl, category.Badge.AwardedXp);
                        }
                        newCategory.SetBadge(badge);
                        newPage.AddCategory(newCategory);
                    }
                    else
                    {
                        newPage.AddCategory(existingCategory);
                    }
                }

                newExternalSystem.AddPage(newPage);
            }

            _context.Systems.Add(newExternalSystem);
            _context.SaveChanges();
        }