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); } }
//public DashboardEventToken GetDashboardCustomEventToken(DateTime date, string name) //{ // return new DashboardEventToken // { // Uid = Guid.NewGuid() // ,Type = DashboardEnums.eDbEventTypes.Custom // ,Name = name // ,Date = date // ,Enabled = true // ,IsStatic = false // }; //} #region Custom events public List <DashboardEventToken> CustomEventGetList(int userId) { try { var entityList = CustomEventsRepository.GetMany(x => x.UserId == userId); return(entityList.Select(x => x.Entity2Token()).ToList()); } catch (Exception e) { Logger.Error("get list custom event", e, CommonEnums.LoggerObjectTypes.Dashboard); return(new List <DashboardEventToken>()); } }
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); } }
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); } }