Exemple #1
0
        internal void Edit(RecipeEditViewModel model)
        {
            var userService   = new UserService(_context, _httpContext);
            var cleranceLevel = userService.GetCurrentUserCleranceLevel();

            var recipe = GetById(model.Id);

            if (cleranceLevel.Level < recipe.ClassificationLevel.Level)
            {
                return;
            }

            var controlLevelService   = new ControlLevelService(_context);
            var classificationLevelId = controlLevelService.GetIdByLevel(model.ClassificationLevel);

            var authorId = userService.GetCurrentUserId();

            recipe.Id   = model.Id;
            recipe.Name = model.Name;
            recipe.Text = model.Text;
            recipe.ClassificationLevelId = classificationLevelId;
            recipe.AuthorId = authorId;

            _context.Entry(recipe).State = EntityState.Modified;
        }
        public ICollection <ControlLevel> GetAvailableClassificationLevels()
        {
            var clearanceLevel      = GetCurrentUserCleranceLevel();
            var controlLevelService = new ControlLevelService(_context);

            return(controlLevelService.GetWriteableFor(clearanceLevel));
        }
        public ICollection <ApplicationUser> GetAvailableUsers()
        {
            var cleranceLevel = GetCurrentUserCleranceLevel();

            var controlLevelService = new ControlLevelService(_context);
            var controlLevelsIds    = controlLevelService.GetReadableFor(cleranceLevel).Select(x => x.Id);

            var users = _context.Users
                        .Include(x => x.UserInfo.CleranceLevel)
                        .Where(x => controlLevelsIds.Contains(x.UserInfo.CleranceLevel.Id))
                        .ToList();

            return(users);
        }
        public async Task <IdentityResult> Add(UserCreateViewModel model)
        {
            var controlLevelService = new ControlLevelService(_context);
            var cleranceLevelId     = controlLevelService.GetIdByLevel(model.CleranceLevel);
            var userInfo            = new User {
                Name = model.Username, Email = model.Email, CleranceLevelId = cleranceLevelId
            };
            var user = new ApplicationUser {
                UserName = model.Username, Email = model.Email, UserInfo = userInfo
            };

            var userManager = _httpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();

            return(await userManager.CreateAsync(user, model.Password));
        }
Exemple #5
0
        public void Add(RecipeCreateViewModel model)
        {
            var controlLevelService   = new ControlLevelService(_context);
            var classificationLevelId = controlLevelService.GetIdByLevel(model.ClassificationLevel);

            var userService = new UserService(_context, _httpContext);
            var authorId    = userService.GetCurrentUserId();

            var recipe = new Recipe
            {
                Name = model.Name,
                Text = model.Text,
                ClassificationLevelId = classificationLevelId,
                AuthorId = authorId
            };

            _context.Recipes.Add(recipe);
        }