Exemple #1
0
        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;
        }
Exemple #2
0
        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();

        }
Exemple #3
0
        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();
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        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();
        }