/// <summary> /// Starts the execution of a Connector based on the parameters /// </summary> /// <param name="sdk"></param> /// <param name="request"></param> /// <returns></returns> public static async Task <Item> CreateItem(PluggyAPI sdk, ItemParameters request) { try { return(await sdk.CreateItem(request)); } catch (ValidationException e) { Console.WriteLine("Execution not started, reason {0} ", e.Message); if (e.ApiError.Errors != null && e.ApiError.Errors.Count > 0) { foreach (var error in e.ApiError.Errors) { Console.WriteLine("[X] {0} ", error.Message); } } Console.ReadLine(); return(null); } catch (ApiException e) { Console.WriteLine("There was an issue starting the execution"); Console.WriteLine(e.Message); Console.ReadLine(); return(null); } }
//----------------------CONSTRUCTORS------------------------- private InstalledItem() { itemParameters = new ItemParameters(); neighbourTypes = new List <string>(); //updateActions = new List<Action>(); }
/* * Execution Helpers */ /// <summary> /// Creates a new item for a connector and starts reviewing the status until completition /// </summary> /// <param name="request">The item parameters</param> /// <returns>an object with the info to retrieve the data when the execution is ready</returns> public async Task <Item> ExecuteAndWait(ItemParameters request) { try { Item item = await CreateItem(request); do { await Task.Delay(STATUS_POLL_INTERVAL); item = await FetchItem(item.Id); }while (!item.HasFinished()); return(item); } catch (ApiException e) { if (e.ApiError != null && e.ApiError.Errors != null) { throw new ValidationException(e.StatusCode, e.ApiError); } throw e; } }
public async Task <int> CountItems(ItemParameters parameters) { return(await _context.Items.CountAsync(x => (x.Name.Contains(parameters.Name) || string.IsNullOrWhiteSpace(parameters.Name)) && x.Price <= parameters.MaxPrice && x.Price >= parameters.MinPrice)); }
public async Task <PagedList <ItemDTO> > GetItemPagesFiltered(ItemParameters parameters) { var x = await _uow.Items.GetAllPagesFiltered(parameters); var list = _mapper.Map <PagedList <ItemDTO> >(x); return(list); }
public async Task <IEnumerable <Item> > GetAllItemsPaginationAsync(ItemParameters itemParams) { var res = await GetAllAsync(); return(PagedList <Item> .ToPagedList(res, itemParams.PageNumber, itemParams.PageSize)); }
public async Task <PagedList <Item> > GetAllPagesFiltered(ItemParameters parameters) { var items = FindByCondition(x => x.Price >= parameters.MinPrice && x.Price <= parameters.MaxPrice); SearchByName(ref items, parameters.Name); items = _sortHelper.ApplySort(items, parameters); return(await PagedList <Item> .ToPagedList(items, parameters.PageNumber, parameters.PageSize)); }
public async Task <int> CountItems(ItemParameters parameters) { if (parameters.Name != null) { parameters.Name = parameters.Name.Trim().ToLower(); } return(await _uow.Items.CountItems(parameters)); }
void ToJson() { int[] tmpArray = { 12, 45, 7, 15 }; ItemParameters itemParameters = new ItemParameters(2, 3, tmpArray); Item item = new Item("John", 20, itemParameters); outputJSON = JsonUtility.ToJson(item, true); }
public async Task <PagedList <Item> > GetAllItemsAsync(ItemParameters itemParameters, bool trackChanges) { var items = await FindByCondition(e => e.AvailableItems != 0, trackChanges) .OrderBy(e => e.Name) .ToListAsync(); return(PagedList <Item> .ToPagedList(items, itemParameters.PageNumber, itemParameters.PageSize)); }
public bool TryLoad(ref ItemParameters itemParameters) { if (IsRegistrated(ref itemParameters)) { itemParameters.pickedup = true; return(true); } return(false); }
private InstalledItem(World world, InstalledItem proto, bool spawn) { //this.updateActions = new List<Action>(); //this.jobs = new List<Job>(); //this.prototypeId = proto.prototypeId; this.type = proto.type; // nice field name, doofus. this.niceName = proto.niceName; this.movementFactor = proto.movementFactor; this.width = proto.width; this.height = proto.height; this.linksToNeighbour = proto.linksToNeighbour; this.spriteName = proto.spriteName; this.setLinkedSpriteNames(proto); this.build = proto.build; this.trash = proto.trash; this.prototype = proto; this.randomRotation = proto.randomRotation; this.roomEnclosure = proto.roomEnclosure; this.recipeName = proto.recipeName; if (proto.updateActions != null) { this.updateActions = proto.updateActions; } this.itemParameters = new ItemParameters(proto.itemParameters);//.GetItems(); this.enterRequestedFunc = proto.enterRequestedFunc; this.neighbourTypes = proto.neighbourTypes; this.inventory = new Inventory(world, proto.inventorySlots, INVENTORY_TYPE.INSTALLED_ITEM, this); this.workTileOffset = new Vector2(proto.workTileOffset.x, proto.workTileOffset.y); //set the countdown timer this.updateActionCountDownMax = proto.updateActionCountDownMax; this.updateActionCountDownRange = proto.updateActionCountDownRange; this.updateActionCountDown = proto.updateActionCountDownMax; this.workRecipeName = proto.workRecipeName; this.isWorkstation = proto.isWorkstation; this.canSpawnOnTileTypeList = proto.canSpawnOnTileTypeList; this.growthStages = proto.growthStages; this.growthStage = proto.growthStage; this.deconRecipeName = proto.deconRecipeName; this.xClearance = proto.xClearance; this.yClearance = proto.yClearance; this.luaOnCreate = proto.luaOnCreate; this.workCondition = proto.workCondition; this.editOnClick = proto.editOnClick; this.availableRecipes = proto.availableRecipes; this.nextWorkRecipeName = this.workRecipeName; this.onRemoved = proto.onRemoved; this.canChangeRecipe = proto.canChangeRecipe; this.active = false; this.powerGenerated = proto.powerGenerated; this.powerUsed = proto.powerUsed; if (spawn && this.growthStages.Count > 0) { this.growthStage = UnityEngine.Random.Range(0, itemParameters.GetInt("maxGrowthStage")); } }
public async Task <IActionResult> GetAllItemsPagination([FromQuery] ItemParameters itemParams) { var query = new GetAllItemsPagiantionQuery(itemParams); var result = await _meadiator.Send(query); return(Ok(result)); //var res = await _itemService.GetAllItemsPaginationAsync(itemParams); //var resDTO = _mapper.Map<IEnumerable<ItemDTO>>(res); //return Ok(resDTO); }
public PagedList <Item> GetItems(ItemParameters itemParameters) { //return Get() //.OrderBy(on => on.Descricao) //.Skip((itemParameters.PageNumber -1) * itemParameters.PageSize) //.Take(itemParameters.PageSize) //.ToList(); return(PagedList <Item> .ToPagedList(Get().OrderBy(i => i.Descricao), itemParameters.PageNumber, itemParameters.PageSize)); }
public async Task <IActionResult> GetAll([FromQuery] ItemParameters itemParameters) { GetItemsQuery query = new GetItemsQuery(itemParameters); (int, IEnumerable <ItemsResponse>)queryResult = await _mediator.Send(query); int totalCount = queryResult.Item1; IEnumerable <ItemsListResponse> items = _mapper.Map <IEnumerable <ItemsListResponse> >(queryResult.Item2); return(Ok(new { totalCount, items })); }
public async Task <IActionResult> GetItems([FromQuery] ItemParameters itemParameters) { var items = await _context.Items.GetAllItemsAsync(itemParameters, trackChanges : false); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(items.MetaData)); var itemsDto = _mapper.Map <IEnumerable <ItemDto> >(items); return(Ok(itemsDto)); }
public bool IsRegistrated(ref ItemParameters itemParameters) { for (int i = 0; i < itemsRegister.Count; i++) { if (itemsRegister[i] == itemParameters) { return(true); } } return(false); }
public async Task <PagedList <Item> > GetItemsByCategoryId(int categoryId, ItemParameters itemParameters) { IQueryable <Item> items = _itemRepositoryObject.Table.Where(i => i.CategoryId == categoryId) .Include(i => i.Category) .Include(i => i.Condition) .Include(i => i.Location) .Include(i => i.Seller); SearchByName(ref items, itemParameters.Name); return(await PagedList <Item> .ToPagedList(items, itemParameters.PageNumber, itemParameters.PageSize)); }
public async Task <List <ItemViewModel> > GetItems(ItemParameters parameters) { var response = await _httpClient.GetAsync($"api/item?PageSize={parameters.PageSize}&PageNumber={parameters.PageNumber}&MinPrice={parameters.MinPrice}&Name={parameters.Name}&MaxPrice={parameters.MaxPrice}&OrderBy={parameters.OrderBy}"); if (!response.IsSuccessStatusCode) { return(null); } using var responseContent = await response.Content.ReadAsStreamAsync(); return(await JsonSerializer.DeserializeAsync <List <ItemViewModel> >(responseContent)); }
public async Task <int> CountItems(ItemParameters parameters) { var response = await _httpClient.GetAsync($"api/item/count?minprice={parameters.MinPrice}&MaxPrice={parameters.MaxPrice}"); if (!response.IsSuccessStatusCode) { return(0); } else { return(Int32.Parse(await response.Content.ReadAsStringAsync())); } }
/// <summary> /// Creates a new item for an specific connector /// </summary> /// <param name="request">The item parameters</param> /// <returns>an object with the info to retrieve the data when the execution is ready</returns> public async Task <Item> CreateItem(ItemParameters request) { try { return(await httpService.PostAsync <Item>(URL_ITEMS, request.ToBody())); } catch (ApiException e) { if (e.ApiError != null && e.ApiError.Errors != null) { throw new ValidationException(e.StatusCode, e.ApiError); } throw e; } }
/// <summary> /// Update an item connection with/without credentials forcing a sync /// </summary> /// <param name="id">Item id</param> /// <returns>An item object with the status of the connection</returns> public async Task <Item> UpdateItem(Guid id, ItemParameters request) { try { return(await httpService.PatchAsync <Item>(URL_ITEMS + "/{id}", request.ToBody(), null, HTTP.Utils.GetSegment(id.ToString()))); } catch (ApiException e) { if (e.ApiError != null && e.ApiError.Errors != null) { throw new ValidationException(e.StatusCode, e.ApiError); } throw e; } }
public void ItemControllerGetAllItemsMethodTest() { //Arrange var param = new ItemParameters(); var itemRepository = new Mock <IItemRepository>(); itemRepository.Setup(repo => repo.GetAllItemsAsync(param, false)).Returns(getList()); var mockManager = new Mock <IRepositoryManager>(); mockManager.Setup(manager => manager.Items).Returns(itemRepository.Object); ItemController controller = new ItemController(mockManager.Object, null, null); //Act var list = controller.GetItems(param).Result; //Assert Assert.AreEqual(list, getList()); }
public void Item_Index_View_Contains_List_Of_Items_Model() { // Arrange Mock <IItemService> mockItemService = new Mock <IItemService>(); Mock <IEmployeeService> mockEmployeeService = new Mock <IEmployeeService>(); Mock <IItemParameters> mockitemParameters = new Mock <IItemParameters>(); Mock <IEmployeeParameters> mockEmployeeParameters = new Mock <IEmployeeParameters>(); IItemParameters parameters = new ItemParameters { PageSize = 5, PageNumber = 1 }; IEmployeeParameters employeeParameters = new EmployeeParameters(); int count = 3; List <IItem> itemList = new List <IItem> { new Item { ID = Guid.NewGuid(), Name = "Hammer", Description = "Green", SerialNumber = "111", EmployeeID = null }, new Item { ID = Guid.NewGuid(), Name = "Hammer", Description = "Black", SerialNumber = "222", EmployeeID = null }, new Item { ID = Guid.NewGuid(), Name = "Phone", Description = "Samsung", SerialNumber = "333", EmployeeID = null } }; mockItemService.Setup(m => m.GetAllPagedListAsync(parameters)).ReturnsAsync(new StaticPagedList <IItem>(itemList, parameters.PageNumber.Value, parameters.PageSize.Value, count)); ItemController controller = new ItemController(mockItemService.Object, mockEmployeeService.Object, mockitemParameters.Object, mockEmployeeParameters.Object); Mapper.Initialize(cfg => { cfg.CreateMap <IItem, ItemIndexViewModel>(); }); // Act var actual = (StaticPagedList <IItem>)controller.Index(null, null, null, null).Result.Model; // Assert Assert.IsInstanceOf <StaticPagedList <IItem> >(actual); }
public void Item_GetAllPagedList_Returns_PagedList() { // Arrange Mock <IItemRepository> mockItemRepository = new Mock <IItemRepository>(); IItemParameters parameters = new ItemParameters() { PageSize = 5, PageNumber = 1 }; IEnumerable <Item> itemList = new List <Item> { new Item { ID = Guid.NewGuid(), Name = "Hammer", Description = "Green", SerialNumber = "111", EmployeeID = Guid.NewGuid() }, new Item { ID = Guid.NewGuid(), Name = "Hammer", Description = "Black", SerialNumber = "222", EmployeeID = Guid.NewGuid() }, new Item { ID = Guid.NewGuid(), Name = "Phone", Description = "Samsung", SerialNumber = "333", EmployeeID = Guid.NewGuid() } }; mockItemRepository.Setup(m => m.GetAllAsync(parameters)).ReturnsAsync(itemList); ItemService service = new ItemService(mockItemRepository.Object); Mapper.Initialize(cfg => { cfg.CreateMap <EmployeeEntity, IEmployee>().ReverseMap(); cfg.CreateMap <ItemEntity, IItem>().ReverseMap(); }); // Act var actual = service.GetAllPagedListAsync(parameters).Result; // Assert Assert.IsInstanceOf <StaticPagedList <IItem> >(actual); }
public ActionResult <IEnumerable <ItemDTO> > Get([FromQuery] ItemParameters itemParameters) { var items = _context.ItemRepository.GetItems(itemParameters); var metadata = new { items.TotalCount, items.PageSize, items.CurrentPage, items.TotalPages, items.HasNext, items.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); var itemsDto = _mapper.Map <List <ItemDTO> >(items); return(itemsDto); }
private Entity(Tile tile, Entity proto) { inventory = new Inventory(World.current, 1, INVENTORY_TYPE.ENTITY, this); this.getNameType = proto.getNameType; switch (proto.getNameType) { case "pet": name = World.current.GetPetName(); break; case "robot": name = World.current.GetRobotName(); break; default: name = World.current.GetName(); break; } info = new ItemParameters(proto.info); this.typeName = proto.typeName; this.spriteName = proto.spriteName; this.animations = proto.animations; this.proto = proto; this.SetPos(tile); this.SetDst(tile); //this.occupier = new TileOccupant(name, proto.typeName); //this.occupier.CBPleaseMove += PleaseMove; this.facingSprites = proto.facingSprites; this.OnUpdate = proto.OnUpdate; this.animator = new NYDIAnimator(proto.animations); }
public async Task <IActionResult> Get([FromQuery] ItemParameters parameters) { if (!parameters.ValidPriceRange) { return(BadRequest("bahama mama")); } try { var items = await _service.GetItemPagesFiltered(parameters); if (items != null) { return(Ok(items)); } else { return(NotFound()); } } catch { return(NotFound()); } }
public Item(string name, int age, ItemParameters itemParameters) { this.name = name; this.age = age; this.itemParameters = itemParameters; }
public async Task <IEnumerable <Item> > GetAllItemsPaginationAsync(ItemParameters itemParams) { return(await _unitOfWork.itemRepository.GetAllItemsPaginationAsync(itemParams)); }