首页 > 解决方案 > ASP.NET MVC - 将结束日期与开始日期与已保存在数据库中的开始日期进行比较

问题描述

我的系统将按如下方式工作:我有一个开始日期和一个结束日期。当您进行约会时,它会插入开始日期并保存此数据。进行新约会时,用户应输入上次约会的结束日期。

我的问题是我如何将他输入的这个最终日期与银行中已经存在的明星日期进行比较。

我的想法是结束日期不小于或等于星日期

 I tried that way, but it will not work because I'm not picking the last start date in the dataBase to compare

public class finalDateoftheAppointmentCannotbeLessthantheStartDate : ISpecification<Appointment>
{
    public bool IsSatisfiedBy(InfoAppointment  infoAppointment)
    {
        return infoAppointment.EndDate<= infoApontamento.StarDate;
    }
}

我使用存储库:

那是我的存储库类,也许我们可以在这里搜索最后日期进行比较

   public virtual IEnumerable<TEntity> Buscar(Expression<Func<TEntity, bool>> predicate)
    {
        return Dbset.Where(predicate);
    }

public class InfoApontamentosRepository : Repository<InfoAppointment>, IAppointmentRepository
{
    public InfoAppointmentRepository(RveContext rveContext) : base(rveContext)
    {
    }

    public InfoAppointment FindLastStartDate(Date date)
    {
        throw new NotImplementedException();
    }

    //example
     public InfoApontamento FindByNumber(int number)
    {
        return Buscar(c => c.Atendimento == number).FirstOrDefault();
    }

总结一下:如何获取数据库中保存的最后一个初始日期并与用户输入的结束日期进行比较,以防止结束日期小于或等于开始日期

标签: c#sql-serverasp.net-mvcrepository

解决方案


推荐阅读