Skip to content

Instantly share code, notes, and snippets.

@dborovsky
Created September 18, 2018 10:00
Show Gist options
  • Save dborovsky/19ce736d4d5bd3fb13fc54fdc49447e8 to your computer and use it in GitHub Desktop.
Save dborovsky/19ce736d4d5bd3fb13fc54fdc49447e8 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GolovinskyAPI.Infrastructure;
using GolovinskyAPI.Models;
using GolovinskyAPI.Models.ViewModels.Images;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace GolovinskyAPI.Controllers
{
//[Produces("application/json")]
[Route("api/Img")]
[DisableRequestSizeLimit]
public class ImgController : ControllerBase
{
IRepository repo;
public ImgController(IRepository r)
{
repo = r;
}
// GET: api/Img/5
[HttpGet]
///
public IActionResult Get(string AppCode, string ImgFileName)
{
var res = repo.GetImageMobile(AppCode, ImgFileName);
if (res != null)
{
//return Ok("data:image/jpeg;base64," + Convert.ToBase64String(res));
return File(res, "image/jpeg;base64");
}
else
{
return BadRequest();
}
}
// POST: api/Img
[HttpPost]
public IActionResult Post([FromBody] SearchPictureInfoInputModel model)
{
if (!ModelState.IsValid)
{
return BadRequest();
}
else
{
var res = repo.SearchPictureInfo(model);
if(res != null)
{
return Ok(res);
}
else
{
return BadRequest();
}
}
}
/// <summary>
/// Добавление картинки
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("/api/img/upload")]
[Authorize]
public IActionResult Upload([FromForm] NewUploadImageInput model)
{
if (!ModelState.IsValid)
{
return BadRequest("параметры запроса некорректные");
}
bool res = repo.UploadPicture(model);
return Ok(new { result = res });
}
[HttpDelete("/api/img/")]
//[Authorize]
public IActionResult Delete([FromBody] SearchPictureInfoInputModel model)
{
if (!ModelState.IsValid)
{
return BadRequest("параметры запроса некорректные");
}
bool res = repo.DeleteMainPicture(model);
return Ok(new { result = res });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment