diff --git a/YouCode.BE/Comment.cs b/YouCode.BE/Comment.cs index 0e55c92..9ed8bf7 100644 --- a/YouCode.BE/Comment.cs +++ b/YouCode.BE/Comment.cs @@ -25,8 +25,6 @@ public class Comment public User User { get; set; } = new User(); [NotMapped] public Post Post { get; set; } =new Post(); - [NotMapped] - public int Top_Aux { get; set; } } } diff --git a/YouCode.BE/Follower.cs b/YouCode.BE/Follower.cs index 5836b3e..b1f1f60 100644 --- a/YouCode.BE/Follower.cs +++ b/YouCode.BE/Follower.cs @@ -21,10 +21,5 @@ public class Follower [NotMapped] public User User = new User(); - [NotMapped] - public int Top_Aux { get; set; } - - - } } diff --git a/YouCode.BE/Group.cs b/YouCode.BE/Group.cs index 41c44f8..69e3e01 100644 --- a/YouCode.BE/Group.cs +++ b/YouCode.BE/Group.cs @@ -9,7 +9,7 @@ namespace YouCode.BE { public class Group - { + { [Key] public int Id { get; set; } [Required] @@ -25,8 +25,5 @@ public class Group [NotMapped] public User User { get; set; } = new User(); - [NotMapped] - public int Top_Aux { get; set; } - - } + } } diff --git a/YouCode.BE/Image.cs b/YouCode.BE/Image.cs index d3561e2..a55d199 100644 --- a/YouCode.BE/Image.cs +++ b/YouCode.BE/Image.cs @@ -20,7 +20,5 @@ public class Image [NotMapped] public Post Post { get; set; } = new Post(); - [NotMapped] - public int Top_Aux { get; set; } } } diff --git a/YouCode.BE/Post.cs b/YouCode.BE/Post.cs index 5a2cc36..c3686ca 100644 --- a/YouCode.BE/Post.cs +++ b/YouCode.BE/Post.cs @@ -21,9 +21,6 @@ public class Post public DateTime PostedAt { get; set; } [ForeignKey("User")] public int IdUser { get; set; } - - [NotMapped] - public int Top_Aux { get; set; } public User User { get; set; } = new User(); } } diff --git a/YouCode.DAL/CommentDAL.cs b/YouCode.DAL/CommentDAL.cs index 74b1cd1..febf8ef 100644 --- a/YouCode.DAL/CommentDAL.cs +++ b/YouCode.DAL/CommentDAL.cs @@ -89,10 +89,7 @@ internal static IQueryable QuerySelect(IQueryable query, Comme } query = query.OrderByDescending(c => c.Id); - if (comment.Top_Aux > 0) - { - query = query.Take(comment.Top_Aux).AsQueryable(); - } + return query; } diff --git a/YouCode.DAL/FollowerDAL.cs b/YouCode.DAL/FollowerDAL.cs index dc8b32f..70f344d 100644 --- a/YouCode.DAL/FollowerDAL.cs +++ b/YouCode.DAL/FollowerDAL.cs @@ -83,10 +83,7 @@ internal static IQueryable QuerySelect(IQueryable query, Fol } query = query.OrderByDescending(c => c.Id); - if (follower.Top_Aux > 0) - { - query = query.Take(follower.Top_Aux).AsQueryable(); - } + return query; } diff --git a/YouCode.DAL/GroupDAL.cs b/YouCode.DAL/GroupDAL.cs index d35c427..865f78b 100644 --- a/YouCode.DAL/GroupDAL.cs +++ b/YouCode.DAL/GroupDAL.cs @@ -87,10 +87,7 @@ public static async Task DeleteAsync(BE.Group group) } query = query.OrderByDescending(c => c.Id); - if (group.Top_Aux > 0) - { - query = query.Take(group.Top_Aux).AsQueryable(); - } + return query; } diff --git a/YouCode.DAL/ImageDAL.cs b/YouCode.DAL/ImageDAL.cs index e766e8f..22c7296 100644 --- a/YouCode.DAL/ImageDAL.cs +++ b/YouCode.DAL/ImageDAL.cs @@ -87,9 +87,6 @@ public static async Task DeleteAsync(BE.Image image) query = query.OrderByDescending(s => s.Id).AsQueryable(); - if (image.Top_Aux > 0) - query = query.Take(image.Top_Aux).AsQueryable(); - return query; } // permite buscar imágenes en la base de datos diff --git a/YouCode.DAL/PostDAL.cs b/YouCode.DAL/PostDAL.cs index d1c67bc..5a2d356 100644 --- a/YouCode.DAL/PostDAL.cs +++ b/YouCode.DAL/PostDAL.cs @@ -87,10 +87,7 @@ internal static IQueryable QuerySelect(IQueryable query, Post post) } query = query.OrderByDescending(c => c.Id); - if (post.Top_Aux > 0) - { - query = query.Take(post.Top_Aux).AsQueryable(); - } + return query; } diff --git a/YouCode.GUI/Controllers/FollowerController.cs b/YouCode.GUI/Controllers/FollowerController.cs index 0fac2fe..fee59cc 100644 --- a/YouCode.GUI/Controllers/FollowerController.cs +++ b/YouCode.GUI/Controllers/FollowerController.cs @@ -11,14 +11,7 @@ public class FollowerController : Controller public async Task Index(Follower follower) { - if(follower.Top_Aux == 0) - follower.Top_Aux = 10; - else if(follower.Top_Aux < 0) - follower.Top_Aux = 0; - - var followers = await followerBL.SearchAsync(follower); - ViewBag.Top = follower.Top_Aux; - return View(followers); + return View(); } public IActionResult Create() { diff --git a/YouCode.GUI/Controllers/GroupController.cs b/YouCode.GUI/Controllers/GroupController.cs index 0a085ef..9fc7187 100644 --- a/YouCode.GUI/Controllers/GroupController.cs +++ b/YouCode.GUI/Controllers/GroupController.cs @@ -11,14 +11,7 @@ public class GroupController : Controller public async Task Index(Group group) { - if(group.Top_Aux == 0) - group.Top_Aux = 10; - else if(group.Top_Aux < 0) - group.Top_Aux = 0; - - var groups = await groupBL.SearchAsync(group); - ViewBag.Top = group.Top_Aux; - return View(groups); + return View(); } public IActionResult Create() { diff --git a/YouCode.GUI/Controllers/ProfileController.cs b/YouCode.GUI/Controllers/ProfileController.cs index 7a731ee..bdb45b6 100644 --- a/YouCode.GUI/Controllers/ProfileController.cs +++ b/YouCode.GUI/Controllers/ProfileController.cs @@ -10,10 +10,6 @@ public class ProfileController : Controller UserBL userBL = new UserBL(); PostBL postBL = new PostBL(); - public IActionResult Index() - { - return View(); //falta de ver como madres traerme la info del usuario actual - } public IActionResult Create() { ViewBag.Error = ""; diff --git a/YouCode.GUI/Controllers/ReportController.cs b/YouCode.GUI/Controllers/ReportController.cs new file mode 100644 index 0000000..8e098a2 --- /dev/null +++ b/YouCode.GUI/Controllers/ReportController.cs @@ -0,0 +1,88 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using YouCode.BE; +using YouCode.BL; + +namespace YouCode.GUI.Controllers; + +public class ReportController : Controller +{ + ReportBL reportBL = new ReportBL(); + + public ActionResult Index() + { + return View(); + } + + // + public IActionResult Create() + { + ViewBag.Error = ""; + return View(); + } + + // + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Create(Report report) + { + try + { + int result = await reportBL.CreateAsync(report); + return RedirectToAction(nameof(Index)); + } + catch(Exception ex) + { + ViewBag.Error = ex.Message; + return View(report); + } + } + + // + public async Task Edit(int id) + { + var report = await reportBL.GetByIdAsync(new Report {Id = id}); + return View(report); + } + + // + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Edit(int id, Report report) + { + try + { + int result = await reportBL.UpdateAsync(report); + return RedirectToAction(nameof(Index)); + } + catch (Exception ex) + { + ViewBag.Error = ex.Message; + return View(); + } + } + + // + public async Task Delete(int id) + { + var report = await reportBL.GetByIdAsync(new Report { Id = id }); + return View(report); + } + + // + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Delete(int id, Report report) + { + try + { + int result = await reportBL.DeleteAsync(report); + return RedirectToAction(nameof(Index)); + } + catch (Exception ex) + { + ViewBag.Error = ex.Message; + return View(report); + } + } +} diff --git a/YouCode.GUI/Services/ImageService.cs b/YouCode.GUI/Services/ImageService.cs new file mode 100644 index 0000000..058cd95 --- /dev/null +++ b/YouCode.GUI/Services/ImageService.cs @@ -0,0 +1,56 @@ +using Firebase.Auth; +using Firebase.Storage; +using System.Security.Cryptography; + +namespace YouCode.GUI.Services +{ + public class ImageService + { + public static async Task SubirArchivo(Stream archivo, string nombre) + { + string fileName = GetRandomNumber().ToString() + nombre; + string email = "kedatech.yourcode@gmail.com"; + string clave = "kdayourc0de"; + string ruta = "youcodefirebase.appspot.com"; + string api_key = "AIzaSyCaZMnze2Y_vDK2qpG5eLIu_uFyGYatrGU"; + + var authProvider = new FirebaseAuthProvider(new FirebaseConfig(api_key)); + var auth = await authProvider.SignInWithEmailAndPasswordAsync(email, clave); + + var cancellation = new CancellationTokenSource(); + + var task = new FirebaseStorage( + ruta, + new FirebaseStorageOptions + { + AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken), + ThrowOnCancel = true + }) + .Child("adds_images") + .Child(fileName) + + .PutAsync(archivo, cancellation.Token); + + try + { + var downloadURL = await task; + return downloadURL; + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + return ""; + } + + static int GetRandomNumber() + { + using (RNGCryptoServiceProvider rngCrypt = new RNGCryptoServiceProvider()) + { + byte[] tokenBuffer = new byte[4]; + rngCrypt.GetBytes(tokenBuffer); + return BitConverter.ToInt32(tokenBuffer, 0); + } + } + } +}