demo20230512/Service/WeeeCommentDataService.cs
2023-05-12 10:20:28 +08:00

38 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using Weee.DAL;
using Weee.Models;
namespace Weee.Service
{
public class WeeeCommentDataService: WeeeDataAuthorizeService
{
public WeeeCommentDataService(WeeeDataContext d)
: base(d)
{
}
public Comment SaveComment(Comment ToBeSave)
{
if (!AuthorizedLCAs.Contains(ToBeSave.LCAID)) throw new Exception("not authorized (comments)");
var LCA = _db.LCAs.Find((ToBeSave.LCAID));
if (LCA.Status != LCAStatus.Waiting) throw new Exception("business logic error , a lca not in waiting status");
var entry = _db.Entry(ToBeSave);
ToBeSave.UpdateTime = DateTime.Now;
if (ToBeSave.ID == 0)
{
entry.State = EntityState.Added;
}
else
{
entry.State = EntityState.Modified;
entry.Property(x => x.CreateTime).IsModified = false;
}
_db.SaveChanges();
return ToBeSave;
}
}
}