mattkol / SugarRestSharp

SugarRestSharp is a .NET C# SugarCRM/SuiteCRM Rest API Client. It is .NET C# Wrapper for the SugarCRM/SuiteCRM REST API Client.
MIT License
30 stars 12 forks source link

DateStart and DateEnd null! #3

Closed luscala closed 6 years ago

luscala commented 6 years ago

Hi @mattkol, I am having a first look to your SugarRestSharp. In particular, I wrote a command-line utility to bulk-create calls and meetings. I am trying to set DateStart and DateEnd but on the CRM I see those fields empty. Duration (hours and minutes) works fine. I am using SuiteCRM 7.8.7 LTS.

Thanks

luscala commented 6 years ago

Ok, this problem is caused from DateTime to String conversion. With a CustomCall class, which has a String DateStart property (overriding the main one), used to pass to the CRM the date/time in the format "yyyy-MM-dd HH:mm:ss" (instead of "yyyy-mm-ddTHH:mm:ss"), it works. Is there a way to mod the default output of SugarRestSharp for DateTime properties? Thanks

luscala commented 6 years ago

SOLVED! I had a look to Newtonsoft website and found the way. I wrote a CustomDateTimeConverter class (which inherits from IsoDateTimeConverter), where I set my DateTimeFormat (yyyy-MM-dd HH:mm:ss). Then in a CustomCall class I set the default converter for DateTime format to be the custom one.

class CustomDateTimeConverter : IsoDateTimeConverter
{
    public CustomDateTimeConverter()
    {
        base.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
    }
}

public class CustomCall : Call
{
    [JsonConverter(typeof(CustomDateTimeConverter))]

    [JsonProperty(PropertyName = "date_start")]
    public virtual DateTime DateStart { get; set; }
}
mattkol commented 6 years ago

I am glad you found solution to the problem. Sorry for the late response.