-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
479 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,111 @@ | ||
using ReasnAPI.Models.Database; | ||
using ReasnAPI.Models.DTOs; | ||
using System.Linq.Expressions; | ||
|
||
using ReasnAPI.Models.Database; | ||
using ReasnAPI.Models.DTOs; | ||
using System.Linq.Expressions; | ||
|
||
namespace ReasnAPI.Services | ||
{ | ||
{ | ||
public class AddressService(ReasnContext context) | ||
{ | ||
{ | ||
public AddressDto? CreateAddress(AddressDto? addressDto) | ||
{ | ||
{ | ||
if (addressDto is null) | ||
{ | ||
return null; | ||
} | ||
|
||
} | ||
|
||
var address = new Address | ||
{ | ||
City = addressDto.City, | ||
Country = addressDto.Country, | ||
State = addressDto.State, | ||
Street = addressDto.Street, | ||
ZipCode = addressDto.ZipCode | ||
}; | ||
|
||
context.Addresses.Add(address); | ||
context.SaveChanges(); | ||
|
||
return addressDto; | ||
} | ||
|
||
{ | ||
City = addressDto.City, | ||
Country = addressDto.Country, | ||
State = addressDto.State, | ||
Street = addressDto.Street, | ||
ZipCode = addressDto.ZipCode | ||
}; | ||
|
||
context.Addresses.Add(address); | ||
context.SaveChanges(); | ||
|
||
return addressDto; | ||
} | ||
|
||
public AddressDto? UpdateAddress(int addressId, AddressDto? addressDto) | ||
{ | ||
{ | ||
if (addressDto is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var address = context.Addresses.FirstOrDefault(r => r.Id == addressId); | ||
|
||
} | ||
|
||
var address = context.Addresses.FirstOrDefault(r => r.Id == addressId); | ||
|
||
if (address is null) | ||
{ | ||
return null; | ||
} | ||
|
||
address.City = addressDto.City; | ||
address.Country = addressDto.Country; | ||
address.Street = addressDto.Street; | ||
address.State = addressDto.State; | ||
address.ZipCode = addressDto.ZipCode; | ||
|
||
context.Addresses.Update(address); | ||
context.SaveChanges(); | ||
|
||
return MapToAddressDto(address); | ||
} | ||
|
||
} | ||
|
||
address.City = addressDto.City; | ||
address.Country = addressDto.Country; | ||
address.Street = addressDto.Street; | ||
address.State = addressDto.State; | ||
address.ZipCode = addressDto.ZipCode; | ||
|
||
context.Addresses.Update(address); | ||
context.SaveChanges(); | ||
|
||
return MapToAddressDto(address); | ||
} | ||
|
||
public bool DeleteAddress(int addressId) | ||
{ | ||
var address = context.Addresses.FirstOrDefault(r => r.Id == addressId); | ||
|
||
{ | ||
var address = context.Addresses.FirstOrDefault(r => r.Id == addressId); | ||
|
||
if (address is null) | ||
{ | ||
return false; | ||
} | ||
|
||
context.Addresses.Remove(address); | ||
context.SaveChanges(); | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
context.Addresses.Remove(address); | ||
context.SaveChanges(); | ||
|
||
return true; | ||
} | ||
|
||
public AddressDto? GetAddressById(int addressId) | ||
{ | ||
var address = context.Addresses.Find(addressId); | ||
|
||
{ | ||
var address = context.Addresses.Find(addressId); | ||
|
||
if (address is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return MapToAddressDto(address); | ||
} | ||
|
||
} | ||
|
||
return MapToAddressDto(address); | ||
} | ||
|
||
public IEnumerable<AddressDto?> GetAddressesByFilter(Expression<Func<Address, bool>> filter) | ||
{ | ||
return context.Addresses | ||
.Where(filter) | ||
.Select(address => MapToAddressDto(address)) | ||
{ | ||
return context.Addresses | ||
.Where(filter) | ||
.Select(address => MapToAddressDto(address)) | ||
.AsEnumerable(); | ||
} | ||
|
||
} | ||
|
||
public IEnumerable<AddressDto?> GetAllAddresses() | ||
{ | ||
return context.Addresses | ||
.Select(address => MapToAddressDto(address)) | ||
.AsEnumerable(); | ||
} | ||
|
||
{ | ||
return context.Addresses | ||
.Select(address => MapToAddressDto(address)) | ||
.AsEnumerable(); | ||
} | ||
|
||
private static AddressDto MapToAddressDto(Address address) | ||
{ | ||
{ | ||
return new AddressDto | ||
{ | ||
Country = address.Country, | ||
City = address.City, | ||
Street = address.Street, | ||
State = address.State, | ||
ZipCode = address.ZipCode | ||
}; | ||
} | ||
} | ||
} | ||
{ | ||
Country = address.Country, | ||
City = address.City, | ||
Street = address.Street, | ||
State = address.State, | ||
ZipCode = address.ZipCode | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,105 @@ | ||
using ReasnAPI.Models.Database; | ||
using ReasnAPI.Models.DTOs; | ||
using System.Linq.Expressions; | ||
|
||
using ReasnAPI.Models.Database; | ||
using ReasnAPI.Models.DTOs; | ||
using System.Linq.Expressions; | ||
|
||
namespace ReasnAPI.Services | ||
{ | ||
{ | ||
public class CommentService(ReasnContext context) | ||
{ | ||
{ | ||
public CommentDto? CreateComment(CommentDto? commentDto) | ||
{ | ||
{ | ||
if (commentDto is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
var comment = new Comment | ||
{ | ||
EventId = commentDto.EventId, | ||
Content = commentDto.Content, | ||
UserId = commentDto.UserId, | ||
CreatedAt = DateTime.UtcNow | ||
}; | ||
|
||
context.Comments.Add(comment); | ||
{ | ||
EventId = commentDto.EventId, | ||
Content = commentDto.Content, | ||
UserId = commentDto.UserId, | ||
CreatedAt = DateTime.UtcNow | ||
}; | ||
|
||
context.Comments.Add(comment); | ||
context.SaveChanges(); | ||
|
||
return commentDto; | ||
} | ||
|
||
return commentDto; | ||
} | ||
|
||
public CommentDto? UpdateComment(int commentId, CommentDto? commentDto) | ||
{ | ||
{ | ||
if (commentDto is null) | ||
{ | ||
return null; | ||
} | ||
|
||
var comment = context.Comments.FirstOrDefault(r => r.Id == commentId); | ||
|
||
return null; | ||
} | ||
|
||
var comment = context.Comments.FirstOrDefault(r => r.Id == commentId); | ||
|
||
if (comment is null) | ||
{ | ||
return null; | ||
} | ||
|
||
comment.Content = commentDto.Content; | ||
|
||
context.Comments.Update(comment); | ||
context.SaveChanges(); | ||
|
||
return MapToCommentDto(comment); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
comment.Content = commentDto.Content; | ||
|
||
context.Comments.Update(comment); | ||
context.SaveChanges(); | ||
|
||
return MapToCommentDto(comment); | ||
} | ||
|
||
public bool DeleteComment(int commentId) | ||
{ | ||
var comment = context.Comments.FirstOrDefault(r => r.Id == commentId); | ||
|
||
{ | ||
var comment = context.Comments.FirstOrDefault(r => r.Id == commentId); | ||
|
||
if (comment is null) | ||
{ | ||
return false; | ||
} | ||
|
||
context.Comments.Remove(comment); | ||
context.SaveChanges(); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
context.Comments.Remove(comment); | ||
context.SaveChanges(); | ||
|
||
return true; | ||
} | ||
|
||
public CommentDto? GetCommentById(int commentId) | ||
{ | ||
var comment = context.Comments.Find(commentId); | ||
|
||
{ | ||
var comment = context.Comments.Find(commentId); | ||
|
||
if (comment is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return MapToCommentDto(comment); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return MapToCommentDto(comment); | ||
} | ||
|
||
public IEnumerable<CommentDto?> GetCommentsByFilter(Expression<Func<Comment, bool>> filter) | ||
{ | ||
return context.Comments | ||
.Where(filter) | ||
.Select(comment => MapToCommentDto(comment)) | ||
.AsEnumerable(); | ||
} | ||
|
||
{ | ||
return context.Comments | ||
.Where(filter) | ||
.Select(comment => MapToCommentDto(comment)) | ||
.AsEnumerable(); | ||
} | ||
|
||
public IEnumerable<CommentDto?> GetAllComments() | ||
{ | ||
return context.Comments | ||
.Select(comment => MapToCommentDto(comment)) | ||
.AsEnumerable(); | ||
} | ||
|
||
{ | ||
return context.Comments | ||
.Select(comment => MapToCommentDto(comment)) | ||
.AsEnumerable(); | ||
} | ||
|
||
private static CommentDto MapToCommentDto(Comment comment) | ||
{ | ||
return new CommentDto | ||
{ | ||
{ | ||
EventId = comment.EventId, | ||
UserId = comment.UserId, | ||
Content = comment.Content, | ||
CreatedAt = comment.CreatedAt | ||
}; | ||
} | ||
} | ||
} | ||
UserId = comment.UserId, | ||
Content = comment.Content, | ||
CreatedAt = comment.CreatedAt | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using ReasnAPI.Models.Database; | ||
|
||
namespace ReasnAPI.Services { | ||
public class ObjectTypeService (ReasnContext context) { | ||
private readonly ReasnContext _context = context; | ||
|
||
/* TODO: Create following functions for this class | ||
* create | ||
* update | ||
* delete | ||
* get by ID | ||
* get list by filter | ||
* get all | ||
*/ | ||
} | ||
} |
Oops, something went wrong.