Skip to content

Commit

Permalink
#1183 Исправляет GroupChangeSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
inyutin-maxim committed Jul 15, 2021
1 parent 9c156c0 commit d23d0d3
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 111 deletions.
200 changes: 100 additions & 100 deletions VkNet/Enums/SafetyEnums/Changes.cs → VkNet/Enums/SafetyEnums/Change.cs
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
using System;
using Newtonsoft.Json;
using VkNet.Utils;
using VkNet.Utils.JsonConverter;
using VkNet.Enums.SafetyEnums;
namespace VkNet.Enums.SafetyEnums
{
/// <summary>
/// Изменение настроек сообщества
/// </summary>
[Serializable]
public class Changes
{
/// <summary>
/// Название секции или раздела, который был изменён
/// </summary>
[JsonProperty("{FIELD}")]
public string Field { get; set; }

/// <summary>
/// Новое значение
/// </summary>
[JsonProperty("new_value")]
public string NewValue { get; set; }

/// <summary>
/// Старое значение
/// </summary>
[JsonProperty("old_value")]
public string OldValue { get; set; }

#region Методы

/// <summary>
/// </summary>
/// <param name="response"> </param>
/// <returns> </returns>
public static Changes FromJson(VkResponse response)
{
var field = "";
if(response["title"]!=null)
field = "title";
else if(response["description"]!=null)
field = "description";
else if(response["access"]!=null)
field = "access";
else if(response["screen_name"]!=null)
field = "screen_name";
else if(response["public_category"]!=null)
field = "public_category";
else if(response["age_limits"]!=null)
field = "age_limits";
else if(response["website"]!=null)
field = "website";
else if(response["public_subcategory"]!=null)
field = "public_subcategory";

else if(response["enable_status_default"]!=null)
field = "enable_status_default";
else if(response["enable_audio"]!=null)
field = "enable_audio";
else if(response["enable_photo"]!=null)
field = "enable_photo";
else if(response["enable_video"]!=null)
field = "enable_video";
else if(response["enable_market"]!=null)
field = "enable_market";
if(field!="")
return new Changes
{
Field = field,
NewValue = response[field]["new_value"],
OldValue = response[field]["old_value"]
}; else return new Changes
{
Field = field,
NewValue = null,
OldValue = null
};
}

/// <summary>
/// Преобразование класса <see cref="Changes" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns>Результат преобразования в <see cref="Changes" /></returns>
public static implicit operator Changes(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}

#endregion
}
using System;
using Newtonsoft.Json;
using VkNet.Utils;
using VkNet.Utils.JsonConverter;
using VkNet.Enums.SafetyEnums;
namespace VkNet.Enums.SafetyEnums
{
/// <summary>
/// Изменение настроек сообщества
/// </summary>
[Serializable]
public class Change
{
/// <summary>
/// Название секции или раздела, который был изменён
/// </summary>
[JsonProperty("{FIELD}")]
public string Field { get; set; }

/// <summary>
/// Новое значение
/// </summary>
[JsonProperty("new_value")]
public string NewValue { get; set; }

/// <summary>
/// Старое значение
/// </summary>
[JsonProperty("old_value")]
public string OldValue { get; set; }

#region Методы

/// <summary>
/// </summary>
/// <param name="response"> </param>
/// <returns> </returns>
public static Change FromJson(VkResponse response)
{
var field = "";
if(response["title"]!=null)
field = "title";
else if(response["description"]!=null)
field = "description";
else if(response["access"]!=null)
field = "access";
else if(response["screen_name"]!=null)
field = "screen_name";
else if(response["public_category"]!=null)
field = "public_category";
else if(response["age_limits"]!=null)
field = "age_limits";
else if(response["website"]!=null)
field = "website";
else if(response["public_subcategory"]!=null)
field = "public_subcategory";

else if(response["enable_status_default"]!=null)
field = "enable_status_default";
else if(response["enable_audio"]!=null)
field = "enable_audio";
else if(response["enable_photo"]!=null)
field = "enable_photo";
else if(response["enable_video"]!=null)
field = "enable_video";
else if(response["enable_market"]!=null)
field = "enable_market";
if(field!="")
return new Change
{
Field = field,
NewValue = response[field]["new_value"],
OldValue = response[field]["old_value"]
}; else return new Change
{
Field = field,
NewValue = null,
OldValue = null
};
}

/// <summary>
/// Преобразование класса <see cref="Change" /> в <see cref="VkParameters" />
/// </summary>
/// <param name="response"> Ответ сервера. </param>
/// <returns>Результат преобразования в <see cref="Change" /></returns>
public static implicit operator Change(VkResponse response)
{
if (response == null)
{
return null;
}

return response.HasToken()
? FromJson(response)
: null;
}

#endregion
}
}
16 changes: 5 additions & 11 deletions VkNet/Enums/SafetyEnums/GroupChangeSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using VkNet.Utils;
using VkNet.Utils.JsonConverter;
using VkNet.Enums.SafetyEnums;

namespace VkNet.Model.GroupUpdate
Expand All @@ -22,23 +22,17 @@ public class GroupChangeSettings
/// Описание внесённых изменений
/// </summary>
[JsonProperty("changes")]
public Changes Changes { get; set; }
public Dictionary<string, Change> Changes { get; set; }


#region Методы
#region Методы

/// <summary>
/// </summary>
/// <param name="response"> </param>
/// <returns> </returns>
public static GroupChangeSettings FromJson(VkResponse response)
{
return new GroupChangeSettings
{
UserId = response["user_id"],
Changes = response["changes"],

};
return JsonConvert.DeserializeObject<GroupChangeSettings>(response.RawJson);
}

/// <summary>
Expand All @@ -58,6 +52,6 @@ public static implicit operator GroupChangeSettings(VkResponse response)
: null;
}

#endregion
#endregion
}
}

0 comments on commit d23d0d3

Please sign in to comment.