예제 #1
0
        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));
        }
예제 #2
0
    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);
            }
        }
    }
예제 #3
0
        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());
        }
예제 #4
0
    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();
        }
    }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
    //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();
    }
예제 #10
0
        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());
        }
예제 #11
0
 private void SetMicro(MicroItem data)
 {
     ViewModel.Data = data;
     _ = ViewModel.TapRefreshAsync();
 }
예제 #12
0
 public async Task <MicroItem> UpdateItemAsync(MicroItem item)
 {
     return(await _repository.UpdateAsync(item));
 }
예제 #13
0
 public async Task <MicroItem> InsertItemAsync(MicroItem item)
 {
     return(await _repository.AddAsync(item));
 }