Пример #1
0
        //update event
        internal bool updateEvent(EventModel eventModel, EventModel previousEvent, List <ContactModel> pickedContactsList)
        {
            DBconnection dBconnection = new DBconnection();

            dBconnection.sqlConnection.ConnectionString = dBconnection.dataString;
            dBconnection.sqlConnection.Open();

            string add_event = "UPDATE Event SET event_title = @data1, event_description=@data2, begin_time=@data3,end_time=@data4,location=@data5,event_variety=@data6,recuring_variety=@data7,userId=@data8 Where id = @eventId; SELECT SCOPE_IDENTITY()";
            string add_event_contact_selection = "INSERT INTO Event_Contact_selection (contactId, eventId) " +
                                                 "Values (@data2_1, @data2_2)";

            //"UPDATE Contact SET name = @data1, mobileNo = @data2, email= @data3 Where id = @contactId"
            try
            {
                dBconnection.sqlCommand.Connection  = dBconnection.sqlConnection;
                dBconnection.sqlCommand.CommandText = add_event;

                dBconnection.sqlCommand.Parameters.AddWithValue("@data1", eventModel.Event_title);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data2", eventModel.Event_description);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data3", eventModel.Event_begin_time);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data4", eventModel.Event_end_time);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data5", eventModel.Event_location);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data6", eventModel.Event_variety);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data7", previousEvent.Event_recuring_variety);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data8", previousEvent.UserId);
                dBconnection.sqlCommand.Parameters.AddWithValue("@eventId", eventModel.Event_id);



                //int rowsAdded = dBconnection.sqlCommand.ExecuteNonQuery();

                int rowsUpdated = dBconnection.sqlCommand.ExecuteNonQuery();

                //int eventId = Convert.ToInt32(dBconnection.sqlCommand.ExecuteScalar());

                dBconnection.sqlConnection.Close();


                // Console.WriteLine("event id" + eventId);
                int rowsAdd_contact_selection = 0;
                if (pickedContactsList != null)
                {
                    dBconnection.sqlCommand.Connection = dBconnection.sqlConnection;
                    dBconnection.sqlConnection.Open();
                    foreach (ContactModel contact in pickedContactsList)
                    {
                        Console.WriteLine(contact.ContactId);


                        dBconnection.sqlCommand.Parameters.Clear();

                        dBconnection.sqlCommand.CommandText = add_event_contact_selection;
                        dBconnection.sqlCommand.Parameters.AddWithValue("@data2_1", contact.ContactId);
                        dBconnection.sqlCommand.Parameters.AddWithValue("@data2_2", eventModel.Event_id);
                        rowsAdd_contact_selection += dBconnection.sqlCommand.ExecuteNonQuery();
                    }
                    dBconnection.sqlConnection.Close();
                }
                Console.WriteLine("contacts rows" + rowsAdd_contact_selection);



                if (rowsUpdated > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Пример #2
0
        //add event to the db
        public Boolean addevent(EventModel eventModel, List <ContactModel> contactsList, int recuringId)
        {
            DBconnection dBconnection = new DBconnection();

            dBconnection.sqlConnection.ConnectionString = dBconnection.dataString;
            dBconnection.sqlConnection.Open();

            string add_event = "INSERT INTO Event (event_title, event_description, begin_time,end_time,location,event_variety,recuring_variety,userId,recuring_id) " +
                               "Values (@data1, @data2, @data3,@data4,@data5,@data6,@data7,@data8,@data9); SELECT SCOPE_IDENTITY()";

            string add_event_contact_selection = "INSERT INTO Event_Contact_selection (contactId, eventId) " +
                                                 "Values (@data2_1, @data2_2)";



            try
            {
                dBconnection.sqlCommand.Parameters.Clear();

                dBconnection.sqlCommand.Connection  = dBconnection.sqlConnection;
                dBconnection.sqlCommand.CommandText = add_event;

                dBconnection.sqlCommand.Parameters.AddWithValue("@data1", eventModel.Event_title);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data2", eventModel.Event_description);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data3", eventModel.Event_begin_time);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data4", eventModel.Event_end_time);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data5", eventModel.Event_location);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data6", eventModel.Event_variety);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data7", eventModel.Event_recuring_variety);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data8", eventModel.UserId);
                dBconnection.sqlCommand.Parameters.AddWithValue("@data9", recuringId);


                //int rowsAdded = dBconnection.sqlCommand.ExecuteNonQuery();



                int eventId = Convert.ToInt32(dBconnection.sqlCommand.ExecuteScalar());

                dBconnection.sqlConnection.Close();


                Console.WriteLine("event id" + eventId);

                int rowsAdd_contact_selection = 0;

                if (contactsList != null)
                {
                    dBconnection.sqlCommand.Connection = dBconnection.sqlConnection;
                    dBconnection.sqlConnection.Open();
                    foreach (ContactModel contact in contactsList)
                    {
                        Console.WriteLine(contact.ContactId);


                        dBconnection.sqlCommand.Parameters.Clear();

                        dBconnection.sqlCommand.CommandText = add_event_contact_selection;
                        dBconnection.sqlCommand.Parameters.AddWithValue("@data2_1", contact.ContactId);
                        dBconnection.sqlCommand.Parameters.AddWithValue("@data2_2", eventId);
                        rowsAdd_contact_selection += dBconnection.sqlCommand.ExecuteNonQuery();
                    }
                    dBconnection.sqlConnection.Close();
                    Console.WriteLine("contacts rows" + rowsAdd_contact_selection);
                }

                if (eventId > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }