|
@@ -1,9 +1,11 @@
|
|
-using Prism.Mvvm;
|
|
|
|
|
|
+using Prism.Commands;
|
|
|
|
+using Prism.Mvvm;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using System.Windows;
|
|
|
|
|
|
namespace DontHarmDesktop.ViewModels
|
|
namespace DontHarmDesktop.ViewModels
|
|
{
|
|
{
|
|
@@ -12,10 +14,37 @@ namespace DontHarmDesktop.ViewModels
|
|
public string Name { get; set; }
|
|
public string Name { get; set; }
|
|
public float Price { get; set; }
|
|
public float Price { get; set; }
|
|
public string Code { get; set; }
|
|
public string Code { get; set; }
|
|
|
|
+ public DelegateCommand Submit { get; set; }
|
|
|
|
|
|
public ServiceAddViewModel()
|
|
public ServiceAddViewModel()
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ Submit = new DelegateCommand(SubmitExecuted);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void SubmitExecuted()
|
|
|
|
+ {
|
|
|
|
+ // Валидация
|
|
|
|
+ decimal price = (decimal)Price;
|
|
|
|
+ List<string> errors = new List<string>();
|
|
|
|
+ bool isValid = Validation.CheckService(Code, price, Name, errors);
|
|
|
|
+
|
|
|
|
+ if (!isValid)
|
|
|
|
+ {
|
|
|
|
+ Validation.DisplayErrors(errors);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var service = new Models.services
|
|
|
|
+ {
|
|
|
|
+ name = Name,
|
|
|
|
+ code = Code,
|
|
|
|
+ price = (decimal)Price
|
|
|
|
+ };
|
|
|
|
+ var db = new DontHarmDesktop.Models.Entities();
|
|
|
|
+ db.services.Add(service);
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+
|
|
|
|
+ (App.Current.MainWindow as MainWindow).MainFrame.Navigate(new Pages.Services());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|