Skip to content

Commit

Permalink
[Add] message
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaleprachan committed Apr 3, 2021
1 parent cee510d commit 8be433e
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 9 deletions.
Binary file modified .vs/Roofcare APIs/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/Roofcare APIs/v16/.suo
Binary file not shown.
22 changes: 15 additions & 7 deletions Controllers/AdminController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
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
{
Expand All @@ -33,17 +28,30 @@ public IActionResult Register([FromBody] AdminRegister registerRequest)
return Ok(adminServices.Register(registerRequest));
}

[HttpGet]
[HttpPost]
[Route("AddProfession/{professionName}")]
public IActionResult AddProfession(string professionName)
{
return Ok(adminServices.AddProfession(professionName));
}
[HttpGet]
[Route("GetProfessions")]
public IActionResult GetProfessions()
{
return Ok(adminServices.GetProfessions());
}
[HttpPut]
[Route("UpdateProfession/{id}/{professionName}")]
public IActionResult UpdateProfession(int id, string professionName)
{
return Ok(adminServices.UpdateProfession(id, professionName));
}

[HttpDelete]
[Route("UpdateProfession/{id}")]
public IActionResult DeleteProfession(int id)
{
return Ok(adminServices.DeleteProefession(id));
}
}
}
40 changes: 40 additions & 0 deletions Services/AdminServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ internal object Register(AdminRegister registerRequest)
}
}

internal object GetProfessions()
{
var professions = _dbContext.Professions.Select(p => new
{
p.ProfessionId,
p.ProfessionName
}).ToList();

AdminResponse response = new()
{
Success = true,
Professions = professions
};
return response;

throw new NotImplementedException();
}

internal object DeleteProefession(int id)
{
Profession profession = _dbContext.Professions.Find(id);
if (profession != null)
{
_dbContext.Professions.Remove(profession);
_dbContext.SaveChanges();
return true;
}
else
{
return false;
}
throw new NotImplementedException();
}

internal object UpdateProfession(int id, string professionName)
{
var old_profession = _dbContext.Professions.Where(p => p.ProfessionId == id).FirstOrDefault();
Expand Down Expand Up @@ -79,4 +113,10 @@ internal object AddProfession(string professionName)
}
}
}

class AdminResponse
{
public bool Success { get; set; }
public dynamic Professions { get; set; }
}
}
2 changes: 1 addition & 1 deletion Services/OffersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal object GetAllOffers()
AddedByUsername = offer.User.Username,
AddedByContact = offer.User.Contact,
AddedByImage = offer.User.UserImage
}).ToList();
}).ToList().OrderByDescending(d=>d.PostedDate);
return offers;
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion Services/ReviewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal object GetRatings(int id)
double rating = (double)(5 * fivestar + 4 * fourstart + 3 * threestar + 2 * twostar + 1 * onestar) / (onestar + twostar + threestar + fourstart + fivestar);

rating = Math.Round(rating, 1);

return new Response { Success = true, Message = rating.ToString() };
}
catch (Exception ex)
Expand Down
Binary file modified bin/Debug/net5.0/Roofcare APIs.dll
Binary file not shown.
Binary file modified bin/Debug/net5.0/Roofcare APIs.pdb
Binary file not shown.
Binary file modified bin/Debug/net5.0/ref/Roofcare APIs.dll
Binary file not shown.
Binary file modified obj/Debug/net5.0/Roofcare APIs.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/net5.0/Roofcare APIs.dll
Binary file not shown.
Binary file modified obj/Debug/net5.0/Roofcare APIs.pdb
Binary file not shown.
Binary file modified obj/Debug/net5.0/ref/Roofcare APIs.dll
Binary file not shown.

0 comments on commit 8be433e

Please sign in to comment.