public async Task <IActionResult> PutDotaItem([FromRoute] int id, [FromBody] DotaItem dotaItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dotaItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(dotaItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DotaItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostDotaItem([FromBody] DotaItem dotaItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.DotaItem.Add(dotaItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDotaItem", new { id = dotaItem.Id }, dotaItem));
        }
        public async Task <IActionResult> UploadFile([FromForm] DotaImageItem meme)
        {
            if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
            {
                return(BadRequest($"Expected a multipart request, but got {Request.ContentType}"));
            }
            try
            {
                using (var stream = meme.Image.OpenReadStream())
                {
                    var cloudBlock = await UploadToBlob(meme.Image.FileName, null, stream);

                    //// Retrieve the filename of the file you have uploaded
                    //var filename = provider.FileData.FirstOrDefault()?.LocalFileName;
                    if (string.IsNullOrEmpty(cloudBlock.StorageUri.ToString()))
                    {
                        return(BadRequest("An error has occured while uploading your file. Please try again."));
                    }

                    DotaItem memeItem = new DotaItem();
                    memeItem.Title = meme.Title;
                    memeItem.Tags  = meme.Tags;

                    System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
                    memeItem.Height   = image.Height.ToString();
                    memeItem.Width    = image.Width.ToString();
                    memeItem.Url      = cloudBlock.SnapshotQualifiedUri.AbsoluteUri;
                    memeItem.Uploaded = DateTime.Now.ToString();

                    _context.DotaItem.Add(memeItem);
                    await _context.SaveChangesAsync();

                    return(Ok($"File: {meme.Title} has successfully uploaded"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"An error has occured. Details: {ex.Message}"));
            }
        }
Exemple #4
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(nameTextBox.Text))
            {
                switch (dialogType)
                {
                case DotaType.Hero:
                    MessageBox.Show("Dota 2 does not currently support custom heroes.");
                    break;

                case DotaType.Unit:
                    DotaUnit unit = new DotaUnit(nameTextBox.Text);
                    unit.BaseClass = DEFAULT_UNIT_CLASS;
                    if (objectListBox.SelectedIndex != -1)
                    {
                        unit.BaseClass = objectListBox.SelectedItem.ToString();
                    }
                    unit.ObjectInfo.ObjectClass = DotaDataObject.DataObjectInfo.ObjectDataClass.Custom;
                    DotaData.AllUnits.Add(unit);
                    break;

                case DotaType.Ability:
                    DotaAbility ability = new DotaAbility(nameTextBox.Text);
                    ability.BaseClass = DEFAULT_ABILITY_CLASS;
                    if (objectListBox.SelectedIndex != -1)
                    {
                        ability.BaseClass = objectListBox.SelectedItem.ToString();
                    }
                    ability.ObjectInfo.ObjectClass = DotaDataObject.DataObjectInfo.ObjectDataClass.Custom;
                    DotaData.AllAbilities.Add(ability);
                    break;

                case DotaType.Item:
                    DotaItem item = new DotaItem(nameTextBox.Text);
                    item.BaseClass = DEFAULT_ITEM_CLASS;
                    if (objectListBox.SelectedIndex != -1)
                    {
                        item.BaseClass = objectListBox.SelectedItem.ToString();
                    }
                    item.ObjectInfo.ObjectClass = DotaDataObject.DataObjectInfo.ObjectDataClass.Custom;
                    DotaData.AllItems.Add(item);
                    break;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                switch (dialogType)
                {
                case DotaType.Hero:
                    MessageBox.Show("Please enter a valid hero name.");
                    break;

                case DotaType.Unit:
                    MessageBox.Show("Please enter a valid unit name.");
                    break;

                case DotaType.Ability:
                    MessageBox.Show("Please enter a valid ability name.");
                    break;

                case DotaType.Item:
                    MessageBox.Show("Please enter a valid item name.");
                    break;
                }
            }
        }