示例#1
0
        public async Task <ActionResult> Post(ElementPostDto elementDto)
        {
            var user = await _userRepository.GetById(AuthUserId);

            if (user == null)
            {
                return(Unauthorized());
            }

            var toDoList = await _listRepository.GetById(elementDto.ToDoListId);

            if (toDoList == null)
            {
                return(BadRequest());
            }

            if (toDoList.UserId != user.Id)
            {
                return(Forbid());
            }

            var id      = Guid.NewGuid();
            var addedAt = DateTime.UtcNow;
            var element = new ToDoElement(id, toDoList.Id, elementDto.Title, addedAt);
            await _elementRepository.Add(element);

            return(CreatedAtRoute("GetElement", new { id = id }, element));
        }
示例#2
0
        public bool Add(Element element)
        {
            var r = inner.Add(element);

            if (r)
            {
                AddCache(element);
            }
            return(r);
        }
        /// <summary>
        /// Adds the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns><c>true</c> if success, <c>false</c> otherwise.</returns>
        public bool Add(Element element)
        {
            var r = _innerRepository.Add(element);

            if (r)
            {
                AddCache(element);
            }
            return(r);
        }
        public async Task <IActionResult> OnPostAsync(Element element)
        {
            await OnGetAsync();

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _elementRepository.Add(element);

            Message = $"Added: {element.Description}";
            return(RedirectToPage());
        }
        public IEnumerable <Guid> FindElements(Session session, string locator, string value, Guid?elementId)
        {
            var container = elementId.HasValue
                ? GetUIAutomationElement(elementId.Value)
                : _automation.ElementFromHandle(session.Process.MainWindowHandle);

            var conditions = new List <IUIAutomationCondition>();

            switch (locator.ToLowerInvariant())
            {
            case "name":
                conditions.Add(_automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ValueValuePropertyId, value));
                conditions.Add(_automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, value));
                break;

            case "tag name":
                conditions.Add(_automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, MapControlType(value)));
                break;

            case "id":
                conditions.Add(_automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, value));
                break;

            default:
                throw new VariableResourceNotFoundException();     // TODO: should this be method not supported?
            }

            var allElementIds = new List <Guid>();
            var condition     = _automation.CreateOrConditionFromArray(conditions.ToArray());
            var results       = container.FindAll(TreeScope.TreeScope_Descendants, condition);

            if (results != null)
            {
                for (int i = 0; i < results.Length; i++)
                {
                    var element = results.GetElement(i);
                    var id      = elementId.HasValue && locator == "tag name" && value == "option"
                        ? _elementRepository.Add(new ListItemElement(_elementRepository.GetById(elementId.Value), i))
                        : _elementRepository.AddByHandle(element.CurrentNativeWindowHandle.ToInt32());
                    allElementIds.Add(id);
                }
            }

            if (allElementIds.Any())
            {
                return(allElementIds);
            }

            throw new VariableResourceNotFoundException();
        }
示例#6
0
        /// <summary>
        /// Get elements of this instance.
        /// </summary>
        /// <returns>IQueryable{Element}.</returns>
        public IQueryable <Element> Elements()
        {
            if (!_cacheRepository.Elements().Any())
            {
                using (var _repository = _repositoryFactory.GetRepositoryInstance())
                {
                    // limit languages by Language setting;
                    var languageSetting = _repository.Settings.Where(s => s.Name.Contains("Lang"))
                                          .Expand(s => s.SettingValues)
                                          .FirstOrDefault();

                    // the expression is: (x=>x.LanguageCode == "en-US" || x.LanguageCode == "ja-JP" || ....)
                    var             parameter = linq.Expression.Parameter(typeof(Localization), "x");
                    linq.Expression condition = linq.Expression.Constant(false);
                    foreach (var name in languageSetting.SettingValues)
                    {
                        condition = linq.Expression.OrElse(
                            condition,
                            linq.Expression.Equal(
                                linq.Expression.Property(parameter, "LanguageCode"),
                                linq.Expression.Constant(name.ShortTextValue)));
                    }

                    var expression = linq.Expression.Lambda <Func <Localization, bool> >(condition, parameter);

                    var query = GetLocalizationsEnumerable(_repository).Where(expression);
                    foreach (var loc in query)
                    {
                        //Update cache with items
                        _cacheRepository.Add(GetElement(loc));
                    }
                }
            }

            return(_cacheRepository.Elements());
        }