Exemplo n.º 1
0
        public static bool DeleteEventInfo(EventInfoModel model)
        {
            try
            {
                var coll = MongodbWrite.GetCollection <EventInfoModel>("EventInfo");

                Dictionary <string, object> dict = new Dictionary <string, object>();
                if (!string.IsNullOrWhiteSpace(model.app_id))
                {
                    dict.Add("app_id", model.app_id);
                }
                if (!string.IsNullOrWhiteSpace(model.event_code))
                {
                    dict.Add("event_code", model.event_code);
                }

                var query = new BsonDocument(dict);
                coll.DeleteManyAsync(query);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }

            return(true);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,EventName,EventOrg,PresentersName,EventLocation,EventStartDate,EventEndDate")] EventInfoModel eventInfoModel)
        {
            if (id != eventInfoModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eventInfoModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventInfoModelExists(eventInfoModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("AddOrEdit", "Questions", new { eventId = eventInfoModel.Id }));
                //return RedirectToAction("Index");
            }
            return(View(eventInfoModel));
        }
Exemplo n.º 3
0
        public static bool InsertEventInfo(EventInfoModel model)
        {
            try
            {
                var coll = MongodbWrite.GetCollection <EventInfoModel>("EventInfo");
                coll.InsertOneAsync(model);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public IActionResult EventInfoEdit(string appid = "", string eventcode = "")
        {
            if (string.IsNullOrWhiteSpace(appid))
            {
                return(Content("app_id Empty"));
            }
            EventInfoModel model = new EventInfoModel();

            if (!string.IsNullOrWhiteSpace(appid) && !string.IsNullOrWhiteSpace(eventcode))
            {
                var list = MongoDbHelper.SearchEventInfoList(appid, eventcode);
                if (list.Count > 0)
                {
                    model = list.First();
                }
            }
            model.app_id = appid;

            return(View(model));
        }
Exemplo n.º 5
0
        public static EventInfoModel ToModel(this  Event entity, int languageId)
        {
            if (entity == null)
            {
                throw(new ArgumentNullException("event"));
            }
            var model = new EventInfoModel()
            {
                Title            = entity.GetLocalized(x => x.Title, languageId: languageId, returnDefaultValue: false),
                ShortDescription = entity.GetLocalized(x => x.ShortDescription, languageId: languageId, returnDefaultValue: false),
                FullDescription  = entity.GetLocalized(x => x.FullDescription, languageId: languageId, returnDefaultValue: false),
                StartDate        = entity.StartDate,
                EndDate          = entity.EndDate,
                SeName           = entity.GetSeName(languageId),
                PictureId        = entity.PictureId,
                CatalogPictureid = entity.CatalogPictureId
            };

            return(model);
        }
Exemplo n.º 6
0
        public IActionResult EventInfoSave(EventInfoModel model)
        {
            if (string.IsNullOrWhiteSpace(model.app_id))
            {
                return(Content("app_id Empty"));
            }
            if (string.IsNullOrWhiteSpace(model.event_code))
            {
                return(Content("event_code Empty"));
            }

            var list = MongoDbHelper.SearchEventInfoList(model.app_id, model.event_code);

            if (list.Any())
            {
                MongoDbHelper.DeleteEventInfo(model);
            }

            var res = MongoDbHelper.InsertEventInfo(model);


            return(Content(res ? "OK" : "ERROR"));
        }
        public async Task <IActionResult> Create([Bind("Id,EventName,EventOrg,PresentersName,EventLocation,EventStartDate,EventEndDate")] EventInfoModel eventInfoModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eventInfoModel);
                await _context.SaveChangesAsync();

                var user = await _userManager.GetUserAsync(HttpContext.User);

                var userEvent = new UserEventModel()
                {
                    UserId  = user.Id,
                    EventId = eventInfoModel.Id
                };

                _context.Add(userEvent);
                await _context.SaveChangesAsync();

                return(RedirectToAction("AddOrEdit", "Questions", new { eventId = eventInfoModel.Id }));
                //return RedirectToAction("Index");
            }
            return(View(eventInfoModel));
        }
Exemplo n.º 8
0
        //[ValidateAntiForgeryToken]
        public String CreateEvent(EventInfoModel eventInfo)
        {
            if (eventInfo.Event.EventTypeObj != null)
            {
                eventInfo.Event.EventType = (EventType)eventInfo.Event.EventTypeObj.Key;  // map key to enum type.
            }

            if (eventInfo.Event.EventStatusObj != null)
            {
                eventInfo.Event.EventStatus = (EventStatus)eventInfo.Event.EventStatusObj.Key; // map key to enum type.
            }


            if (eventInfo.Event.EventVisibilityObj != null)
            {
                eventInfo.Event.EventVisibility = (EventVisibility)eventInfo.Event.EventVisibilityObj.Key; // map key to from enum type.
            }


            if (eventInfo.Event.EventScEligibilityObj != null)
            {
                eventInfo.Event.ScEligibility = (scEligibility)eventInfo.Event.EventScEligibilityObj.Key; // map key to enum type.
            }

            if (ModelState.IsValid)
            {
                if (eventInfo.Event.EventID == 0)                                                                                           //if new event.
                {
                    db.Events.Add(eventInfo.Event);                                                                                         //add new event.
                    if (eventInfo.EventTracks == null && (eventInfo.EventTechnologTags == null || eventInfo.EventAudienceTypeTags == null)) //event technolog tags does not exist and event tracks are also empty.
                    {
                        return(JsonConvert.SerializeObject(new { responseCode = 003 }));
                    }
                    db.SaveChanges();
                    if (eventInfo.EventTracks != null)              //event tracks if exists.
                    {
                        foreach (var eventTrack in eventInfo.EventTracks)
                        {
                            eventTrack.EventID = eventInfo.Event.EventID;

                            db.EventTracks.Add(eventTrack);
                        }
                        if (eventInfo.EventTechnologTags != null)       //event log tags in event if exist.
                        {
                            var @event = db.Events.Where(x => x.EventID == eventInfo.Event.EventID).FirstOrDefault();
                            foreach (var eventLog in eventInfo.EventTechnologTags)
                            {
                                @event.EventTechnologTags.Remove(eventLog);
                            }
                        }
                        if (eventInfo.EventAudienceTypeTags != null)
                        {
                            var @event = db.Events.Where(x => x.EventID == eventInfo.Event.EventID).FirstOrDefault();
                            foreach (var eventLog in eventInfo.EventAudienceTypeTags)
                            {
                                @event.EventAudienceTypeTags.Remove(eventLog);
                            }
                        }
                    }
                    else
                    {
                        var @event = db.Events.Where(x => x.EventID == eventInfo.Event.EventID).FirstOrDefault();
                        @event.EventTechnologTags = new List <PrimaryTechnology>();
                        foreach (var eventLog in eventInfo.EventTechnologTags)          //event techno log tags exist.
                        {
                            var existingEventLog = db.PrimaryTechnologies.Where(x => x.PrimaryTechnologyID == eventLog.PrimaryTechnologyID).FirstOrDefault();
                            @event.EventTechnologTags.Add(existingEventLog);        //add to event.
                        }

                        @event.EventAudienceTypeTags = new List <AudienceType>();
                        foreach (var eventLog in eventInfo.EventAudienceTypeTags)          //event techno log tags exist.
                        {
                            var existingEventLog = db.AudienceTypes.Where(x => x.AudienceTypeID == eventLog.AudienceTypeID).FirstOrDefault();
                            @event.EventAudienceTypeTags.Add(existingEventLog);        //add to event.
                        }
                    }
                }
                else
                {
                    var existingEvent = db.Events
                                        .Where(p => p.EventID == eventInfo.Event.EventID)
                                        .Include("EventTracks.TrackAgendas")
                                        .SingleOrDefault();

                    if (existingEvent != null)                                            //event already exist.
                    {
                        db.Entry(existingEvent).CurrentValues.SetValues(eventInfo.Event); //update existing event values.

                        // Delete children
                        foreach (var existingChild in existingEvent.EventTracks.ToList())
                        {
                            if (eventInfo.EventTracks == null || !eventInfo.EventTracks.Any(c => c.EventTrackID == existingChild.EventTrackID))
                            {
                                existingChild.TrackAgendas.ToList().ForEach(p => db.TrackAgendas.Remove(p));
                                db.EventTracks.Remove(existingChild);
                            }
                        }


                        if (eventInfo.EventTracks != null)
                        {
                            // Update and Insert children
                            foreach (var childModel in eventInfo.EventTracks)
                            {
                                var existingChild = existingEvent.EventTracks
                                                    .Where(c => c.EventTrackID == childModel.EventTrackID)
                                                    .SingleOrDefault();

                                if (existingChild != null)
                                {
                                    // Update child

                                    db.Entry(existingChild).CurrentValues.SetValues(childModel);

                                    // Delete children
                                    foreach (var existingGrandChild in existingChild.TrackAgendas.ToList())
                                    {
                                        if (!existingChild.TrackAgendas.Any(c => c.TrackAgendaID == existingGrandChild.TrackAgendaID))
                                        {
                                            db.TrackAgendas.Remove(existingGrandChild);
                                        }
                                    }

                                    // Update and Insert children
                                    foreach (var grandChildModel in existingChild.TrackAgendas)
                                    {
                                        var existingGrandChild = existingChild.TrackAgendas
                                                                 .Where(c => c.TrackAgendaID == grandChildModel.TrackAgendaID)
                                                                 .SingleOrDefault();

                                        if (existingGrandChild != null)
                                        {
                                            // Update child

                                            db.Entry(existingGrandChild).CurrentValues.SetValues(grandChildModel);
                                        }
                                        else
                                        {
                                            // Insert child
                                            var newChild = new TrackAgenda()
                                            {
                                                EndTime      = grandChildModel.EndTime,
                                                SpeakerID    = grandChildModel.SpeakerID,
                                                EventTrackID = grandChildModel.EventTrackID,
                                                FavCount     = grandChildModel.FavCount,
                                                QRCode       = grandChildModel.QRCode,
                                                SessionID    = grandChildModel.SessionID,
                                                StartTime    = grandChildModel.StartTime
                                            };
                                            existingChild.TrackAgendas.Add(newChild);
                                        }
                                    }
                                }
                                else
                                {
                                    // Insert child
                                    var newChild = new EventTrack()
                                    {
                                        EventID        = childModel.EventID,
                                        TrackEndTime   = childModel.TrackEndTime,
                                        TrackID        = childModel.TrackID,
                                        TrackOwner     = childModel.TrackOwner,
                                        TrackSeating   = childModel.TrackSeating,
                                        TrackVenue     = childModel.TrackVenue,
                                        TrackStartTime = childModel.TrackStartTime,
                                        TrackAgendas   = childModel.TrackAgendas
                                    };
                                    existingEvent.EventTracks.Add(newChild);
                                }
                            }
                            if (existingEvent.EventTechnologTags != null)
                            {
                                var existingTags = existingEvent.EventTechnologTags.ToList();
                                foreach (var eventLog in existingTags)
                                {
                                    existingEvent.EventTechnologTags.Remove(
                                        existingEvent.EventTechnologTags.FirstOrDefault(
                                            x => x.PrimaryTechnologyID == eventLog.PrimaryTechnologyID));
                                }
                            }
                            if (existingEvent.EventAudienceTypeTags != null)
                            {
                                var existingTags = existingEvent.EventAudienceTypeTags.ToList();
                                foreach (var eventLog in existingTags)
                                {
                                    existingEvent.EventAudienceTypeTags.Remove(
                                        existingEvent.EventAudienceTypeTags.FirstOrDefault(
                                            x => x.AudienceTypeID == eventLog.AudienceTypeID));
                                }
                            }
                        }
                        else
                        {
                            if (eventInfo.EventTechnologTags == null)
                            {
                                return(JsonConvert.SerializeObject(new { responseCode = 003 }));
                            }
                            else
                            {
                                if (existingEvent.EventTechnologTags != null)
                                {
                                    var existingTags = existingEvent.EventTechnologTags.ToList();
                                    foreach (var eventLog in existingTags)
                                    {
                                        existingEvent.EventTechnologTags.Remove(eventLog);
                                    }
                                }
                                existingEvent.EventTechnologTags = new List <PrimaryTechnology>();
                                foreach (var eventLog in eventInfo.EventTechnologTags)
                                {
                                    var existingEventLog = db.PrimaryTechnologies.Where(x => x.PrimaryTechnologyID == eventLog.PrimaryTechnologyID).FirstOrDefault();
                                    existingEvent.EventTechnologTags.Add(existingEventLog);         //add new techno log tags of event.
                                }
                            }

                            if (eventInfo.EventAudienceTypeTags == null)
                            {
                                return(JsonConvert.SerializeObject(new { responseCode = 003 }));
                            }
                            else
                            {
                                if (existingEvent.EventAudienceTypeTags != null)
                                {
                                    var existingTags = existingEvent.EventAudienceTypeTags.ToList();
                                    foreach (var eventLog in existingTags)
                                    {
                                        existingEvent.EventAudienceTypeTags.Remove(eventLog);
                                    }
                                }
                                existingEvent.EventAudienceTypeTags = new List <AudienceType>();
                                foreach (var eventLog in eventInfo.EventAudienceTypeTags)
                                {
                                    var existingEventLog = db.AudienceTypes.Where(x => x.AudienceTypeID == eventLog.AudienceTypeID).FirstOrDefault();
                                    existingEvent.EventAudienceTypeTags.Add(existingEventLog);         //add new techno log tags of event.
                                }
                            }
                        }
                    }
                }
                db.SaveChanges();

                return(JsonConvert.SerializeObject(new { responseCode = 001 }));
            }
            return(JsonConvert.SerializeObject(new { responseCode = 002 }));
        }