public int CreateEvent(string currentUsername, DataModel.Event baseEvent) { var usBusiness = new Business.Users(base.db); CityAngels.DataModel.User loggedUser = usBusiness.GetUser(currentUsername); // create event if (baseEvent.DateTo == DateTime.MinValue) baseEvent.DateTo = null; // standart schedule type (weekly) if (baseEvent.IsPeriodic) { baseEvent.EventSchedulingTypeId = (int)Data.Enum.ScheduleType.WEEKLY; } // baseEvent.RefEventId = null; <- non rimuovo il riferimento all'evento ripetuto, mi serve per non ripetere due volte l'evento nella giornata baseEvent.IsEnabled = true; baseEvent.CreateDate = DateTime.Now; baseEvent.CreatorUserId = loggedUser.UserId; baseEvent.UpdateDate = DateTime.Now; baseEvent.UpdateUserId = loggedUser.UserId; db.Events.Add(baseEvent); // log for other users Business.Logs log = new Business.Logs(base.db, Data.Enum.LogTypes.NEW, loggedUser); log.Push(baseEvent); db.SaveChanges(); return baseEvent.EventId; }
public object GetUserLogs(string userName, bool getCount, bool getUnread) { DateTime minDate = DateTime.Now.AddDays(-10); var usBusiness = new Business.Users(base.db); DataModel.User loggedUser = usBusiness.GetUser(userName); //return db.Logs.Where(log => log.LogDestinationUserId == UserId).ToList(); var logs = ( from log in db.Logs where log.RelatedUserId == loggedUser.UserId && log.CreateDate >= minDate select log ); if (getCount) if (getUnread) return logs.Where(log => log.IsRead == false).Count(); else return logs.Count(); else return logs.OrderByDescending(l => l.CreateDate).ToList(); }
public void UpdateEvent(string currentUsername, DataModel.Event baseEvent) { var usBusiness = new Business.Users(base.db); CityAngels.DataModel.User loggedUser = usBusiness.GetUser(currentUsername); db.Entry(baseEvent).State = EntityState.Modified; baseEvent.UpdateDate = DateTime.Now; baseEvent.UpdateUserId = loggedUser.UserId; // log for other users Business.Logs log = new Business.Logs(base.db, Data.Enum.LogTypes.UPDATE, loggedUser); log.Push(baseEvent); db.SaveChanges(); }
public void Push(DataModel.Event eventToLog) { var usBusiness = new Business.Users(base.db); var enabledUsers = usBusiness.GetEnabledUsers(); foreach (DataModel.User user in enabledUsers) { DataModel.Logs log = new DataModel.Logs(); log.LogTypeId = (int)this.logType; log.LogTable = Data.Enum.Tables.Events; log.RefId = eventToLog.EventId; switch (this.logType) { case Data.Enum.LogTypes.NEW: log.LogText = string.Format("Nuovo evento creato da {0} ({1}) per il {2}.", this.currentUser.UserName, eventToLog.Description, eventToLog.DateFrom.ToString("d")); break; case Data.Enum.LogTypes.UPDATE: log.LogText = string.Format("Evento del {0} ({1}) modificato da {2}.", eventToLog.DateFrom.ToString("d"), eventToLog.Description, this.currentUser.UserName); break; case Data.Enum.LogTypes.DELETE: log.LogText = string.Format("Evento del {0} ({1}) eliminato da {2}.", eventToLog.DateFrom.ToString("d"), eventToLog.Description, this.currentUser.UserName); break; case Data.Enum.LogTypes.JOIN_EVENT: log.LogText = string.Format("{0} parteciperà al servizio {1} del {2}.", this.currentUser.UserName, eventToLog.Description, eventToLog.DateFrom.ToString("d")); break; case Data.Enum.LogTypes.UNJOIN_EVENT: log.LogText = string.Format("{0} non parteciperà più al servizio {1} del {2}.", this.currentUser.UserName, eventToLog.Description, eventToLog.DateFrom.ToString("d")); break; } log.IsRead = false; log.RelatedUserId = user.UserId; log.CreatorUserId = this.currentUser.UserId; log.CreateDate = DateTime.Now; db.Logs.Add(log); } }
public UsersController() { this.usersBusiness = new Business.Users(base.db); }
public DatabaseConfig() { businessUsers = new Business.Users(this._db); }
public void DeleteEvent(string currentUsername, int eventId, DateTime? deletedDateEvent, int? refEventId) { // se era un evento ripetuto, lo creo, per poi disabilitarlo successivamente if (eventId == Data.Consts.DEFAULT_EVENT_ID_BY_REPEATED_ONE) { if (!refEventId.HasValue) throw new Exception("Impossibile continuare con la cancellazione, manca l'evento di riferimento."); DataModel.Event dbNewEvent = GetEvent(refEventId.Value, true); dbNewEvent.EventId = Data.Consts.DEFAULT_EVENT_ID_BY_REPEATED_ONE; dbNewEvent.RefEventId = refEventId.Value; dbNewEvent.IsPeriodic = false; // imposto la data affinché il metodo che si occuperà di recuperare gli eventi ricorsivi, capirà che per questa data esiste gia' un evento // e quindi non sarà necessario replicarlo dbNewEvent.DateFrom = deletedDateEvent.Value; eventId = this.CreateEvent(currentUsername, dbNewEvent); // popolo eventId con l'id dell'evento appena creato } var usBusiness = new Business.Users(base.db); CityAngels.DataModel.User loggedUser = usBusiness.GetUser(currentUsername); DataModel.Event dbEvent = GetEvent(eventId, false); // log for other users Business.Logs log = new Business.Logs(base.db, Data.Enum.LogTypes.DELETE, loggedUser); log.Push(dbEvent); dbEvent.IsEnabled = false; dbEvent.UpdateUserId = loggedUser.UserId; dbEvent.UpdateDate = DateTime.Now; db.SaveChanges(); }
public void ToggleJoinEvent(string currentUsername, int eventId) { var usBusiness = new Business.Users(base.db); CityAngels.DataModel.User loggedUser = usBusiness.GetUser(currentUsername); DataModel.Event dbEvent = GetEvent(eventId, false); Data.Enum.LogTypes lt = Data.Enum.LogTypes.JOIN_EVENT; var eventRef = db.EventRefs.FirstOrDefault(er => er.EventId == eventId && er.UserId == loggedUser.UserId); if (eventRef == null) { lt = Data.Enum.LogTypes.JOIN_EVENT; db.EventRefs.Add(new EventRef() { EventId = dbEvent.EventId, UserId = loggedUser.UserId, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, CreatorUserId = loggedUser.UserId, UpdateUserId = loggedUser.UserId }); } else { lt = Data.Enum.LogTypes.UNJOIN_EVENT; db.EventRefs.Remove(eventRef); } // log join/unjoin Business.Logs log = new Business.Logs(base.db, lt, loggedUser); log.Push(dbEvent); db.SaveChanges(); }