Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ication into main
  • Loading branch information
ozanozbirecikli committed Jan 2, 2021
2 parents a22fc4c + 3d47700 commit ba943c6
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 55 deletions.
Binary file modified .vs/CS434.API/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/CS434.API/v16/.suo
Binary file not shown.
Binary file modified .vs/LibraryApplication/v16/.suo
Binary file not shown.
Binary file modified .vs/slnx.sqlite
Binary file not shown.
5 changes: 5 additions & 0 deletions CS434.API/CS434.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="MODELS\Response\Class.cs" />
<Compile Remove="MODELS\Response\Class1.cs" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
Expand Down
23 changes: 18 additions & 5 deletions CS434.API/Controllers/RezervationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,32 @@ namespace CS434.API.Controllers
[Authorize]
public class RezervationsController : ControllerBase
{
IRezervationService RezervationService;
IReservationService reservationService;
IConfiguration configuration;
public RezervationsController(IConfiguration configuration)
{
RezervationService = new RezervationService(configuration);
reservationService = new ReservationService(configuration);
}

[HttpPost("Rezerve")]
public ReserveModel makeReservation(RezervationModel reservationModel)
[HttpPost("Reserve")]
public ReserveResponseModel makeReservation(ReservationModel reservationModel)
{
return
return reservationService.makeReservation(reservationModel);
}

[HttpPost("Return")]
public MessageModel returnReservation(ReservationModel reservationModel)
{
return reservationService.returnReservedItem(reservationModel);
}

[HttpPost("ShowReservations")]
public ReservationsResponseModel showReservations(int USER_ID)
{
return reservationService.ShowAllItems(USER_ID);
}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace CS434.API.Interfaces
{
interface IRezervationService
interface IReservationService
{
MessageModel makeRezervation(RezervationModel rezervationRequestModel);
MessageModel returnRezervedItem(RezervationModel rezervationModel);
List<Items> ShowAllItems();
ReserveResponseModel makeReservation(ReservationModel rezervationRequestModel);
MessageModel returnReservedItem(ReservationModel rezervationModel);
ReservationsResponseModel ShowAllItems(int USER_ID);

}
}
1 change: 1 addition & 0 deletions CS434.API/MODELS/Database/DEV_Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
public DbSet<Users> Users { get; set; }
public DbSet<Roles> Roles { get; set; }
public DbSet<Items> Items { get; set; }
public DbSet<Reservations> Reservations { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

namespace CS434.API.MODELS.Database
{
[Table("REZERVATIONS")]
public class Rezervations
[Table("RESERVATIONS")]
public class Reservations
{
[Key]
public int REZ_ID { get; set; }
public int USER_ID { get; set; }
public int ITEM_ID { get; set; }
public bool? IS_RETURNED { get; set; }
public DateTime? REZ_DATE { get; set; }
public DateTime? RETURN_DATE { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CS434.API.MODELS.Request
{
public class RezervationModel
public class ReservationModel
{
public int User_Id { get; set; }
public int Item_Id { get; set; }
Expand Down
11 changes: 11 additions & 0 deletions CS434.API/MODELS/Response/Class.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
llusing System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CS434.API.MODELS.Response
{
public class Class
{
}
}
8 changes: 8 additions & 0 deletions CS434.API/MODELS/Response/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


namespace CS434.API.MODELS.Response
{
public class Class1
{
}
}
15 changes: 15 additions & 0 deletions CS434.API/MODELS/Response/ReservationsResponseModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CS434.API.MODELS.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CS434.API.MODELS.Response
{
public class ReservationsResponseModel
{
public bool Result { get; set; }
public string Message { get; set; }
public List<Reservations> reservations { get; set; }
}
}
2 changes: 1 addition & 1 deletion CS434.API/MODELS/Response/ReserveResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class ReserveResponseModel
{
public bool Result { get; set; }
public string Message { get; set; }
public Rezervations Rezervation { get; set; }
public Reservations Rezervation { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

namespace CS434.API.Services
{
public class RezervationService: IRezervationService
public class ReservationService : IReservationService
{
IConfiguration configuration;
public RezervationService(IConfiguration configuration)
public ReservationService(IConfiguration configuration)
{
this.configuration = configuration;
}

public ReserveResponseModel makeRezervation(RezervationModel rezervationModel)
public ReserveResponseModel makeReservation(ReservationModel rezervationModel)
{
using (var dbContext = new DEV_Context())
{
Expand All @@ -27,8 +27,8 @@ public ReserveResponseModel makeRezervation(RezervationModel rezervationModel)
try
{
ReserveResponseModel reserveResponseModel = new ReserveResponseModel();
var sorgu = dbContext.Set<Rezervations>().FirstOrDefault(x => x.USER_ID == rezervationModel.User_Id && x.ITEM_ID == rezervationModel.Item_Id && x.IS_RETURNED == false);
if (sorgu!= null)
var sorgu = dbContext.Set<Reservations>().FirstOrDefault(x => x.USER_ID == rezervationModel.User_Id && x.ITEM_ID == rezervationModel.Item_Id && x.IS_RETURNED == false);
if (sorgu != null)
{
reserveResponseModel.Message = "Bu kitabınız hala rezerve haldedir.";
reserveResponseModel.Result = false;
Expand All @@ -38,25 +38,26 @@ public ReserveResponseModel makeRezervation(RezervationModel rezervationModel)
}
else
{
var rezervation = new Rezervations
var rezervation = new Reservations
{
USER_ID = rezervationModel.User_Id,
ITEM_ID = rezervationModel.Item_Id,
IS_RETURNED = false,
REZ_DATE = DateTime.Now
REZ_DATE = DateTime.Now,
RETURN_DATE = null
};

reserveResponseModel.Rezervation = rezervation;
reserveResponseModel.Message = "Rezervasyon başarıyla oluşturulmuştur.";
reserveResponseModel.Result = true;

dbContext.Set<Rezervations>().Add(rezervation);
dbContext.Set<Reservations>().Add(rezervation);
var itemSorgu = dbContext.Set<Items>().FirstOrDefault(x => x.Id == rezervationModel.Item_Id);
itemSorgu.Amount = itemSorgu.Amount - 1;
dbContext.SaveChanges();
dbContextTransaction.Commit();

return reserveResponseModel;
return reserveResponseModel;
}
}
catch (Exception e)
Expand All @@ -70,7 +71,7 @@ public ReserveResponseModel makeRezervation(RezervationModel rezervationModel)
}
}

public MessageModel returnRezervedItem(RezervationModel rezervationModel)
public MessageModel returnReservedItem(ReservationModel rezervationModel)
{
using (var dbContext = new DEV_Context())
{
Expand All @@ -79,17 +80,18 @@ public MessageModel returnRezervedItem(RezervationModel rezervationModel)
try
{
MessageModel messageModel = new MessageModel();
var sorgu = dbContext.Set<Rezervations>().FirstOrDefault(x => x.USER_ID == rezervationModel.User_Id && x.ITEM_ID == rezervationModel.Item_Id);
var sorgu = dbContext.Set<Reservations>().FirstOrDefault(x => x.USER_ID == rezervationModel.User_Id && x.ITEM_ID == rezervationModel.Item_Id);
if (sorgu.IS_RETURNED == true)
{
messageModel.Message = "Kitap zaten rezerve edilmemiştir.";
messageModel.Message = "Book is already avalaible.";
messageModel.Result = false;
return messageModel;
}
else
{
sorgu.IS_RETURNED = true;
messageModel.Message = "Kitap iade edilmiştir";
sorgu.RETURN_DATE = DateTime.Now;
messageModel.Message = "Book has been returned.";
messageModel.Result = true;
var itemSorgu = dbContext.Set<Items>().FirstOrDefault(x => x.Id == rezervationModel.Item_Id);
itemSorgu.Amount = itemSorgu.Amount + 1;
Expand All @@ -111,29 +113,43 @@ public MessageModel returnRezervedItem(RezervationModel rezervationModel)
}
}

public List<Items> ShowAllItems()


public ReservationsResponseModel ShowAllItems(int userId)
{
throw new NotImplementedException();
}
using (var dbContext = new DEV_Context())
{

//public List<Items> ShowAllItems(int USER_ID)
//{
// using (var dbContext = new DEV_Context())
// {
// using (var dbContextTransaction = dbContext.Database.BeginTransaction())
// {
// try
// {

// }
// catch (Exception)
// {

// throw;
// }
// }
// }
//}
try
{
ReservationsResponseModel reservationsResponseModel = new ReservationsResponseModel();
var queryList = dbContext.Set<Reservations>().ToList();
if (queryList.Count > 0)
{
reservationsResponseModel.Message = "All reservations is fetched succesfully!";
reservationsResponseModel.Result = true;
reservationsResponseModel.reservations = queryList;
return reservationsResponseModel;
}
else
{
reservationsResponseModel.Message = "There is no reservations!";
reservationsResponseModel.Result = false;
reservationsResponseModel.reservations = null;
return reservationsResponseModel;
}
}


catch (Exception e)
{

throw;
}


}
}



Expand Down
Binary file modified CS434.API/bin/Debug/netcoreapp2.1/CS434.API.dll
Binary file not shown.
Binary file modified CS434.API/bin/Debug/netcoreapp2.1/CS434.API.pdb
Binary file not shown.
10 changes: 5 additions & 5 deletions CS434.API/obj/CS434.API.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
"C:\\Users\\Cem\\Source\\Repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj": {}
"C:\\Users\\Cem\\source\\repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj": {}
},
"projects": {
"C:\\Users\\Cem\\Source\\Repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj": {
"C:\\Users\\Cem\\source\\repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\Cem\\Source\\Repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj",
"projectUniqueName": "C:\\Users\\Cem\\source\\repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj",
"projectName": "CS434.API",
"projectPath": "C:\\Users\\Cem\\Source\\Repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj",
"projectPath": "C:\\Users\\Cem\\source\\repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj",
"packagesPath": "C:\\Users\\Cem\\.nuget\\packages\\",
"outputPath": "C:\\Users\\Cem\\Source\\Repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\obj\\",
"outputPath": "C:\\Users\\Cem\\source\\repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\Cem\\AppData\\Roaming\\NuGet\\NuGet.Config",
Expand Down
Binary file modified CS434.API/obj/Debug/netcoreapp2.1/CS434.API.assets.cache
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d6455b5b4880d52b2f44a856836bebe088743bd5
71a24a5da6588949e6284a138228ac3f187b7398
Binary file not shown.
Binary file modified CS434.API/obj/Debug/netcoreapp2.1/CS434.API.dll
Binary file not shown.
Binary file modified CS434.API/obj/Debug/netcoreapp2.1/CS434.API.pdb
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions CS434.API/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": 2,
"dgSpecHash": "z9g8tY/AQkSSHQE6juJ+QGhL7xXHOjCFhoWToWNeOX0D4Dxp2DMfWfrRou9bhdhPlEdzFWGCqynKvJTe4dgN9A==",
"dgSpecHash": "EnMi58P3Te89eaqmHBleeVu6VSg8Q/d8h3wq0GwVOquKGpKeBgRXhjArZooKDGn4sDofd287ri5e0JKNsDRMJw==",
"success": true,
"projectFilePath": "C:\\Users\\Cem\\Source\\Repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj",
"projectFilePath": "C:\\Users\\Cem\\source\\repos\\ozanozbirecikli\\LibraryApplication\\CS434.API\\CS434.API.csproj",
"expectedPackageFiles": [
"C:\\Users\\Cem\\.nuget\\packages\\microsoft.aspnet.webapi.client\\5.2.6\\microsoft.aspnet.webapi.client.5.2.6.nupkg.sha512",
"C:\\Users\\Cem\\.nuget\\packages\\microsoft.aspnetcore\\2.1.1\\microsoft.aspnetcore.2.1.1.nupkg.sha512",
Expand Down

0 comments on commit ba943c6

Please sign in to comment.