Пример #1
0
        EventEntity AddEvent(EventsView entity, List <EventInviteEntity> inviteList)
        {
#if !DEBUG
            using (TransactionScope tran = new TransactionScope())
#endif
            {
                if (entity.Repeat != RepeatType.None && entity.End == EndType.on_date && entity.Times <= 1)
                {
                    var      times = entity.Times > -1 ? entity.Times : 0;
                    DateTime start = entity.FromDay;
                    while (start < entity.EndDate)
                    {
                        times++;
                        // calc next event date
                        switch (entity.Repeat)
                        {
                        case RepeatType.Every_Day:
                            start = start.AddDays(1);
                            break;

                        case RepeatType.Every_Week:
                            start = start.AddDays(7);
                            break;

                        case RepeatType.Every_two_weeks:
                            start = start.AddDays(2 * 7);
                            break;

                        case RepeatType.Every_Month:
                        case RepeatType.Every_Month_First_Friday:
                            start = start.AddMonths(1);
                            break;

                        case RepeatType.Every_Year:
                            start = start.AddYears(1);
                            break;
                        }
                    }
                    entity.Times = times;
                }
                //entity.CreatedOn = DateTime.Now;
                entity.UpdatedOn = DateTime.Now;
                entity.Highlight = false;

                bool result = false;
                entity.ID = mgr.AddEvents(entity, entity.Times, entity.IsOff);
                if (entity.ID > 0)
                {
                    result = mgr.AddEventInvites(entity, inviteList);
                }
                if (entity.IsOff)//如果选择了OFF的ticket,则添加TimeSheets
                {
                    result = AddTimeSheetsWithEvent(entity);
                }
#if !DEBUG
                if (result)
                {
                    tran.Complete();
                }
#endif
                if (result)
                {
                    return(entity);
                }
                else
                {
                    return(null);
                }
            }
        }