profile image

This commit is contained in:
henrydays 2019-03-24 18:57:09 +00:00
parent 71e37564f4
commit 18ab36a06f
7 changed files with 60 additions and 6 deletions

View File

@ -31,13 +31,34 @@ namespace api.Controllers
_repo = repo;
}
[AllowAnonymous]
[HttpGet("getProfileImage/{QRcode}")]
public async Task<IActionResult> getProfileImage(string QRcode)
{
var user = _repo.getProfileImageAsync(QRcode);
profileImageToReturn a = new profileImageToReturn();
if (user.Result != null)
{
a.profileBase64 = user.Result;
return Ok(a);
}
return NotFound();
}
[HttpPost("changeProfileImage")]
public async Task<IActionResult> changeProfileImage(profileImage i)
{
User a = new User();
var cenas =await _repo.changeProfileImage(i);
var cenas = await _repo.changeProfileImage(i);
return Ok(cenas);
}

View File

@ -14,6 +14,9 @@ namespace api.Data
Task<IEnumerable<User>> GetUsers();
Task<User> GetUser(int id);
Task<User> changeProfileImage(profileImage a);
Task<string> getProfileImageAsync(string qrCode);
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using api.Dtos;
using api.Models;
@ -44,9 +45,20 @@ namespace api.Data
public void Delete<T>(T entity) where T : class
{
_context.Remove(entity);
}
public Task<string> getProfileImageAsync(string qrCode)
{
return Task.Run(() =>
{
return _context.Users.Where(a => a.QRcode == qrCode).Select(u => u.profileImage).SingleOrDefault() ;
});
}
public async Task<User> GetUser(int id)
{
var user = await _context.Users.Include(p => p.Photos).FirstOrDefaultAsync(u => u.Id == id);

View File

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace api.Dtos
{
public class getProfileImage
{
[Required]
public string QRcode{get;set;}
}
}

View File

@ -0,0 +1,7 @@
namespace api.Dtos
{
public class profileImageToReturn
{
public string profileBase64{get;set;}
}
}

View File

@ -5,7 +5,7 @@
},
"ConnectionStrings":
{
"DefaultConnection":"server=35.195.235.45;database=enei;uid=api;password=VkGTCmDAg6p4THnE"
"DefaultConnection":"server=35.195.235.45;database=enei;uid=local;password=VkGTCmDAg6p4THnE"
},
"Logging": {

View File

@ -5,7 +5,7 @@
},
"ConnectionStrings":
{
"DefaultConnection":"server=35.195.235.45;database=enei;uid=api;password=VkGTCmDAg6p4THnE"
"DefaultConnection":"server=35.195.235.45;database=enei;uid=local;password=VkGTCmDAg6p4THnE"
},
"Logging": {