Пример #1
0
        public bool CustomEventUpdate(int userId, DashboardEventToken token)
        {
            try
            {
                var uid    = token.Uid.ToString();
                var entity = CustomEventsRepository.Get(x => x.Uid == uid && x.UserId == userId);

                if (entity == null)
                {
                    return(false);
                }

                entity.Name  = token.Name;
                entity.Color = token.Color;
                if (token.Date != null)
                {
                    entity.Date = (DateTime)token.Date;
                }

                CustomEventsRepository.Update(entity);
                return(CustomEventsRepository.UnitOfWork.CommitAndRefreshChanges());
            }
            catch (Exception e)
            {
                Logger.Error("edit custom event", e, CommonEnums.LoggerObjectTypes.Dashboard);
                return(false);
            }
        }
Пример #2
0
 public static DB_CustomEvents Token2Entity(this DashboardEventToken token, int userId)
 {
     return(new DB_CustomEvents
     {
         UserId = userId,
         Color = token.Color,
         Date = (DateTime)token.Date,
         Name = token.Name,
         Uid = Guid.NewGuid().ToString()
     });
 }
Пример #3
0
 public bool CustomEventAdd(int userId, DashboardEventToken token)
 {
     try
     {
         var entity = token.Token2Entity(userId);
         token.Uid = Guid.Parse(entity.Uid);
         CustomEventsRepository.Add(entity);
         return(CustomEventsRepository.UnitOfWork.CommitAndRefreshChanges());
     }
     catch (Exception e)
     {
         Logger.Error("add custom event", e, CommonEnums.LoggerObjectTypes.Dashboard);
         return(false);
     }
 }
Пример #4
0
        public bool CustomEventRemove(int userId, DashboardEventToken token)
        {
            try
            {
                var uid    = token.Uid.ToString();
                var entity = CustomEventsRepository.Get(x => x.Uid == uid && x.UserId == userId);

                if (entity == null)
                {
                    return(false);
                }

                CustomEventsRepository.Delete(entity);

                return(CustomEventsRepository.UnitOfWork.CommitAndRefreshChanges());
            }
            catch (Exception e)
            {
                Logger.Error("remove custom event", e, CommonEnums.LoggerObjectTypes.Dashboard);
                return(false);
            }
        }
Пример #5
0
        public DashboardEventToken GetDashboardEventToken(int userId, DashboardEnums.eDbEventTypes type, DateRangeToken dates, string eventName = null)
        {
            var token = new DashboardEventToken
            {
                Uid        = Guid.NewGuid()
                , Type     = type
                , Name     = eventName ?? Utils.GetEnumDescription(type)
                , Color    = type.EventType2Color()
                , Enabled  = true
                , IsStatic = false
            };

            if (type == DashboardEnums.eDbEventTypes.Custom || type == DashboardEnums.eDbEventTypes.NewMailchimp)
            {
                return(token);
            }

            token.IsStatic = true;

            using (var context = new lfeAuthorEntities())
            {
                var evenStats = context.tvf_DB_GetAuthorEventStats(userId).FirstOrDefault();

                if (evenStats == null)
                {
                    return(token);
                }

                DateTime?date = null;

                switch (type)
                {
                case DashboardEnums.eDbEventTypes.NewItem:
                    var cd = evenStats.LastCoursePublish;
                    var bd = evenStats.LastBundlePublish;

                    if (cd == null && bd == null)
                    {
                        return(token);
                    }

                    date = (cd ?? DateTime.MinValue).CompareToDate(bd ?? DateTime.MinValue);
                    break;

                case DashboardEnums.eDbEventTypes.NewChapter:
                    date = evenStats.LastChaperCreated;
                    break;

                case DashboardEnums.eDbEventTypes.NewFbStore:
                    date = evenStats.LastChaperCreated;
                    break;

                case DashboardEnums.eDbEventTypes.NewStore:
                    date = evenStats.LastChaperCreated;
                    break;
                }

                token.Date    = date;
                token.Enabled = date != null && (((DateTime)date).Ticks >= dates.from.Ticks && ((DateTime)date).Ticks <= dates.to.Ticks);

                return(token);
            }
        }
Пример #6
0
        public ActionResult DestroyCustomeEvent([DataSourceRequest] DataSourceRequest request, DashboardEventToken token, int userId)
        {
            if (token != null && !token.Uid.Equals(Guid.Empty))
            {
                _dashboardServices.CustomEventRemove(userId, token);
            }

            return(Json(ModelState.ToDataSourceResult()));
        }
Пример #7
0
        public ActionResult UpdateCustomeEvent([DataSourceRequest] DataSourceRequest request, DashboardEventToken token, int userId)
        {
            if (token != null && !token.Uid.Equals(Guid.Empty) && token.Date != null && !string.IsNullOrEmpty(token.Name) && !string.IsNullOrEmpty(token.Color))
            {
                _dashboardServices.CustomEventUpdate(userId, token);
            }

            return(Json(ModelState.ToDataSourceResult()));
        }
Пример #8
0
 public ActionResult CreateCustomeEvent([DataSourceRequest] DataSourceRequest request, DashboardEventToken token, int userId)
 {
     if (token != null && token.Uid.Equals(Guid.Empty) && token.Date != null && !string.IsNullOrEmpty(token.Name) && !string.IsNullOrEmpty(token.Color))
     {
         _dashboardServices.CustomEventAdd(userId, token);
     }
     return(Json(new List <DashboardEventToken> {
         token
     }.ToDataSourceResult(request)));
 }