Esempio n. 1
0
        public ActionResult Create(EventsModelInput model)
        {
            try
            {
                var eventsDto = GenerateDto(model);

                var res = _manager.AddEvents(eventsDto);

                return(Json(new ResultModel {
                    Error = res ? string.Empty : "Error during the save in db!"
                }));
            }
            catch (Exception ex)
            {
                return(Json(new ResultModel {
                    Error = "Error during the save process!"
                }));
            }
        }
Esempio n. 2
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);
                }
            }
        }