public bool UpdateActivity(UserActivity userActivity)
 {
     try
     {
         if (!(Conn.GetSingleItem <UserActivity>("SELECT Id FROM UserActivity WHERE Id = ?", userActivity.Id).Id > 0))
         {
             throw new Exception("ERROR_ACTIVITY_DOESNT_EXIST");
         }
         List <ActivityPropertyValue> tempList = Conn.GetItems <ActivityPropertyValue>("SELECT * FROM ActivityPropertyValue WHERE UserActivityId = ?", userActivity.Id);
         foreach (KeyValuePair <string, string> obj in userActivity.Activity.PropertyValues)
         {
             ActivityProperty currentObj = userActivity.Activity.Properties.FirstOrDefault(data => data.Property == obj.Key);
             if (String.IsNullOrEmpty(obj.Value) && !currentObj.AllowNull)
             {
                 throw new Exception("ERROR_FILL_ALL_FIELDS");
             }
             ActivityPropertyValue editObj = tempList.FirstOrDefault(x => x.ActivityPropertyId == currentObj.Id);
             editObj.Value = obj.Value;
         }
         Conn.UpdateRange(tempList);
         Conn.Update(userActivity);
     }
     catch (Exception ex)
     {
         ErrorMessage = ErrorHandler.ReturnErrorMessage(ex.Message);
         return(false);
     }
     return(true);
 }
        private void AddItemToGrid(ActivityProperty obj, int row)
        {
            string property      = obj.Name;
            string propertyValue = CurrentActivityType.PropertyValues.FirstOrDefault(x => x.Key == obj.Property).Value ?? "";

            PropertyGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            TextBlock TextBlock = new TextBlock();

            TextBlock.Style = (Style)Application.Current.Resources["ActivityPropertyHeader"];
            TextBlock.Text  = property + ":";
            TextBlock.SetValue(Grid.RowProperty, row);
            PropertyGrid.Children.Add(TextBlock);

            row++;

            PropertyGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            if (obj.Type == 0 || obj.Type < 2)
            {
                TextBox textBox = new TextBox();
                textBox.Style = (Style)Application.Current.Resources["ActivityPropertyTextBox"];
                textBox.Text  = propertyValue;
                textBox.Name  = obj.Property;
                textBox.SetValue(Grid.RowProperty, row);
                PropertyGrid.Children.Add(textBox);
            }
            else if (obj.Type == 2)
            {
                ComboBox ComboBox = new ComboBox();
                ComboBox.Style = (Style)Application.Current.Resources["ActivityPropertyComboBox"];
                ComboBox.Name  = obj.Property;
                foreach (ActivityPropertyTypeValue objs in obj.StaticPropertyValues)
                {
                    ComboboxItem item = new ComboboxItem();
                    item.Text  = objs.Name;
                    item.Value = objs;
                    ComboBox.Items.Add(item);
                    if (objs.Name == propertyValue)
                    {
                        ComboBox.SelectedItem = item;
                    }
                }
                ComboBox.SetValue(Grid.RowProperty, row);
                PropertyGrid.Children.Add(ComboBox);
            }
            Border border = new Border()
            {
                BorderBrush     = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)),
                BorderThickness = new Thickness(0, 0, 0, 1),
            };

            border.SetValue(Grid.RowProperty, row);
            PropertyGrid.Children.Add(border);
        }
        public bool AddActivity(Activity activity, DateTime dateTime)
        {
            try
            {
                List <ActivityPropertyValue> tempList = new List <ActivityPropertyValue>();
                foreach (KeyValuePair <string, string> obj in activity.PropertyValues)
                {
                    ActivityProperty currentObj = activity.Properties.FirstOrDefault(data => data.Property == obj.Key);
                    if (String.IsNullOrEmpty(obj.Value) && !currentObj.AllowNull)
                    {
                        throw new Exception("ERROR_FILL_ALL_FIELDS");
                    }
                    tempList.Add(new ActivityPropertyValue()
                    {
                        ActivityPropertyId = currentObj.Id, Value = obj.Value
                    });
                }
                UserActivity uaObj = new UserActivity()
                {
                    ActivityId = activity.Id, UserId = User.Instance.Id, DateTime = dateTime
                };
                Conn.Insert(uaObj);

                foreach (ActivityPropertyValue obj in tempList)
                {
                    obj.UserActivityId = uaObj.Id;
                }

                Conn.InsertRange(tempList);
                AchievementHandler.UpdateProgress(AchievementType.CreatedOneActivity);
            }
            catch (Exception ex)
            {
                ErrorMessage = ErrorHandler.ReturnErrorMessage(ex.Message);
                return(false);
            }
            return(true);
        }
 SetValue(ActivityProperty, value);