5. Тест бд, создание Models и Implements
This commit is contained in:
parent
def5df21d0
commit
d4903934ea
173
LawFirm/LawFirm/FormRegistrationCustomer.Designer.cs
generated
Normal file
173
LawFirm/LawFirm/FormRegistrationCustomer.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
namespace LawFirmView
|
||||||
|
{
|
||||||
|
partial class FormRegistrationCustomer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.textBoxLogin = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxPassword = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxSurname = new System.Windows.Forms.TextBox();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
|
this.label4 = new System.Windows.Forms.Label();
|
||||||
|
this.buttonRegister = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAuthorize = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// textBoxLogin
|
||||||
|
//
|
||||||
|
this.textBoxLogin.Location = new System.Drawing.Point(121, 47);
|
||||||
|
this.textBoxLogin.Name = "textBoxLogin";
|
||||||
|
this.textBoxLogin.Size = new System.Drawing.Size(100, 23);
|
||||||
|
this.textBoxLogin.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// textBoxPassword
|
||||||
|
//
|
||||||
|
this.textBoxPassword.Location = new System.Drawing.Point(121, 76);
|
||||||
|
this.textBoxPassword.Name = "textBoxPassword";
|
||||||
|
this.textBoxPassword.Size = new System.Drawing.Size(100, 23);
|
||||||
|
this.textBoxPassword.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(121, 105);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(100, 23);
|
||||||
|
this.textBoxName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// textBoxSurname
|
||||||
|
//
|
||||||
|
this.textBoxSurname.Location = new System.Drawing.Point(121, 134);
|
||||||
|
this.textBoxSurname.Name = "textBoxSurname";
|
||||||
|
this.textBoxSurname.Size = new System.Drawing.Size(100, 23);
|
||||||
|
this.textBoxSurname.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(32, 50);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(41, 15);
|
||||||
|
this.label1.TabIndex = 1;
|
||||||
|
this.label1.Text = "Логин";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(32, 79);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(49, 15);
|
||||||
|
this.label2.TabIndex = 1;
|
||||||
|
this.label2.Text = "Пароль";
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
this.label3.AutoSize = true;
|
||||||
|
this.label3.Location = new System.Drawing.Point(32, 108);
|
||||||
|
this.label3.Name = "label3";
|
||||||
|
this.label3.Size = new System.Drawing.Size(31, 15);
|
||||||
|
this.label3.TabIndex = 1;
|
||||||
|
this.label3.Text = "Имя";
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
this.label4.AutoSize = true;
|
||||||
|
this.label4.Location = new System.Drawing.Point(32, 137);
|
||||||
|
this.label4.Name = "label4";
|
||||||
|
this.label4.Size = new System.Drawing.Size(58, 15);
|
||||||
|
this.label4.TabIndex = 1;
|
||||||
|
this.label4.Text = "Фамилия";
|
||||||
|
//
|
||||||
|
// buttonRegister
|
||||||
|
//
|
||||||
|
this.buttonRegister.Location = new System.Drawing.Point(32, 176);
|
||||||
|
this.buttonRegister.Name = "buttonRegister";
|
||||||
|
this.buttonRegister.Size = new System.Drawing.Size(131, 23);
|
||||||
|
this.buttonRegister.TabIndex = 2;
|
||||||
|
this.buttonRegister.Text = "Зарегистрироваться";
|
||||||
|
this.buttonRegister.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRegister.Click += new System.EventHandler(this.buttonRegister_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(209, 176);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(131, 23);
|
||||||
|
this.buttonCancel.TabIndex = 2;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// buttonAuthorize
|
||||||
|
//
|
||||||
|
this.buttonAuthorize.Location = new System.Drawing.Point(227, 47);
|
||||||
|
this.buttonAuthorize.Name = "buttonAuthorize";
|
||||||
|
this.buttonAuthorize.Size = new System.Drawing.Size(113, 110);
|
||||||
|
this.buttonAuthorize.TabIndex = 3;
|
||||||
|
this.buttonAuthorize.Text = "Авторизоваться";
|
||||||
|
this.buttonAuthorize.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormRegistrationCustomer
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(394, 243);
|
||||||
|
this.Controls.Add(this.buttonAuthorize);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonRegister);
|
||||||
|
this.Controls.Add(this.label4);
|
||||||
|
this.Controls.Add(this.label3);
|
||||||
|
this.Controls.Add(this.label2);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.Controls.Add(this.textBoxSurname);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.textBoxPassword);
|
||||||
|
this.Controls.Add(this.textBoxLogin);
|
||||||
|
this.Name = "FormRegistrationCustomer";
|
||||||
|
this.Text = "FormRegistrationCustomer";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private TextBox textBoxLogin;
|
||||||
|
private TextBox textBoxPassword;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxSurname;
|
||||||
|
private Label label1;
|
||||||
|
private Label label2;
|
||||||
|
private Label label3;
|
||||||
|
private Label label4;
|
||||||
|
private Button buttonRegister;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonAuthorize;
|
||||||
|
}
|
||||||
|
}
|
36
LawFirm/LawFirm/FormRegistrationCustomer.cs
Normal file
36
LawFirm/LawFirm/FormRegistrationCustomer.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace LawFirmView
|
||||||
|
{
|
||||||
|
public partial class FormRegistrationCustomer : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICustomerLogic _customerLogic;
|
||||||
|
public FormRegistrationCustomer(ILogger<FormRegistrationCustomer> logger, ICustomerLogic customerLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_customerLogic = customerLogic;
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
private void buttonRegister_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_customerLogic.Create(new()
|
||||||
|
{
|
||||||
|
Login = textBoxLogin.Text,
|
||||||
|
Password = textBoxPassword.Text,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Surname = textBoxSurname.Text
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,43 @@
|
|||||||
using LawFirmDatabase;
|
using LawFirmBusinessLogic.BusinessLogics;
|
||||||
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmDatabase.Implements;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
namespace LawFirmView
|
namespace LawFirmView
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
private static ServiceProvider? _serviceProvider;
|
||||||
/// The main entry point for the application.
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run();
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormRegistrationCustomer>());
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
|
//áóäóò äîáàâëåíû Storage
|
||||||
|
services.AddTransient<ICaseLogic, CaseLogic>();
|
||||||
|
services.AddTransient<ICustomerLogic, CustomerLogic>();
|
||||||
|
services.AddTransient<IItemLogic, ItemLogic>();
|
||||||
|
services.AddTransient<IPaymentLogic, PaymentLogic>();
|
||||||
|
services.AddTransient<IServiceLogic, ServiceLogic>();
|
||||||
|
|
||||||
|
services.AddTransient<ICustomerStorage, CustomerStorage>();
|
||||||
|
|
||||||
|
services.AddTransient<FormRegistrationCustomer>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,5 +9,6 @@ namespace LawFirmContracts.SearchModels
|
|||||||
public class ItemSearchModel
|
public class ItemSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
76
LawFirm/LawFirmDatabase/Implements/CaseStorage.cs
Normal file
76
LawFirm/LawFirmDatabase/Implements/CaseStorage.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class CaseStorage : ICaseStorage
|
||||||
|
{
|
||||||
|
public List<CaseViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Cases.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<CaseViewModel> GetFilteredList(CaseSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Cases.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public CaseViewModel? GetElement(CaseSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Cases.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CaseViewModel? Insert(CaseBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newCase = Case.Create(context, model);
|
||||||
|
if (newCase != null)
|
||||||
|
{
|
||||||
|
context.Cases.Add(newCase);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newCase.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CaseViewModel? Update(CaseBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var casee = context.Cases.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (casee == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
casee.Update(context, model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return casee.GetViewModel;
|
||||||
|
}
|
||||||
|
public CaseViewModel? Delete(CaseBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var casee = context.Cases.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (casee == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Cases.Remove(casee);
|
||||||
|
context.SaveChanges();
|
||||||
|
return casee.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
76
LawFirm/LawFirmDatabase/Implements/CustomerStorage.cs
Normal file
76
LawFirm/LawFirmDatabase/Implements/CustomerStorage.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class CustomerStorage : ICustomerStorage
|
||||||
|
{
|
||||||
|
public List<CustomerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Customers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<CustomerViewModel> GetFilteredList(CustomerSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Customers.Select(x => x.GetViewModel).Where(x => x.Id == model.Id).ToList();
|
||||||
|
}
|
||||||
|
public CustomerViewModel? GetElement(CustomerSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Customers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(model.Login))
|
||||||
|
{
|
||||||
|
return context.Customers.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CustomerViewModel? Insert(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newCustomer = Customer.Create(model);
|
||||||
|
if (newCustomer != null)
|
||||||
|
{
|
||||||
|
context.Customers.Add(newCustomer);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newCustomer.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CustomerViewModel? Update(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var customer = context.Customers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (customer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
customer.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return customer.GetViewModel;
|
||||||
|
}
|
||||||
|
public CustomerViewModel? Delete(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var customer = context.Customers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (customer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Customers.Remove(customer);
|
||||||
|
context.SaveChanges();
|
||||||
|
return customer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
82
LawFirm/LawFirmDatabase/Implements/ItemStorage.cs
Normal file
82
LawFirm/LawFirmDatabase/Implements/ItemStorage.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class ItemStorage : IItemStorage
|
||||||
|
{
|
||||||
|
public List<ItemViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Items.Include(x => x.Services).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<ItemViewModel> GetFilteredList(ItemSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Items.Where(x => x.Id == model.Id).Include(x => x.Services).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public ItemViewModel? GetElement(ItemSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Items.Include(x => x.Services).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
return context.Items.Include(x => x.Services).FirstOrDefault(x => x.Name == model.Name)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ItemViewModel? Insert(ItemBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newItem = Item.Create(context, model);
|
||||||
|
if (newItem != null)
|
||||||
|
{
|
||||||
|
context.Items.Add(newItem);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newItem.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ItemViewModel? Update(ItemBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var item = context.Items.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
item.Update(context, model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetViewModel;
|
||||||
|
}
|
||||||
|
public ItemViewModel? Delete(ItemBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var item = context.Items.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Items.Remove(item);
|
||||||
|
context.SaveChanges();
|
||||||
|
return item.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
83
LawFirm/LawFirmDatabase/Implements/PaymentStorage.cs
Normal file
83
LawFirm/LawFirmDatabase/Implements/PaymentStorage.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class PaymentStorage : IPaymentStorage
|
||||||
|
{
|
||||||
|
public List<PaymentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Payments
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<PaymentViewModel> GetFilteredList(PaymentSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Payments
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public PaymentViewModel? GetElement(PaymentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Payments
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public PaymentViewModel? Insert(PaymentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newPayment = Payment.Create(context, model);
|
||||||
|
if (newPayment != null)
|
||||||
|
{
|
||||||
|
context.Payments.Add(newPayment);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newPayment.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public PaymentViewModel? Update(PaymentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var payment = context.Payments.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (payment == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
payment.Update(context, model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return payment.GetViewModel;
|
||||||
|
}
|
||||||
|
public PaymentViewModel? Delete(PaymentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var payment = context.Payments.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (payment == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Payments.Remove(payment);
|
||||||
|
context.SaveChanges();
|
||||||
|
return payment.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
89
LawFirm/LawFirmDatabase/Implements/ServiceStorage.cs
Normal file
89
LawFirm/LawFirmDatabase/Implements/ServiceStorage.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class ServiceStorage : IServiceStorage
|
||||||
|
{
|
||||||
|
public ServiceViewModel? Delete(ServiceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var service = context.Services.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (service == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Services.Remove(service);
|
||||||
|
context.SaveChanges();
|
||||||
|
return service.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceViewModel? GetElement(ServiceSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Services
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ServiceViewModel> GetFilteredList(ServiceSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Services
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ServiceViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Services
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceViewModel? Insert(ServiceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newService = Service.Create(context, model);
|
||||||
|
if (newService != null)
|
||||||
|
{
|
||||||
|
context.Services.Add(newService);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newService.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceViewModel? Update(ServiceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var service = context.Services.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (service == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
service.Update(context, model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return service.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -52,7 +52,7 @@ namespace LawFirmDatabase.Models
|
|||||||
Customer = context.Customers.First(x => x.Id == model.CustomerId);
|
Customer = context.Customers.First(x => x.Id == model.CustomerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CaseViewModel? GetViewModel() => new()
|
public CaseViewModel? GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
|
@ -54,13 +54,13 @@ namespace LawFirmDatabase.Models
|
|||||||
Surname = model.Surname;
|
Surname = model.Surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomerViewModel? GetViewModel() => new()
|
public CustomerViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Login = Login,
|
Login = Login,
|
||||||
Password = Password,
|
Password = Password,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Surname = Surname,
|
Surname = Surname
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ namespace LawFirmDatabase.Models
|
|||||||
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaymentViewModel? GetViewModel() => new()
|
public PaymentViewModel? GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
|
@ -54,7 +54,7 @@ namespace LawFirmDatabase.Models
|
|||||||
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceViewModel? GetViewModel() => new()
|
public ServiceViewModel? GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
|
Loading…
Reference in New Issue
Block a user