DemoService/AddEditWindow.axaml.cs
2024-09-09 16:26:07 +03:00

58 lines
1.8 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using DemoService.Context;
using DemoService.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Net;
namespace DemoService;
public partial class AddEditWindow : Window
{
private bool AdminMode;
public AddEditWindow()
{
InitializeComponent();
Icon = new WindowIcon(new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "/Assets/service_logo.ico"));
}
public AddEditWindow(bool AdminMode)
{
InitializeComponent();
this.AdminMode = AdminMode;
Icon = new WindowIcon(new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "/Assets/service_logo.ico"));
}
private void AddPictureButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
}
private void AddServiceButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
Service service = new Service()
{
Id = Utils.Context.Services.Count + 1,
Title = ServiceName.Text,
Cost = Convert.ToDecimal(Cost.Text),
DurationInSeconds = Convert.ToInt32(DurationInSeconds.Text),
Description = Description.Text,
Discount = Convert.ToDecimal(Discount.Text)
};
using (var context = new OvsyannikovContext())
{
context.Add(service);
context.SaveChanges();
}
Utils.Context.Services = new List<Service>(Utils.Context.DbContext.Services);
ServiceWindow serviceWindow = new(AdminMode);
serviceWindow.Show();
Close();
}
private void EditServiceButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
}
}