Exemple #1
0
        private int get_or_create_collection(TableTopDataClassesDataContext db, string user_name, int activity_id, DateTime dt)
        {
            int user_id = 0;
            var ru      = from u in db.Users
                          where u.name == user_name
                          select u;

            if (ru.Count() == 0)
            {
                if (user_name.ToLower() != "default")
                {
                    return(0);
                }
            }
            else
            {
                user_id = ru.First <User>().id;
            }

            var r = from c in db.Collections
                    where ((c.user_id == user_id) && c.activity_id == activity_id)
                    orderby c.date descending
                    select c;

            if (r.Count() != 0)
            {
                foreach (Collection col in r)
                {
                    if (Configurations.GetDate_Formatted(col.date) == Configurations.GetDate_Formatted(dt))
                    {
                        return(col.id);
                    }
                }
            }

            // create new collection
            Collection cl = new Collection();

            cl.activity_id = activity_id;
            cl.date        = dt;
            cl.name        = Configurations.GetDate_Formatted(dt);
            cl.user_id     = user_id;
            db.Collections.InsertOnSubmit(cl);
            if (!SubmitChangesToLocalDB(db))
            {
                return(-1);
            }
            return(cl.id);
        }
Exemple #2
0
        private void button_add_contrib_Click(object sender, EventArgs e)
        {
            try
            {
                int uid = cached_users[comboBox_users_addcontrib.SelectedIndex].id;
                int cid = cached_user_collections[comboBox_collections_addcontrib.SelectedIndex].id;
                int lid = cached_locations[comboBox_locations_addcontrib.SelectedIndex].id;

                TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
                Contribution c = new Contribution();
                c.date          = DateTime.Now;
                c.modified_date = DateTime.Now;
                c.location_id   = lid;
                c.media_url     = textBox_mediaurl_addcontrib.Text;
                c.note          = textBox_desc_addcontrib.Text;
                c.tags          = textBox_tags_addcontrib.Text;
                c.status        = "";
                db.Contributions.InsertOnSubmit(c);
                db.SubmitChanges();

                if (checkBox_new_collection.Checked)
                {
                    Collection c2 = new Collection();
                    c2.activity_id = cached_activities_addcontrib[comboBox_activities_addcontrib.SelectedIndex].id;
                    c2.date        = DateTime.Now;
                    c2.user_id     = uid;
                    c2.name        = Configurations.GetDate_Formatted(c2.date);
                    db.Collections.InsertOnSubmit(c2);
                    db.SubmitChanges();
                    cid = c2.id;
                }

                Collection_Contribution_Mapping ccm = new Collection_Contribution_Mapping();
                ccm.collection_id   = cid;
                ccm.contribution_id = c.id;
                ccm.date            = DateTime.Now;
                db.Collection_Contribution_Mappings.InsertOnSubmit(ccm);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n--\r\n" + ex.StackTrace);
            }
            MessageBox.Show("Contribution was added successfully.");
        }