public async Task <IActionResult> Post([FromBody] MicroItem model) { //only authenticated users can post an item string id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (id == null) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest()); } //authorized user is the owner of the item var user = await _userManager.FindByIdAsync(id); model.OwnerName = user.UserName; model.WorkerName = null; //item added var item = await _itemService.InsertItemAsync(model); if (item == null) { return(BadRequest()); } return(Ok(item)); }
public void StartMicro(int difficulty, bool randomize) { _StartMicro(difficulty, randomize); //Have them instantiate everything they need, and then we handle setup for them won = false; playing = true; //Now we set up our own stuff timer.gameObject.SetActive(true); timer.StartTimer(this); positions.Clear(); foreach (Transform child in GetComponentsInChildren <Transform>(true)) //And set up all the MicroItems { if (child == transform) { continue; } positions.Add(child, child.transform.position); MicroItem mi = child.GetComponent <MicroItem>(); if (mi != null) { mi.StartItem(); mi.SetParent(this); } } }
public async Task <IActionResult> Worker([FromBody] int itemId) { //anonymous workers are not allowed string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (userId == null) { return(Unauthorized()); } var user = await _userManager.FindByIdAsync(userId); // owner cannot be a worker! bool isOwner = await IsUserOwnerAsync(userId, itemId); if (isOwner) { return(BadRequest()); } //item must be updated MicroItem oldItem = await _itemService.FindItemAsync(itemId); oldItem.WorkerName = user.UserName; oldItem.Status = ItemStatus.Accepted; var item = await _itemService.UpdateItemAsync(oldItem); if (item == null) { return(BadRequest()); } return(Ok()); }
public void EndMicro() { foreach (Transform child in positions.Keys) //Here is where we need the transforms { MicroItem mi = child.GetComponent <MicroItem>(); if (mi != null) { mi.OnComplete(); } if (ResetPositions) { child.transform.position = positions[child]; } } playing = false; _EndMicro(); //We have cleaned everything up for them, let them handle the rest timer.gameObject.SetActive(false); MicroMixManager.Instance.fireworksController.StopFireworks(); if (won) //This should always be called last { MicroMixManager.Instance.WinMicro(); } else { MicroMixManager.Instance.LoseMicro(); } }
public async Task UpdateMicroItemAsync(MicroItem item, byte[] image = null) { await Service.PutAsync("api/items/", item, authorize : true); if (image != null) { await Service.PostAsync("api/items/image/" + item.Id, image, authorize : true); } }
public async Task AddMicroItemAsync(MicroItem item, byte[] image = null) { // result id needed in order to assign image MicroItem resultItem = await Service.PostAsync <MicroItem, MicroItem>("api/items/", item, authorize : true); if (image != null) { await Service.PostAsync("api/items/image/" + resultItem.Id, image, authorize : true); } }
public async Task <MicroItem> AddAsync(MicroItem item) { var category = await _context.Categories.FindAsync(item.Category.Id); item.Category = category; var added = await _context.AddAsync(item); await _context.SaveChangesAsync(); return(added.Entity); }
public async Task <MicroItem> UpdateAsync(MicroItem item) { if (item.Category != null) { var category = await _context.Categories.FindAsync(item.Category.Id); item.Category = category; } var updated = _context.MicroItems.Update(item); await _context.SaveChangesAsync(); return(updated.Entity); }
//end micro for reset public void CancelMicro() { foreach (Transform child in positions.Keys) //Here is where we need the transforms { MicroItem mi = child.GetComponent <MicroItem>(); if (mi != null) { mi.OnComplete(); } if (ResetPositions) { child.transform.position = positions[child]; } } playing = false; timer.gameObject.SetActive(false); MicroMixManager.Instance.fireworksController.StopFireworks(); }
public async Task <IActionResult> Put([FromBody] MicroItem model) { if (!ModelState.IsValid) { return(BadRequest()); } //user must be authorized and the owner of the item string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (userId == null) { return(Unauthorized()); } if (!await IsUserOwnerAsync(userId, model.Id)) { return(Forbid()); } //item to be updated MicroItem oldItem = await _itemService.FindItemAsync(model.Id); // assigning to properties which are allowed to be modified oldItem.Category = model.Category; oldItem.Description = model.Description; oldItem.Price = model.Price; oldItem.Title = model.Title; //update var item = await _itemService.UpdateItemAsync(oldItem); if (item == null) { return(BadRequest()); } return(NoContent()); }
private void SetMicro(MicroItem data) { ViewModel.Data = data; _ = ViewModel.TapRefreshAsync(); }
public async Task <MicroItem> UpdateItemAsync(MicroItem item) { return(await _repository.UpdateAsync(item)); }
public async Task <MicroItem> InsertItemAsync(MicroItem item) { return(await _repository.AddAsync(item)); }