using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Common.CalendarManage;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.ViewModel;
using System.Linq.Expressions;
using EMIS.ViewModel.CalendarManage;
namespace EMIS.CommonLogic.CalendarManage
{
public class SCalendarServices : BaseServices, ISCalendarServices
{
public SCalendarDAL scalendarDAL { get; set; }
///
/// 查询校历信息
///
/// 查询条件实体
/// 活动类型
/// 时间段
/// 页码
/// 显示页数
///
public IGridResultSet GetSCalendarViewGrid(ConfiguretView configuretView, int? activitiesType, int? timesSegment, int pageIndex, int pageSize)
{
var query = scalendarDAL.GetSCalendarQueryable(x => true);
if (activitiesType.HasValue && activitiesType != -1)
query = query.Where(x => x.ActivitiesType == activitiesType);
if (timesSegment.HasValue && timesSegment != -1)
query = query.Where(x => x.TimesSegment == timesSegment);
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
.OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToGridResultSet(pageIndex, pageSize);
return query.OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询校历信息
///
/// 查询条件实体
/// 活动类型
/// 时间段
///
public List GetSCalendarViewList(ConfiguretView configuretView, int? activitiesType, int? timesSegment)
{
var query = scalendarDAL.GetSCalendarQueryable(x => true);
if (activitiesType.HasValue && activitiesType != -1)
query = query.Where(x => x.ActivitiesType == activitiesType);
if (timesSegment.HasValue && timesSegment != -1)
query = query.Where(x => x.TimesSegment == timesSegment);
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
.OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToList();
return query.OrderByDescending(x => x.ActivitiesTime).ThenBy(x => x.TimesSegment).ToList();
}
///
/// 获取校历信息
///
/// 主键ID
///
public CF_SCalendar GetSCalendar(Guid? activitiesID)
{
//查询条件
Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expression = (x => x.ActivitiesID == activitiesID);
return scalendarDAL.scalendarRepository.GetSingle(expression);
}
///
/// 获取校历信息
///
/// 活动名称
///
public CF_SCalendar GetSCalendar(string Name)
{
//查询条件
Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expression = (x => x.Name == Name);
return scalendarDAL.scalendarRepository.GetSingle(expression);
}
///
/// 获取校历信息
///
/// 主键ID
///
public SCalendarView GetSCalendarView(Guid? activitiesID)
{
SCalendarView scalendarView = new SCalendarView();
if (activitiesID.HasValue)
scalendarView = scalendarDAL.GetSCalendarQueryable(x => true).Where(x => x.ActivitiesID == activitiesID).FirstOrDefault();
return scalendarView;
}
///
/// 添加
///
/// 实体
///
public bool SCalendarAdd(SCalendarView scalendarView)
{
try
{
if (this.scalendarDAL.scalendarRepository
.GetList(x => x.Name == scalendarView.Name && x.ActivitiesTime == scalendarView.ActivitiesTime
&& x.TimesSegment == scalendarView.TimesSegment).Count() > 0)
{
throw new Exception("已存在相同的数据,请重新输入!");
}
CF_SCalendar scalendar = new CF_SCalendar();
scalendar.ActivitiesID = Guid.NewGuid();
scalendar.Name = scalendarView.Name;
scalendar.ActivitiesTime = scalendarView.ActivitiesTime.Value;
scalendar.TimesSegment = scalendarView.TimesSegment.Value;
scalendar.ActivitiesContent = scalendarView.ActivitiesContent;
scalendar.ActivitiesType = scalendarView.ActivitiesType;
this.SetNewStatus(scalendar);
UnitOfWork.Add(scalendar);
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 修改
///
/// 实体
///
public bool SCalendarUpdate(SCalendarView scalendarView)
{
try
{
if (this.scalendarDAL.scalendarRepository
.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
&& x.Name == scalendarView.Name && x.ActivitiesTime == scalendarView.ActivitiesTime
&& x.TimesSegment == scalendarView.TimesSegment && x.ActivitiesID != scalendarView.ActivitiesID).Count() > 0)
{
throw new Exception("活动名称已存在,请重新输入!");
}
var scalendar = GetSCalendar(scalendarView.ActivitiesID);
if (scalendar == null)
{
throw new Exception("未能找到相对应的数据!");
}
scalendar.Name = scalendarView.Name;
scalendar.ActivitiesTime = scalendarView.ActivitiesTime.Value;
scalendar.TimesSegment = scalendarView.TimesSegment.Value;
scalendar.ActivitiesContent = scalendarView.ActivitiesContent;
scalendar.ActivitiesType = scalendarView.ActivitiesType;
this.SetModifyStatus(scalendar);
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 删除
///
///
///
public bool SCalendarDelete(List activitiesIDs)
{
try
{
UnitOfWork.Delete(x => activitiesIDs.Contains(x.ActivitiesID));
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
}
}