Ejemplo n.º 1
0
        //Add a new topic: returns the new topicID
        public topiccategory addTopic(topiccategory s)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    var checkTopic = (from t in context.topiccategories
                                      where t.name == s.name && t.deleted == true
                                      select t).FirstOrDefault();
                    //check if there has been topics with the specified name
                    if (checkTopic != null)
                    {
                        //Recover topic and set deleted attribute back to false
                        checkTopic.deleted = false;
                        s.topiccategoryID = checkTopic.topiccategoryID;
                    }
                    else
                    {
                        s.deleted = false;
                        //Add new topic
                        context.topiccategories.Add(s);
                    }

                    context.SaveChanges();
                    return s;
                }
            }
            catch (Exception ex)
            {
                Console.Write("AdminManager.addTopic error " + ex);
                return s;
            }
        }
Ejemplo n.º 2
0
        //Update topic to the specified name
        public bool updateTopic(topiccategory x)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    //Get the topic to update
                    var topic = (from s in context.topiccategories
                                 where s.topiccategoryID == x.topiccategoryID
                                 select s).FirstOrDefault();

                    if (topic != null)
                    {
                        //Change name
                        topic.name = x.name;
                        context.SaveChanges();
                    }

                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.Write("AdminManager.updateTopic error " + ex);
                return false;
            }
        }