PostgreSQL и MongoDB работают, осталось сделать перенос данных
This commit is contained in:
parent
fb58294e55
commit
040a7e8821
@ -2,6 +2,7 @@
|
||||
using CarRentContracts.BindingModels;
|
||||
using CarRentContracts.BusinessLogicContracts;
|
||||
using CarRentContracts.SearchModels;
|
||||
using CarRentContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -21,6 +22,8 @@ namespace CarRent
|
||||
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
private string? _objectId;
|
||||
public string ObjectId { set { _objectId = value; } }
|
||||
public FormAddReview(IRentalLogic rentalLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -37,8 +40,11 @@ namespace CarRent
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _rentalLogic.ReadElement(new RentalSearchModel { Id = _id.Value });
|
||||
|
||||
RentalViewModel view;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
view = _rentalLogic.ReadElement(new RentalSearchModel { Id = _id.Value });
|
||||
else
|
||||
view = _rentalLogic.ReadElement(new RentalSearchModel { ObjectId = _objectId });
|
||||
if (view != null && (view.ReviewRating >= 1 || view.ReviewRating <= 5))
|
||||
{
|
||||
textBoxReviewText.Text = view.ReviewText;
|
||||
@ -72,13 +78,38 @@ namespace CarRent
|
||||
}
|
||||
try
|
||||
{
|
||||
var model = new RentalBindingModel
|
||||
RentalBindingModel model;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
{
|
||||
var rent = _rentalLogic.ReadElement(new RentalSearchModel { Id = _id });
|
||||
model = new RentalBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ReviewRating = Convert.ToInt32(numericUpDown.Value),
|
||||
ReviewText = textBoxReviewText.Text,
|
||||
ClientId = rent?.ClientId,
|
||||
CarId = rent?.CarId,
|
||||
StartDate = rent?.StartDate ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc),
|
||||
EndDate = rent?.EndDate,
|
||||
RentalCost = rent?.RentalCost ?? 0.0,
|
||||
};
|
||||
var operationResult = _id.HasValue && _id != 0 ? _rentalLogic.Update(model) : throw new Exception("Проблема с отзывом к аренде");
|
||||
}
|
||||
else
|
||||
{
|
||||
var rent = _rentalLogic.ReadElement(new RentalSearchModel { ObjectId = _objectId });
|
||||
model = new RentalBindingModel
|
||||
{
|
||||
ObjectId = _objectId ?? string.Empty,
|
||||
ReviewRating = Convert.ToInt32(numericUpDown.Value),
|
||||
ReviewText = textBoxReviewText.Text,
|
||||
ClientStringId = rent?.ClientStringId,
|
||||
CarStringId = rent?.CarStringId,
|
||||
StartDate = rent?.StartDate ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc),
|
||||
EndDate = rent?.EndDate,
|
||||
RentalCost = rent?.RentalCost ?? 0.0,
|
||||
};
|
||||
}
|
||||
var operationResult = _id.HasValue ? _rentalLogic.Update(model) : throw new Exception("Проблема с отзывом к аренде");
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
|
@ -25,8 +25,8 @@ namespace CarRent
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
/*try
|
||||
{*/
|
||||
var list = _carLogic.ReadList(null);
|
||||
|
||||
if (list != null)
|
||||
@ -37,9 +37,8 @@ namespace CarRent
|
||||
dataGridView.Columns["BranchId"].Visible = false;
|
||||
dataGridView.Columns["BranchStringId"].Visible = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ }
|
||||
/*}
|
||||
catch (Exception){ }*/
|
||||
}
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -63,6 +62,7 @@ namespace CarRent
|
||||
if (service is FormCreateCar form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
form.ObjectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString() ?? string.Empty;
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
@ -78,14 +78,14 @@ namespace CarRent
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
int? id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
string? objectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
if (!_carLogic.Delete(new CarBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL")
|
||||
&& !_carLogic.Delete(new CarBindingModel { Id = id ?? 0 })
|
||||
|| !_carLogic.Delete(new CarBindingModel { ObjectId = objectId ?? string.Empty }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении.");
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ namespace CarRent
|
||||
if (service is FormCreateClient form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
form.ObjectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString() ?? string.Empty;
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
@ -81,14 +82,13 @@ namespace CarRent
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
int? id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
string? objectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString();
|
||||
try
|
||||
{
|
||||
if (!_clientLogic.Delete(new ClientBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL")
|
||||
&& !_clientLogic.Delete(new ClientBindingModel { Id = id ?? 0 })
|
||||
|| !_clientLogic.Delete(new ClientBindingModel { ObjectId = objectId ?? string.Empty }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении.");
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ namespace CarRent
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var operationResult = _id.HasValue ? _branchLogic.Update(model) : _branchLogic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
@ -100,7 +99,7 @@ namespace CarRent
|
||||
|
||||
private void FormCreateBranch_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
if (_id.HasValue || !string.IsNullOrEmpty(_objectId))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -22,6 +22,8 @@ namespace CarRent
|
||||
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
private string? _objectId;
|
||||
public string ObjectId { set { _objectId = value; } }
|
||||
public FormCreateCar(ICarLogic carLogic,
|
||||
IBranchLogic branchLogic)
|
||||
{
|
||||
@ -39,13 +41,15 @@ namespace CarRent
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxBranch.DisplayMember = "Name";
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
comboBoxBranch.ValueMember = "Id";
|
||||
else
|
||||
comboBoxBranch.ValueMember = "ObjectId";
|
||||
comboBoxBranch.DataSource = list;
|
||||
comboBoxBranch.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ }
|
||||
catch (Exception){ }
|
||||
}
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -81,7 +85,10 @@ namespace CarRent
|
||||
}
|
||||
try
|
||||
{
|
||||
var model = new CarBindingModel
|
||||
CarBindingModel model;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
{
|
||||
model = new CarBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Brand = textBoxBrand.Text,
|
||||
@ -92,7 +99,23 @@ namespace CarRent
|
||||
RentalCostPerHour = Convert.ToDouble(textBoxRentalCost.Text),
|
||||
BranchId = Convert.ToInt32(comboBoxBranch.SelectedValue),
|
||||
};
|
||||
var operationResult = _id.HasValue ? _carLogic.Update(model) : _carLogic.Create(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new CarBindingModel
|
||||
{
|
||||
ObjectId = _objectId ?? string.Empty,
|
||||
Brand = textBoxBrand.Text,
|
||||
Model = textBoxModel.Text,
|
||||
YearOfManuf = DateTime.SpecifyKind(dateTimePicker.Value, DateTimeKind.Utc),
|
||||
Color = textBoxColor.Text,
|
||||
LicensePlate = textBoxLicensePlate.Text,
|
||||
RentalCostPerHour = Convert.ToDouble(textBoxRentalCost.Text),
|
||||
BranchStringId = comboBoxBranch.SelectedValue.ToString(),
|
||||
};
|
||||
}
|
||||
|
||||
var operationResult = _id.HasValue || !string.IsNullOrEmpty(_objectId) ? _carLogic.Update(model) : _carLogic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using CarRentContracts.BindingModels;
|
||||
using CarRentContracts.BusinessLogicContracts;
|
||||
using CarRentContracts.SearchModels;
|
||||
using CarRentContracts.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -21,6 +22,8 @@ namespace CarRent
|
||||
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
private string? _objectId;
|
||||
public string ObjectId { set { _objectId = value; } }
|
||||
public FormCreateClient(IClientLogic clientLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -61,8 +64,10 @@ namespace CarRent
|
||||
return;
|
||||
}
|
||||
try
|
||||
{ ClientBindingModel model;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
{
|
||||
var model = new ClientBindingModel
|
||||
model = new ClientBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Name = textBoxName.Text,
|
||||
@ -71,6 +76,19 @@ namespace CarRent
|
||||
Email = textBoxEmail.Text,
|
||||
DriveLicenseNumber = textBoxDriveLicense.Text,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new ClientBindingModel
|
||||
{
|
||||
ObjectId = _objectId ?? string.Empty,
|
||||
Name = textBoxName.Text,
|
||||
PhoneNumber = textBoxPhoneNumber.Text,
|
||||
Surname = textBoxSurname.Text,
|
||||
Email = textBoxEmail.Text,
|
||||
DriveLicenseNumber = textBoxDriveLicense.Text,
|
||||
};
|
||||
}
|
||||
var operationResult = _id.HasValue ? _clientLogic.Update(model) : _clientLogic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
@ -101,7 +119,15 @@ namespace CarRent
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _clientLogic.ReadElement(new ClientSearchModel { Id = _id.Value });
|
||||
ClientViewModel? view;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
{
|
||||
view = _clientLogic.ReadElement(new ClientSearchModel { Id = _id });
|
||||
}
|
||||
else
|
||||
{
|
||||
view = _clientLogic.ReadElement(new ClientSearchModel { ObjectId = _objectId });
|
||||
}
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
|
@ -26,6 +26,8 @@ namespace CarRent
|
||||
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
private string? _objectId;
|
||||
public string ObjectId { set { _objectId = value; } }
|
||||
public FormCreateRental(ICarLogic carLogic,
|
||||
IClientLogic clientLogic,
|
||||
IRentalLogic rentalLogic)
|
||||
@ -47,20 +49,25 @@ namespace CarRent
|
||||
if (listClients != null)
|
||||
{
|
||||
comboBoxClient.DisplayMember = "Name";
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
comboBoxClient.ValueMember = "Id";
|
||||
else
|
||||
comboBoxClient.ValueMember = "ObjectId";
|
||||
comboBoxClient.DataSource = listClients;
|
||||
comboBoxClient.SelectedItem = null;
|
||||
}
|
||||
if (listCars != null)
|
||||
{
|
||||
comboBoxCar.DisplayMember = "LicensePlate";
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
comboBoxCar.ValueMember = "Id";
|
||||
else
|
||||
comboBoxCar.ValueMember = "ObjectId";
|
||||
comboBoxCar.DataSource = listCars;
|
||||
comboBoxCar.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{ }
|
||||
catch (Exception){ }
|
||||
}
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -81,7 +88,10 @@ namespace CarRent
|
||||
}
|
||||
try
|
||||
{
|
||||
var model = new RentalBindingModel
|
||||
RentalBindingModel model;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
{
|
||||
model = new RentalBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
StartDate = DateTime.SpecifyKind(dateTimePickerStart.Value, DateTimeKind.Utc),
|
||||
@ -90,6 +100,19 @@ namespace CarRent
|
||||
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
|
||||
CarId = Convert.ToInt32(comboBoxCar.SelectedValue),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new RentalBindingModel
|
||||
{
|
||||
ObjectId = _objectId ?? string.Empty,
|
||||
StartDate = DateTime.SpecifyKind(dateTimePickerStart.Value, DateTimeKind.Utc),
|
||||
EndDate = DateTime.SpecifyKind(dateTimePickerEnd.Value, DateTimeKind.Utc),
|
||||
RentalCost = Convert.ToInt32(Math.Round(Convert.ToDouble(textBoxCost.Text))),
|
||||
ClientStringId = comboBoxClient.SelectedValue.ToString(),
|
||||
CarStringId = comboBoxCar.SelectedValue.ToString(),
|
||||
};
|
||||
}
|
||||
var operationResult = _id.HasValue ? _rentalLogic.Update(model) : _rentalLogic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
@ -121,12 +144,20 @@ namespace CarRent
|
||||
{
|
||||
try
|
||||
{
|
||||
var view = _rentalLogic.ReadElement(new RentalSearchModel { Id = _id.Value });
|
||||
RentalViewModel? view;
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
{
|
||||
view = _rentalLogic.ReadElement(new RentalSearchModel { Id = _id });
|
||||
}
|
||||
else
|
||||
{
|
||||
view = _rentalLogic.ReadElement(new RentalSearchModel { ObjectId = _objectId });
|
||||
}
|
||||
|
||||
if (view != null)
|
||||
{
|
||||
comboBoxClient.SelectedValue = view.ClientId;
|
||||
comboBoxCar.SelectedValue = view.CarId;
|
||||
comboBoxClient.SelectedValue = view.ClientStringId;
|
||||
comboBoxCar.SelectedValue = view.CarStringId;
|
||||
dateTimePickerStart.Value = view.StartDate;
|
||||
dateTimePickerEnd.Value = view.EndDate ?? DateTime.Now;
|
||||
textBoxCost.Text = Math.Round(view.RentalCost, 2).ToString();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using CarRentContracts.BindingModels;
|
||||
using CarRentContracts.BusinessLogicContracts;
|
||||
using CarRentContracts.SearchModels;
|
||||
using CarRentContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -43,7 +44,10 @@ namespace CarRent
|
||||
if (listClients != null)
|
||||
{
|
||||
comboBoxClientsEmail.DisplayMember = "Email";
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
comboBoxClientsEmail.ValueMember = "Id";
|
||||
else
|
||||
comboBoxClientsEmail.ValueMember = "ObjectId";
|
||||
comboBoxClientsEmail.DataSource = listClients;
|
||||
comboBoxClientsEmail.SelectedItem = null;
|
||||
}
|
||||
@ -67,6 +71,16 @@ namespace CarRent
|
||||
{
|
||||
ClientId = id,
|
||||
});
|
||||
|
||||
dataGridView.DataSource = list;
|
||||
}
|
||||
private void LoadData(string objectId)
|
||||
{
|
||||
var list = _rentalLogic.ReadList(new RentalSearchModel
|
||||
{
|
||||
ClientStringId = objectId,
|
||||
});
|
||||
|
||||
dataGridView.DataSource = list;
|
||||
}
|
||||
private void филиалыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
@ -132,7 +146,7 @@ namespace CarRent
|
||||
if (service is FormAddReview form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
|
||||
form.ObjectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString() ?? string.Empty;
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
@ -152,7 +166,10 @@ namespace CarRent
|
||||
|
||||
private void comboBoxClientsEmail_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if(Program.CURRENT_DATABASE.Equals("PostgreSQL"))
|
||||
LoadData(Convert.ToInt32(comboBoxClientsEmail.SelectedValue));
|
||||
else
|
||||
LoadData(comboBoxClientsEmail.SelectedValue?.ToString());
|
||||
}
|
||||
|
||||
private void buttonChange_Click(object sender, EventArgs e)
|
||||
@ -164,6 +181,7 @@ namespace CarRent
|
||||
if (service is FormCreateRental form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
form.ObjectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString() ?? string.Empty;
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
@ -179,14 +197,14 @@ namespace CarRent
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
int? id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
string? objectId = dataGridView.SelectedRows[0].Cells["ObjectId"].Value.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
if (!_rentalLogic.Delete(new RentalBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
if (Program.CURRENT_DATABASE.Equals("PostgreSQL")
|
||||
&& !_rentalLogic.Delete(new RentalBindingModel { Id = id ?? 0 })
|
||||
|| !_rentalLogic.Delete(new RentalBindingModel { ObjectId = objectId ?? string.Empty }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении.");
|
||||
}
|
||||
|
@ -38,9 +38,7 @@ namespace CarRent
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _rentalLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value),
|
||||
_clientLogic.ReadList(null) ?? new(),
|
||||
_carLogic.ReadList(null) ?? new());
|
||||
var result = _rentalLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value));
|
||||
|
||||
textBoxInsertTime.Text = result;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using CarRentBusinessLogic.BusinessLogics;
|
||||
using CarRentContracts.BusinessLogicContracts;
|
||||
using CarRentContracts.StoragesContracts;
|
||||
using CarRentMongoDB.Implements;
|
||||
using CarRentDatabase.Implements;
|
||||
using ClientRentBusinessLogic.BusinessLogics;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
@ -10,7 +10,7 @@ namespace CarRent
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
public static string CURRENT_DATABASE = "MongoDB";
|
||||
public static string CURRENT_DATABASE = "PostgreSQL";
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
/// <summary>
|
||||
|
@ -18,11 +18,9 @@ namespace CarRentBusinessLogic.BusinessLogics
|
||||
{
|
||||
_rentalStorage = RentalStorage;
|
||||
}
|
||||
public string TestInsertList(int num,
|
||||
List<ClientViewModel> clients,
|
||||
List<CarViewModel> cars)
|
||||
public string TestInsertList(int num)
|
||||
{
|
||||
return _rentalStorage.TestInsertList(num, clients, cars);
|
||||
return _rentalStorage.TestInsertList(num);
|
||||
}
|
||||
public string TestReadList(int num)
|
||||
{
|
||||
|
@ -16,9 +16,7 @@ namespace CarRentContracts.BusinessLogicContracts
|
||||
bool Create(RentalBindingModel model);
|
||||
bool Update(RentalBindingModel model);
|
||||
bool Delete(RentalBindingModel model);
|
||||
public string TestInsertList(int num,
|
||||
List<ClientViewModel> clients,
|
||||
List<CarViewModel> cars);
|
||||
public string TestInsertList(int num);
|
||||
string TestReadList(int num);
|
||||
string TestJoinReadList(int num);
|
||||
void ClearEntity();
|
||||
|
@ -19,6 +19,7 @@ namespace CarRentContracts.SearchModels
|
||||
public string? DriveLicenseNumber { get; set; }
|
||||
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? ObjectId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace CarRentContracts.SearchModels
|
||||
|
||||
public int? ReviewRating { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string? ClientStringId { get; set; }
|
||||
public int? Id { get; set; }
|
||||
public string? ObjectId { get; set; }
|
||||
}
|
||||
|
@ -17,9 +17,7 @@ namespace CarRentContracts.StoragesContracts
|
||||
RentalViewModel? Insert(RentalBindingModel model);
|
||||
RentalViewModel? Update(RentalBindingModel model);
|
||||
RentalViewModel? Delete(RentalBindingModel model);
|
||||
string TestInsertList(int num,
|
||||
List<ClientViewModel> clients,
|
||||
List<CarViewModel> cars);
|
||||
string TestInsertList(int num);
|
||||
string TestReadList(int num);
|
||||
string TestJoinReadList(int num);
|
||||
void ClearEntity();
|
||||
|
@ -14,7 +14,7 @@ namespace CarRentDatabase
|
||||
optionsBuilder.UseNpgsql(@"
|
||||
Host=192.168.56.101;
|
||||
Port=5432;
|
||||
Database=SUBDLab4;
|
||||
Database=SUBDLab8;
|
||||
Username=postgres;
|
||||
Password=123");
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ namespace CarRentDatabase.Implements
|
||||
{
|
||||
var model = new BranchBindingModel
|
||||
{
|
||||
Id = 0,
|
||||
Name = faker.Company.CompanyName(),
|
||||
Address = faker.Address.FullAddress(),
|
||||
PhoneNumber = faker.Phone.PhoneNumber(),
|
||||
|
@ -44,7 +44,6 @@ namespace CarRentDatabase.Implements
|
||||
{
|
||||
var model = new CarBindingModel
|
||||
{
|
||||
Id = 0,
|
||||
Brand = faker.Vehicle.Manufacturer(),
|
||||
Model = faker.Vehicle.Model(),
|
||||
YearOfManuf = DateTime.SpecifyKind(faker.Date.Past(), DateTimeKind.Utc),
|
||||
|
@ -31,7 +31,6 @@ namespace CarRentDatabase.Implements
|
||||
{
|
||||
var model = new ClientBindingModel
|
||||
{
|
||||
Id = 0,
|
||||
Name = faker.Name.FirstName(),
|
||||
Surname = faker.Name.LastName(),
|
||||
PhoneNumber = faker.Phone.PhoneNumber(),
|
||||
@ -44,15 +43,15 @@ namespace CarRentDatabase.Implements
|
||||
}
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
if (string.IsNullOrEmpty(model.DriveLicenseNumber) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarRentDatabase();
|
||||
return context.Clients
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Name) && x.Name ==
|
||||
model.Name) ||
|
||||
(!string.IsNullOrEmpty(model.DriveLicenseNumber) && x.DriveLicenseNumber ==
|
||||
model.DriveLicenseNumber) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
@ -22,18 +22,22 @@ namespace CarRentDatabase.Implements
|
||||
string deleteAllQuery = "DELETE FROM \"Rentals\"";
|
||||
context.Database.ExecuteSqlRaw(deleteAllQuery);
|
||||
}
|
||||
public string TestInsertList(int num,
|
||||
List<ClientViewModel> clients,
|
||||
List<CarViewModel> cars)
|
||||
public string TestInsertList(int num)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
var faker = new Faker("ru");
|
||||
using var context = new CarRentDatabase();
|
||||
for(int i = 0; i < num; ++i)
|
||||
var clients = context.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
var cars = context.Cars
|
||||
.Include(x => x.Branch)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
var model = new RentalBindingModel
|
||||
{
|
||||
Id = 0,
|
||||
StartDate = DateTime.SpecifyKind(faker.Date.Past(), DateTimeKind.Utc),
|
||||
EndDate = DateTime.SpecifyKind(faker.Date.Future(), DateTimeKind.Utc),
|
||||
RentalCost = 25,
|
||||
|
@ -1,204 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarRentDatabase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarRentDatabase))]
|
||||
[Migration("20230412152855_Lab4")]
|
||||
partial class Lab4
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Branches");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("BranchId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Color")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("LicensePlate")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Model")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("RentalCostPerHour")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("YearOfManuf")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BranchId");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("DriveLicenseNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("EndDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("RentalCost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("ReviewRating")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ReviewText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Rentals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Branch", null)
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("BranchId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Car", "Car")
|
||||
.WithMany()
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRentDatabase.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarRentDatabase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarRentDatabase))]
|
||||
[Migration("20230425195232_lab4start")]
|
||||
partial class lab4start
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Branches");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("BranchId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Color")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("LicensePlate")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Model")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("RentalCostPerHour")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("YearOfManuf")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BranchId");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("DriveLicenseNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("EndDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("RentalCost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("ReviewRating")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ReviewText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Rentals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Branch", null)
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("BranchId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Car", "Car")
|
||||
.WithMany()
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRentDatabase.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class lab4start : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class lab4sybdfix : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Cars_Branches_BranchId",
|
||||
table: "Cars");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Password",
|
||||
table: "Clients");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "BranchId",
|
||||
table: "Cars",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Cars_Branches_BranchId",
|
||||
table: "Cars",
|
||||
column: "BranchId",
|
||||
principalTable: "Branches",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Cars_Branches_BranchId",
|
||||
table: "Cars");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Password",
|
||||
table: "Clients",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "BranchId",
|
||||
table: "Cars",
|
||||
type: "integer",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Cars_Branches_BranchId",
|
||||
table: "Cars",
|
||||
column: "BranchId",
|
||||
principalTable: "Branches",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarRentDatabase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarRentDatabase))]
|
||||
[Migration("20230426112015_lab4sybdfix2")]
|
||||
partial class lab4sybdfix2
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Branches");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BranchId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Color")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("LicensePlate")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Model")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("RentalCostPerHour")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("YearOfManuf")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BranchId");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("DriveLicenseNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("EndDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("RentalCost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("ReviewRating")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ReviewText")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Rentals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Branch", "Branch")
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("BranchId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Branch");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Car", "Car")
|
||||
.WithMany()
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRentDatabase.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class lab4sybdfix2 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ReviewText",
|
||||
table: "Rentals",
|
||||
type: "text",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ReviewRating",
|
||||
table: "Rentals",
|
||||
type: "integer",
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ReviewText",
|
||||
table: "Rentals",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
defaultValue: "",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ReviewRating",
|
||||
table: "Rentals",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarRentDatabase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarRentDatabase))]
|
||||
[Migration("20230426113038_lab4sybdfix3")]
|
||||
partial class lab4sybdfix3
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.5")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Branches");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BranchId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Color")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("LicensePlate")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Model")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("RentalCostPerHour")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<DateTime>("YearOfManuf")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BranchId");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("DriveLicenseNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("EndDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<double>("RentalCost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("ReviewRating")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ReviewText")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.ToTable("Rentals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Branch", "Branch")
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("BranchId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Branch");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.HasOne("CarRentDatabase.Models.Car", "Car")
|
||||
.WithMany()
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarRentDatabase.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class lab4sybdfix3 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarRentDatabase))]
|
||||
[Migration("20230426104558_lab4sybdfix")]
|
||||
partial class lab4sybdfix
|
||||
[Migration("20230508170702_lab8")]
|
||||
partial class lab8
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -27,11 +27,11 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
@ -52,13 +52,14 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<int>("BranchId")
|
||||
b.Property<int?>("BranchId")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
@ -92,11 +93,11 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<string>("DriveLicenseNumber")
|
||||
.IsRequired()
|
||||
@ -125,16 +126,18 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
b.Property<int?>("CarId")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
b.Property<int?>("ClientId")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("EndDate")
|
||||
@ -145,11 +148,9 @@ namespace CarRentDatabase.Migrations
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int?>("ReviewRating")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ReviewText")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace CarRentDatabase.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Lab4 : Migration
|
||||
public partial class lab8 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@ -37,7 +37,6 @@ namespace CarRentDatabase.Migrations
|
||||
Surname = table.Column<string>(type: "text", nullable: false),
|
||||
PhoneNumber = table.Column<string>(type: "text", nullable: false),
|
||||
Email = table.Column<string>(type: "text", nullable: false),
|
||||
Password = table.Column<string>(type: "text", nullable: false),
|
||||
DriveLicenseNumber = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
@ -57,7 +56,7 @@ namespace CarRentDatabase.Migrations
|
||||
Color = table.Column<string>(type: "text", nullable: false),
|
||||
LicensePlate = table.Column<string>(type: "text", nullable: false),
|
||||
RentalCostPerHour = table.Column<double>(type: "double precision", nullable: false),
|
||||
BranchId = table.Column<int>(type: "integer", nullable: true)
|
||||
BranchId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -66,7 +65,8 @@ namespace CarRentDatabase.Migrations
|
||||
name: "FK_Cars_Branches_BranchId",
|
||||
column: x => x.BranchId,
|
||||
principalTable: "Branches",
|
||||
principalColumn: "Id");
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
@ -78,8 +78,8 @@ namespace CarRentDatabase.Migrations
|
||||
StartDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
EndDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
RentalCost = table.Column<double>(type: "double precision", nullable: false),
|
||||
ReviewText = table.Column<string>(type: "text", nullable: false),
|
||||
ReviewRating = table.Column<int>(type: "integer", nullable: false),
|
||||
ReviewText = table.Column<string>(type: "text", nullable: true),
|
||||
ReviewRating = table.Column<int>(type: "integer", nullable: true),
|
||||
ClientId = table.Column<int>(type: "integer", nullable: false),
|
||||
CarId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
@ -24,11 +24,11 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Branch", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
@ -49,13 +49,14 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<int>("BranchId")
|
||||
b.Property<int?>("BranchId")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Brand")
|
||||
@ -89,11 +90,11 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<string>("DriveLicenseNumber")
|
||||
.IsRequired()
|
||||
@ -122,16 +123,18 @@ namespace CarRentDatabase.Migrations
|
||||
|
||||
modelBuilder.Entity("CarRentDatabase.Models.Rental", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int?>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
b.Property<int?>("CarId")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
b.Property<int?>("ClientId")
|
||||
.IsRequired()
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("EndDate")
|
||||
|
@ -36,13 +36,13 @@ namespace CarRentMongoDB.Implements
|
||||
}
|
||||
public BranchViewModel? GetElement(BranchSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && model.ObjectId.Equals(string.Empty))
|
||||
if (string.IsNullOrEmpty(model.Name) && string.IsNullOrEmpty(model.ObjectId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new CarRentMongoDB())
|
||||
{
|
||||
var _branches = context.GetCollection<Branch>("Branches");
|
||||
var branches = context.GetCollection<Branch>("Branches");
|
||||
|
||||
var filterBuilder = Builders<Branch>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
@ -50,11 +50,11 @@ namespace CarRentMongoDB.Implements
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.Name, model.Name);
|
||||
}
|
||||
if (model.ObjectId.Equals(string.Empty))
|
||||
if (!string.IsNullOrEmpty(model.ObjectId))
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.ObjectId, model.ObjectId);
|
||||
}
|
||||
return _branches.Find(filter)
|
||||
return branches.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
@ -67,22 +67,23 @@ namespace CarRentMongoDB.Implements
|
||||
return new List<BranchViewModel>();
|
||||
}
|
||||
using var context = new CarRentMongoDB();
|
||||
var _branches = context.GetCollection<Branch>("Branches");
|
||||
var branches = context.GetCollection<Branch>("Branches");
|
||||
|
||||
var filterBuilder = Builders<Branch>.Filter;
|
||||
var filter = filterBuilder
|
||||
.Regex(x => x.Name, new BsonRegularExpression(model.Name));
|
||||
var branches = _branches
|
||||
return branches
|
||||
.Find(filter)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return branches.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<BranchViewModel> GetFullList()
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var _branches = context.GetCollection<Branch>("Branches");
|
||||
return _branches.Find(Builders<Branch>.Filter.Empty)
|
||||
var branches = context.GetCollection<Branch>("Branches");
|
||||
return branches.Find(Builders<Branch>.Filter.Empty)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -90,39 +91,39 @@ namespace CarRentMongoDB.Implements
|
||||
|
||||
public BranchViewModel? Insert(BranchBindingModel model)
|
||||
{
|
||||
using (var context = new CarRentMongoDB())
|
||||
{
|
||||
var _branches = context.GetCollection<Branch>("Branches");
|
||||
using var context = new CarRentMongoDB();
|
||||
|
||||
var branches = context.GetCollection<Branch>("Branches");
|
||||
|
||||
var branch = Branch.Create(model);
|
||||
_branches.InsertOne(branch);
|
||||
branches.InsertOne(branch);
|
||||
return branch.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BranchViewModel? Update(BranchBindingModel model)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var _branches = context.GetCollection<Branch>("Branches");
|
||||
var branches = context.GetCollection<Branch>("Branches");
|
||||
|
||||
var filter = Builders<Branch>.Filter.Eq(x => x.ObjectId, model.ObjectId);
|
||||
var branch = _branches.Find(filter).FirstOrDefault();
|
||||
var branch = branches.Find(filter).FirstOrDefault();
|
||||
if (branch == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
branch.Update(model);
|
||||
_branches.ReplaceOne(filter, branch);
|
||||
branches.ReplaceOne(filter, branch);
|
||||
return branch.GetViewModel;
|
||||
}
|
||||
|
||||
public BranchViewModel? Delete(BranchBindingModel model)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var _branches = context.GetCollection<Branch>("Branches");
|
||||
var branches = context.GetCollection<Branch>("Branches");
|
||||
|
||||
var filter = Builders<Branch>.Filter.Eq(x => x.ObjectId, model.ObjectId);
|
||||
var branch = _branches.FindOneAndDelete(filter);
|
||||
var branch = branches.FindOneAndDelete(filter);
|
||||
return branch?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
@ -1,92 +1,163 @@
|
||||
using Bogus;
|
||||
using Bogus.DataSets;
|
||||
using CarRentContracts.BindingModels;
|
||||
using CarRentContracts.SearchModels;
|
||||
using CarRentContracts.StoragesContracts;
|
||||
using CarRentContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CarRentMongoDB.Models;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace CarRentMongoDB.Implements
|
||||
{
|
||||
public class CarStorage : ICarStorage
|
||||
{
|
||||
/*public void ClearEntity()
|
||||
{
|
||||
|
||||
}
|
||||
public CarViewModel? GetElement(CarSearchModel model)
|
||||
{
|
||||
|
||||
}
|
||||
public void CarInsertList(int num, List<BranchViewModel> branches)
|
||||
{
|
||||
|
||||
}
|
||||
public List<CarViewModel> GetFilteredList(CarSearchModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<CarViewModel> GetFullList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CarViewModel? Insert(CarBindingModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CarViewModel? Update(CarBindingModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CarViewModel? Delete(CarBindingModel model)
|
||||
{
|
||||
|
||||
}*/
|
||||
public void CarInsertList(int num, List<BranchViewModel> branches)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ClearEntity()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public CarViewModel? Delete(CarBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
context.GetCollection<Car>("Cars")
|
||||
.DeleteMany(Builders<Car>.Filter.Empty);
|
||||
}
|
||||
|
||||
public CarViewModel? GetElement(CarSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var cars = context.GetCollection<Car>("Cars");
|
||||
var filterBuilder = Builders<Car>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.LicensePlate))
|
||||
{
|
||||
filter = filterBuilder.Eq(c => c.LicensePlate, model.LicensePlate);
|
||||
}
|
||||
else if (model.Id.HasValue)
|
||||
{
|
||||
filter = filterBuilder.Eq(c => c.Id, model.Id.Value);
|
||||
}
|
||||
return cars.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public void CarInsertList(int num, List<BranchViewModel> branches)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var cars = context.GetCollection<Car>("Cars");
|
||||
var faker = new Faker("ru");
|
||||
var rnd = new Random();
|
||||
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
var model = new CarBindingModel
|
||||
{
|
||||
ObjectId = "",
|
||||
Brand = faker.Vehicle.Manufacturer(),
|
||||
Model = faker.Vehicle.Model(),
|
||||
YearOfManuf = DateTime.SpecifyKind(faker.Date.Past(), DateTimeKind.Utc),
|
||||
Color = "#" + rnd.Next(100000).ToString(),
|
||||
LicensePlate = faker.Vehicle.Vin(),
|
||||
RentalCostPerHour = rnd.Next(1000),
|
||||
BranchStringId = branches[rnd.Next(branches.Count)].ObjectId,
|
||||
};
|
||||
var car = Car.Create(model);
|
||||
cars.InsertOne(car);
|
||||
}
|
||||
}
|
||||
|
||||
public List<CarViewModel> GetFilteredList(CarSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var filterBuilder = Builders<Car>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
filter = filterBuilder.Eq(c => c.Id, model.Id);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.ObjectId))
|
||||
{
|
||||
filter = filterBuilder.Eq(c => c.ObjectId, model.ObjectId);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Brand))
|
||||
{
|
||||
filter = filterBuilder.Eq(c => c.Brand, model.Brand);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Color))
|
||||
{
|
||||
filter = filterBuilder.Eq(c => c.Color, model.Color);
|
||||
}
|
||||
else if (model.YearOfManuf.HasValue)
|
||||
{
|
||||
filter = filterBuilder.Gte(c => c.YearOfManuf, model.YearOfManuf.Value);
|
||||
}
|
||||
else if (model.RentalCostPerHour.HasValue)
|
||||
{
|
||||
filter = filterBuilder.Lte(c => c.RentalCostPerHour, model.RentalCostPerHour.Value);
|
||||
}
|
||||
var cars = context.GetCollection<Car>("Cars").Find(filter)
|
||||
.ToList();
|
||||
cars.ForEach(c =>
|
||||
{
|
||||
var filter = Builders<Branch>.Filter.Eq(x => x.ObjectId, c.BranchStringId);
|
||||
c.Branch = context.GetCollection<Branch>("Branches").Find(filter).FirstOrDefault();
|
||||
});
|
||||
return cars.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CarViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var cars = context.GetCollection<Car>("Cars").Find(Builders<Car>.Filter.Empty)
|
||||
.ToList();
|
||||
cars.ForEach(c =>
|
||||
{
|
||||
var filter = Builders<Branch>.Filter.Eq(x => x.ObjectId, c.BranchStringId);
|
||||
c.Branch = context.GetCollection<Branch>("Branches").Find(filter).FirstOrDefault();
|
||||
});
|
||||
return cars.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CarViewModel? Insert(CarBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var newCar = Car.Create(model);
|
||||
if (newCar == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new CarRentMongoDB();
|
||||
var cars = context.GetCollection<Car>("Cars");
|
||||
cars.InsertOne(newCar);
|
||||
return newCar.GetViewModel;
|
||||
}
|
||||
|
||||
public CarViewModel? Update(CarBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var cars = context.GetCollection<Car>("Cars");
|
||||
var filter = Builders<Car>.Filter.Eq(x => x.Id, model.Id);
|
||||
var component = cars.Find(filter).FirstOrDefault();
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
cars.ReplaceOne(filter, component);
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public CarViewModel? Delete(CarBindingModel model)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var cars = context.GetCollection<Car>("Cars");
|
||||
var filter = Builders<Car>.Filter.Eq(x => x.Id, model.Id);
|
||||
var element = cars.Find(filter).FirstOrDefault();
|
||||
if (element != null)
|
||||
{
|
||||
cars.DeleteOne(filter);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,86 +8,131 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Bogus;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Bson;
|
||||
using CarRentMongoDB.Models;
|
||||
|
||||
namespace CarRentMongoDB.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
/*public void ClearEntity()
|
||||
{
|
||||
|
||||
}
|
||||
public void ClientInsertList(int num)
|
||||
{
|
||||
|
||||
}
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
|
||||
}*/
|
||||
public void ClearEntity()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
context.GetCollection<Client>("Clients")
|
||||
.DeleteMany(Builders<Client>.Filter.Empty);
|
||||
}
|
||||
|
||||
public void ClientInsertList(int num)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
using var context = new CarRentMongoDB();
|
||||
var faker = new Faker("ru");
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var model = new ClientBindingModel
|
||||
{
|
||||
ObjectId = string.Empty,
|
||||
Name = faker.Name.FirstName(),
|
||||
Surname = faker.Name.LastName(),
|
||||
PhoneNumber = faker.Phone.PhoneNumber(),
|
||||
Email = faker.Internet.Email(),
|
||||
DriveLicenseNumber = rnd.Next(1000).ToString(),
|
||||
};
|
||||
context.GetCollection<Client>("Clients")
|
||||
.InsertOne(Client.Create(model));
|
||||
}
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (string.IsNullOrEmpty(model.DriveLicenseNumber)
|
||||
&& string.IsNullOrEmpty(model.ObjectId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new CarRentMongoDB())
|
||||
{
|
||||
var clients = context.GetCollection<Client>("Clients");
|
||||
|
||||
var filterBuilder = Builders<Client>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
if (!string.IsNullOrEmpty(model.DriveLicenseNumber))
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.DriveLicenseNumber, model.DriveLicenseNumber);
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ObjectId))
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.ObjectId, model.ObjectId);
|
||||
}
|
||||
return clients.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new List<ClientViewModel>();
|
||||
}
|
||||
using var context = new CarRentMongoDB();
|
||||
var clients = context.GetCollection<Client>("Clients");
|
||||
|
||||
var filterBuilder = Builders<Client>.Filter;
|
||||
var filter = filterBuilder
|
||||
.Regex(x => x.Name, new BsonRegularExpression(model.Name));
|
||||
return clients
|
||||
.Find(filter)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var clients = context.GetCollection<Client>("Clients");
|
||||
return clients.Find(Builders<Client>.Filter.Empty)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
|
||||
var clients = context.GetCollection<Client>("Clients");
|
||||
|
||||
var client = Client.Create(model);
|
||||
clients.InsertOne(client);
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var clients = context.GetCollection<Client>("Clients");
|
||||
|
||||
var filter = Builders<Client>.Filter.Eq(x => x.ObjectId, model.ObjectId);
|
||||
var client = clients.Find(filter).FirstOrDefault();
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
clients.ReplaceOne(filter, client);
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var clients = context.GetCollection<Client>("Clients");
|
||||
|
||||
var filter = Builders<Client>.Filter.Eq(x => x.ObjectId, model.ObjectId);
|
||||
var client = clients.FindOneAndDelete(filter);
|
||||
return client?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ using CarRentContracts.BindingModels;
|
||||
using CarRentContracts.SearchModels;
|
||||
using CarRentContracts.StoragesContracts;
|
||||
using CarRentContracts.ViewModels;
|
||||
using CarRentMongoDB.Models;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@ -14,101 +17,169 @@ namespace CarRentMongoDB.Implements
|
||||
{
|
||||
public class RentalStorage : IRentalStorage
|
||||
{
|
||||
/*public void ClearEntity()
|
||||
{
|
||||
|
||||
}
|
||||
public string TestInsertList(int num,
|
||||
List<ClientViewModel> clients,
|
||||
List<CarViewModel> cars)
|
||||
{
|
||||
|
||||
}
|
||||
public string TestReadList(int num)
|
||||
{
|
||||
|
||||
}
|
||||
public string TestJoinReadList(int num)
|
||||
{
|
||||
|
||||
}
|
||||
public RentalViewModel? GetElement(RentalSearchModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<RentalViewModel> GetFilteredList(RentalSearchModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public List<RentalViewModel> GetFullList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RentalViewModel? Insert(RentalBindingModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RentalViewModel? Update(RentalBindingModel model)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RentalViewModel? Delete(RentalBindingModel model)
|
||||
{
|
||||
|
||||
}*/
|
||||
public void ClearEntity()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
context.GetCollection<Rental>("Rentals")
|
||||
.DeleteMany(Builders<Rental>.Filter.Empty);
|
||||
}
|
||||
|
||||
public RentalViewModel? Delete(RentalBindingModel model)
|
||||
public string TestInsertList(int num)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Random rnd = new Random();
|
||||
using var context = new CarRentMongoDB();
|
||||
var faker = new Faker("ru");
|
||||
var clients = context.GetCollection<Client>("Clients").Find(Builders<Client>.Filter.Empty).ToList();
|
||||
var cars = context.GetCollection<Car>("Cars").Find(Builders<Car>.Filter.Empty).ToList();
|
||||
List<Rental> rentals = new List<Rental>();
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
var model = new RentalBindingModel
|
||||
{
|
||||
ObjectId = string.Empty,
|
||||
StartDate = DateTime.SpecifyKind(faker.Date.Past(), DateTimeKind.Utc),
|
||||
EndDate = DateTime.SpecifyKind(faker.Date.Future(), DateTimeKind.Utc),
|
||||
RentalCost = rnd.Next(10,100),
|
||||
ClientStringId = clients[rnd.Next(clients.Count)].ObjectId,
|
||||
CarStringId = cars[rnd.Next(cars.Count)].ObjectId,
|
||||
};
|
||||
rentals.Add(Rental.Create(model));
|
||||
}
|
||||
Stopwatch stopwatch = new();
|
||||
|
||||
stopwatch.Start();
|
||||
context.GetCollection<Rental>("Rentals")
|
||||
.InsertMany(rentals);
|
||||
stopwatch.Stop();
|
||||
return stopwatch.ElapsedMilliseconds.ToString();
|
||||
}
|
||||
public string TestReadList(int num)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
|
||||
Stopwatch stopwatch = new();
|
||||
|
||||
stopwatch.Start();
|
||||
var rentals = context.GetCollection<Rental>("Rentals")
|
||||
.Find(Builders<Rental>.Filter.Empty)
|
||||
.Sort(Builders<Rental>.Sort.Ascending(x => x.ObjectId))
|
||||
.Limit(num)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
stopwatch.Stop();
|
||||
return stopwatch.ElapsedMilliseconds.ToString();
|
||||
}
|
||||
public string TestJoinReadList(int num)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
Stopwatch stopwatch = new();
|
||||
|
||||
stopwatch.Start();
|
||||
var rentals = context.GetCollection<Rental>("Rentals").Find(Builders<Rental>.Filter.Empty)
|
||||
.ToList();
|
||||
rentals.ForEach(c =>
|
||||
{
|
||||
var filterCar = Builders<Car>.Filter.Eq(x => x.ObjectId, c.CarStringId);
|
||||
c.Car = context.GetCollection<Car>("Cars").Find(filterCar).FirstOrDefault();
|
||||
|
||||
var filterBranch = Builders<Branch>.Filter.Eq(x => x.ObjectId, c.Car.BranchStringId);
|
||||
c.Car.Branch = context.GetCollection<Branch>("Branches").Find(filterBranch).FirstOrDefault();
|
||||
|
||||
var filterClient = Builders<Client>.Filter.Eq(x => x.ObjectId, c.ClientStringId);
|
||||
c.Client = context.GetCollection<Client>("Clients").Find(filterClient).FirstOrDefault();
|
||||
});
|
||||
stopwatch.Stop();
|
||||
return stopwatch.ElapsedMilliseconds.ToString();
|
||||
}
|
||||
public RentalViewModel? GetElement(RentalSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var rentals = context.GetCollection<Rental>("Rentals");
|
||||
if (string.IsNullOrEmpty(model.ObjectId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var rental = rentals.Find(x => x.ObjectId == model.ObjectId).FirstOrDefault();
|
||||
return rental?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<RentalViewModel> GetFilteredList(RentalSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
if (model.ObjectId == null && model.ClientStringId == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var filterBuilder = Builders<Rental>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
filter = filterBuilder.Gte(c => c.ClientStringId, model.ClientStringId);
|
||||
|
||||
var rentals = context.GetCollection<Rental>("Rentals").Find(filter)
|
||||
.ToList();
|
||||
rentals.ForEach(c =>
|
||||
{
|
||||
var filterCar = Builders<Car>.Filter.Eq(x => x.ObjectId, c.CarStringId);
|
||||
c.Car = context.GetCollection<Car>("Cars").Find(filterCar).FirstOrDefault();
|
||||
|
||||
var filterClient = Builders<Client>.Filter.Eq(x => x.ObjectId, c.ClientStringId);
|
||||
c.Client = context.GetCollection<Client>("Clients").Find(filterClient).FirstOrDefault();
|
||||
});
|
||||
return rentals.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<RentalViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var rentals = context.GetCollection<Rental>("Rentals").Find(Builders<Rental>.Filter.Empty)
|
||||
.ToList();
|
||||
rentals.ForEach(c =>
|
||||
{
|
||||
var filterCar = Builders<Car>.Filter.Eq(x => x.ObjectId, c.CarStringId);
|
||||
c.Car = context.GetCollection<Car>("Cars").Find(filterCar).FirstOrDefault();
|
||||
|
||||
var filterClient = Builders<Client>.Filter.Eq(x => x.ObjectId, c.ClientStringId);
|
||||
c.Client = context.GetCollection<Client>("Clients").Find(filterClient).FirstOrDefault();
|
||||
});
|
||||
return rentals.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public RentalViewModel? Insert(RentalBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string TestInsertList(int num, List<ClientViewModel> clients, List<CarViewModel> cars)
|
||||
var newRental = Rental.Create(model);
|
||||
if (newRental == null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return null;
|
||||
}
|
||||
|
||||
public string TestJoinReadList(int num)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string TestReadList(int num)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
context.GetCollection<Rental>("Rentals").InsertOne(newRental);
|
||||
return newRental.GetViewModel;
|
||||
}
|
||||
|
||||
public RentalViewModel? Update(RentalBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new CarRentMongoDB();
|
||||
var component = context.GetCollection<Rental>("Rentals")
|
||||
.Find(x => x.ObjectId == model.ObjectId).FirstOrDefault();
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.GetCollection<Rental>("Rentals").ReplaceOne(x => x.ObjectId == model.ObjectId, component);
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public RentalViewModel? Delete(RentalBindingModel model)
|
||||
{
|
||||
using var context = new CarRentMongoDB();
|
||||
var element = context.GetCollection<Rental>("Rentals").Find(x => x.ObjectId == model.ObjectId).FirstOrDefault();
|
||||
if (element != null)
|
||||
{
|
||||
context.GetCollection<Rental>("Rentals").DeleteOne(x => x.ObjectId == model.ObjectId);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ namespace CarRentMongoDB.Models
|
||||
[BsonIgnoreIfNull]
|
||||
public List<Rental> RentalCars { get; set; } = new List<Rental>();
|
||||
|
||||
[BsonRequired]
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual Branch Branch { get; set; }
|
||||
|
||||
public static Car? Create(CarBindingModel model)
|
||||
|
@ -33,9 +33,11 @@ namespace CarRentMongoDB.Models
|
||||
public double RentalCost { get; set; }
|
||||
|
||||
[BsonElement("review_text")]
|
||||
[BsonIgnoreIfNull]
|
||||
public string? ReviewText { get; set; }
|
||||
|
||||
[BsonElement("review_rating")]
|
||||
[BsonIgnoreIfNull]
|
||||
public int? ReviewRating { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
@ -45,7 +47,13 @@ namespace CarRentMongoDB.Models
|
||||
[BsonRequired]
|
||||
[BsonElement("car_id")]
|
||||
public string? CarStringId { get; set; }
|
||||
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual Car Car { get; set; }
|
||||
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public static Rental? Create(RentalBindingModel? model)
|
||||
@ -72,6 +80,11 @@ namespace CarRentMongoDB.Models
|
||||
{
|
||||
return;
|
||||
}
|
||||
CarStringId = model.CarStringId;
|
||||
ClientStringId = model.ClientStringId;
|
||||
StartDate = model.StartDate;
|
||||
EndDate = model.EndDate;
|
||||
RentalCost = model.RentalCost;
|
||||
ReviewText = model.ReviewText;
|
||||
ReviewRating = model.ReviewRating;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user