Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settle conflicts and add Reportcontroller #17

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions YouCode.BE/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}
}
5 changes: 0 additions & 5 deletions YouCode.BE/Follower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
public DateTime FollowedAt { get; set; }

[NotMapped]
public User User = new User();

Check warning on line 22 in YouCode.BE/Follower.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Make this field 'private' and encapsulate it in a 'public' property. (https://rules.sonarsource.com/csharp/RSPEC-1104)

[NotMapped]
public int Top_Aux { get; set; }



}
}
7 changes: 2 additions & 5 deletions YouCode.BE/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace YouCode.BE
{
public class Group
{
{
[Key]
public int Id { get; set; }
[Required]
Expand All @@ -25,8 +25,5 @@ public class Group
[NotMapped]
public User User { get; set; } = new User();

[NotMapped]
public int Top_Aux { get; set; }

}
}
}
2 changes: 0 additions & 2 deletions YouCode.BE/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ public class Image
[NotMapped]
public Post Post { get; set; } = new Post();

[NotMapped]
public int Top_Aux { get; set; }
}
}
3 changes: 0 additions & 3 deletions YouCode.BE/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
5 changes: 1 addition & 4 deletions YouCode.DAL/CommentDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{
commentDB = await bdContexto.Comment.FirstOrDefaultAsync(c => c.Id == comment.Id);
}
return commentDB;

Check warning on line 64 in YouCode.DAL/CommentDAL.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Possible null reference return.
}
public static async Task<List<Comment>> GetAllAsync()
{
Expand Down Expand Up @@ -89,10 +89,7 @@
}

query = query.OrderByDescending(c => c.Id);
if (comment.Top_Aux > 0)
{
query = query.Take(comment.Top_Aux).AsQueryable();
}

return query;
}

Expand Down
5 changes: 1 addition & 4 deletions YouCode.DAL/FollowerDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ internal static IQueryable<Follower> QuerySelect(IQueryable<Follower> query, Fol
}

query = query.OrderByDescending(c => c.Id);
if (follower.Top_Aux > 0)
{
query = query.Take(follower.Top_Aux).AsQueryable();
}

return query;
}

Expand Down
5 changes: 1 addition & 4 deletions YouCode.DAL/GroupDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public static async Task<int> DeleteAsync(BE.Group group)
}

query = query.OrderByDescending(c => c.Id);
if (group.Top_Aux > 0)
{
query = query.Take(group.Top_Aux).AsQueryable();
}

return query;
}

Expand Down
3 changes: 0 additions & 3 deletions YouCode.DAL/ImageDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ public static async Task<int> 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
Expand Down
5 changes: 1 addition & 4 deletions YouCode.DAL/PostDAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ internal static IQueryable<Post> QuerySelect(IQueryable<Post> query, Post post)
}

query = query.OrderByDescending(c => c.Id);
if (post.Top_Aux > 0)
{
query = query.Take(post.Top_Aux).AsQueryable();
}

return query;
}

Expand Down
9 changes: 1 addition & 8 deletions YouCode.GUI/Controllers/FollowerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ public class FollowerController : Controller

public async Task<IActionResult> 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()
{
Expand Down
9 changes: 1 addition & 8 deletions YouCode.GUI/Controllers/GroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ public class GroupController : Controller

public async Task<IActionResult> 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()
{
Expand Down
4 changes: 0 additions & 4 deletions YouCode.GUI/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
88 changes: 88 additions & 0 deletions YouCode.GUI/Controllers/ReportController.cs
Original file line number Diff line number Diff line change
@@ -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<IActionResult> 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<IActionResult> Edit(int id)
{
var report = await reportBL.GetByIdAsync(new Report {Id = id});
return View(report);
}

//
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> 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<IActionResult> Delete(int id)
{
var report = await reportBL.GetByIdAsync(new Report { Id = id });
return View(report);
}

//
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> 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);
}
}
}
56 changes: 56 additions & 0 deletions YouCode.GUI/Services/ImageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Firebase.Auth;

Check failure on line 1 in YouCode.GUI/Services/ImageService.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

The type or namespace name 'Firebase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 1 in YouCode.GUI/Services/ImageService.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

The type or namespace name 'Firebase' could not be found (are you missing a using directive or an assembly reference?)
using Firebase.Storage;

Check failure on line 2 in YouCode.GUI/Services/ImageService.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

The type or namespace name 'Firebase' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 2 in YouCode.GUI/Services/ImageService.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

The type or namespace name 'Firebase' could not be found (are you missing a using directive or an assembly reference?)
using System.Security.Cryptography;

namespace YouCode.GUI.Services
{
public class ImageService
{
public static async Task<string> 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);
}
}
}
}
Loading