-
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
1 parent
641c338
commit ce7cf94
Showing
23 changed files
with
323 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
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
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,27 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Roofcare_APIs.Data; | ||
using Roofcare_APIs.Services; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Roofcare_APIs.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class SearchController : ControllerBase | ||
{ | ||
private SearchService _searchService; | ||
public SearchController(RoofCareDbContext dbContext) | ||
{ | ||
_searchService = new SearchService(dbContext); | ||
} | ||
[HttpGet] | ||
public IActionResult Get(string searchItem) | ||
{ | ||
return Ok(_searchService.SearchItem(searchItem)); | ||
} | ||
} | ||
} |
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,45 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Roofcare_APIs.Data; | ||
using Roofcare_APIs.Services; | ||
using Roofcare_APIs.UserModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Roofcare_APIs.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class UserSavedController : ControllerBase | ||
{ | ||
private UserSavedService userSavedService; | ||
public UserSavedController(RoofCareDbContext roofCareDbContext) | ||
{ | ||
userSavedService = new UserSavedService(roofCareDbContext); | ||
} | ||
[HttpGet] | ||
public IActionResult Get(int userId) | ||
{ | ||
return Ok(userSavedService.GetSavedOffers(userId)); | ||
} | ||
[HttpGet] | ||
[Route("/GetId")] | ||
public IActionResult GetId(int userId) | ||
{ | ||
return Ok(userSavedService.GetId(userId)); | ||
} | ||
[HttpPost] | ||
public IActionResult Post(SaveOfferModel offerModel) | ||
{ | ||
return Ok(userSavedService.SaveOffer(offerModel)); | ||
} | ||
|
||
[HttpDelete] | ||
public IActionResult Delete(int savedId) | ||
{ | ||
return Ok(userSavedService.DeleteUserSaved(savedId)); | ||
} | ||
} | ||
} |
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
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
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
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,46 @@ | ||
using Roofcare_APIs.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Roofcare_APIs.Services | ||
{ | ||
public class SearchService | ||
{ | ||
private RoofCareDbContext _dbContext; | ||
public SearchService(RoofCareDbContext dbContext) | ||
{ | ||
_dbContext = dbContext; | ||
} | ||
|
||
internal object SearchItem(string searchItem) | ||
{ | ||
try | ||
{ | ||
using (_dbContext) | ||
{ | ||
var searchResult = (from prop in _dbContext.UserProfessions | ||
select new | ||
{ | ||
prop.Profession.ProfessionId, | ||
prop.Profession.ProfessionName, | ||
prop.User.UserId, | ||
prop.User.Username, | ||
prop.User.FullName, | ||
prop.User.Verified, | ||
prop.User.UserType, | ||
prop.User.UserImage, | ||
}).Where(u => u.ProfessionName.StartsWith(searchItem)) | ||
.ToList(); | ||
|
||
return searchResult; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ex.Message; | ||
} | ||
} | ||
} | ||
} |
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,120 @@ | ||
using Roofcare_APIs.Data; | ||
using Roofcare_APIs.Models; | ||
using Roofcare_APIs.UserModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Roofcare_APIs.Services | ||
{ | ||
public class UserSavedService | ||
{ | ||
private RoofCareDbContext _dbContext; | ||
public UserSavedService(RoofCareDbContext roofCareDbContext) | ||
{ | ||
_dbContext = roofCareDbContext; | ||
} | ||
internal object GetSavedOffers(int userId) | ||
{ | ||
try | ||
{ | ||
var savedOffers = (from u in _dbContext.Users | ||
select new | ||
{ | ||
u.UserId, | ||
SavedOffer = (from o in u.SavedOffers | ||
select new | ||
{ | ||
o.SavedOfferId, | ||
o.OfferId, | ||
o.Offer.OfferDescription, | ||
o.Offer.OfferImage, | ||
o.Offer.PostedDate, | ||
o.Offer.ValidDate, | ||
OfferUserId = o.Offer.User.UserId, | ||
OfferUsername = o.Offer.User.Username, | ||
OfferFullName = o.Offer.User.FullName, | ||
OfferPhoneNum = o.Offer.User.Contact, | ||
OfferUserImage = o.Offer.User.UserImage, | ||
}).ToList() | ||
|
||
}).Where(us => us.UserId == userId).FirstOrDefault(); | ||
return savedOffers; | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
return "{Success: " + ex.Message + "}"; | ||
} | ||
} | ||
|
||
internal object DeleteUserSaved(int savedId) | ||
{ | ||
try | ||
{ | ||
SavedOffer old_saved = _dbContext.SavedOffers.Find(savedId); | ||
if (old_saved != null) | ||
{ | ||
_dbContext.Remove(old_saved); | ||
_dbContext.SaveChanges(); | ||
return "Unsaved"; | ||
} | ||
else | ||
{ | ||
return "Offer Save not found"; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ex.Message; | ||
} | ||
} | ||
|
||
internal object GetId(int userId) | ||
{ | ||
try | ||
{ | ||
var savedIds = (from u in _dbContext.Users | ||
select new | ||
{ | ||
u.UserId, | ||
Saveds = (from s in u.SavedOffers | ||
select new | ||
{ | ||
s.SavedOfferId, | ||
s.OfferId | ||
}).ToList() | ||
}).Where(ui => ui.UserId == userId).FirstOrDefault(); | ||
return savedIds; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ex.Message; | ||
} | ||
} | ||
|
||
internal object SaveOffer(SaveOfferModel offerModel) | ||
{ | ||
try | ||
{ | ||
using (_dbContext) | ||
{ | ||
SavedOffer savedOffer = new SavedOffer | ||
{ | ||
UserId = offerModel.UserId, | ||
OfferId = offerModel.OfferId, | ||
SaveDate = DateTime.Now | ||
}; | ||
_dbContext.SavedOffers.Add(savedOffer); | ||
_dbContext.SaveChanges(); | ||
return "{Success: true}"; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return "{Success: " + ex.Message + "}"; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.