/
LayoutCrud.cs
69 lines (58 loc) · 1.81 KB
/
LayoutCrud.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Microsoft.AspNetCore.Http;
using MyCms.Bussiness.Services.Interfaces;
using MyCms.Common.Dtos;
using MyCms.Domain.Context;
using MyCms.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyCms.Bussiness.Services
{
public class LayoutCrud : ILayoutCrud
{
private MyCmsDbContext _dbContext;
public LayoutCrud(IHttpContextAccessor httpAccessor)
{
_dbContext = (MyCmsDbContext)httpAccessor.HttpContext.RequestServices.GetService(typeof(MyCmsDbContext));
}
public void AddLayout(LayoutDto layout)
{
if (layout.Name != null)
{
Layout newLayout = new Layout();
newLayout.Name = layout.Name;
newLayout.IsDeleted = false;
newLayout.CreateTime = DateTime.Now;
_dbContext.Layouts.Add(newLayout);
_dbContext.SaveChanges();
}
}
public void DeleteLayout(LayoutDto layout)
{
var model = _dbContext.Layouts.Find(layout.Id);
_dbContext.Layouts.Remove(model);
_dbContext.SaveChanges();
}
public LayoutDto GetLayoutById(string name)
{
throw new NotImplementedException();
}
public List<LayoutDto> GetLayouts()
{
IEnumerable<Layout> user = _dbContext.Layouts.ToList();
var model = user.Select(x => new LayoutDto
{
Id = x.Id,
CreateTime = x.CreateTime,
IsDeleted = x.IsDeleted,
Name = x.Name
}).ToList();
return model;
}
public void UpdateLayout(LayoutDto layout)
{
throw new NotImplementedException();
}
}
}