47 lines
1017 B
C#
47 lines
1017 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
using shoe_store.Models;
|
|
|
|
namespace shoe_store.Models
|
|
{
|
|
internal partial class Product : IEditableObject
|
|
{
|
|
Ispr2521TimofeevKoShoestoreContext context;
|
|
|
|
|
|
public void BeginEdit()
|
|
{
|
|
context = new();
|
|
context.Update(this);
|
|
}
|
|
|
|
|
|
public void CancelEdit()
|
|
{
|
|
var entry = context.Entry(this);
|
|
if (entry.State == Microsoft.EntityFrameworkCore.EntityState.Modified)
|
|
{
|
|
entry.Reload();
|
|
}
|
|
}
|
|
|
|
|
|
public void EndEdit()
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(ProductName))
|
|
{
|
|
throw new ValidationException("Имя не должно быть пустым");
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
|