Browse Source

profile image

filipe
henrydays 3 years ago
parent
commit
18ab36a06f
  1. 23
      api/Controllers/UsersController.cs
  2. 3
      api/Data/IUsersRepository.cs
  3. 18
      api/Data/UsersRepository.cs
  4. 11
      api/Dtos/getProfileImage.cs
  5. 7
      api/Dtos/profileImageToReturn.cs
  6. 2
      api/appsettings.Production.json
  7. 2
      api/appsettings.json

23
api/Controllers/UsersController.cs

@ -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);
}

3
api/Data/IUsersRepository.cs

@ -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);
}
}

18
api/Data/UsersRepository.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using api.Dtos;
using api.Models;
@ -26,16 +27,16 @@ namespace api.Data
if (utilizador != null)
{
utilizador.profileImage = a.base64;
_context.Users.Update(utilizador);
var result = _context.SaveChanges();
if (result >= 1)
if (result >= 1)
{
return utilizador;
}
return null;
}
@ -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);

11
api/Dtos/getProfileImage.cs

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

7
api/Dtos/profileImageToReturn.cs

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

2
api/appsettings.Production.json

@ -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": {

2
api/appsettings.json

@ -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": {

Loading…
Cancel
Save