Start a new topic

Tutorials for C# .Net

 Scenario is,


Im new to Kinvey,

I need some tutorials for Specific C# to use with kinvey so that I can CRUD operations on REST API.


Regards:


Zaid Mirza


Hi,


This documentation link: http://devcenter.kinvey.com/rest/guides/datastore#RelationalData covers a similar scenario of books collection with reference to authors and publishers. This should set you up to use Kinvey references effectively.


To sum it up in one sentence, you need to save editors first and then save the book object with KinveyRef array containing editor ids.


Let me know if you get face any issues with the implementation.



Regards,

Wani

Kinvey Support

Hi Wani,

Do you mean I have to POST parent entity first then childs? if yes then I have to set KinvevRef,_type,_collection attributes from front end in POST request preparation of child records?

 

hi Zaid Mirza,


did u get something about access kinvey in C# application ?

Hi Gayan,

Yes I used WebClient or WebRequest to make a REST calls. I was looking for code sample for you in my directory but it is missing. We changed our backend planning from kinvey to firebase cloud due to some other reason. But you can use WebClient or WebRequest classes in C# to make any REST calls with GET,POST,PUT,DELETE.... Methods

 

in firebase can be possible for storing and retrieving bitmap images

Hi Zaid,


Can you tell me more about your use case:

  • What kind of application are you planning to build using C# and Kinvey?
  • Which platforms are you targeting?

I will be able to help you out once I know about your use case.



Regards,

Wani

Kinvey Support

Hi Gayan,

You can see sample code for kinvey in c# in above comments and you can save any type of image at any cloud by converting them in bytes string like "YyauuuUYw%rRARrRRrAttatttRrTYYQyqtqtTQttq........" you can use 64base or any other method to convert

 

ok, i planing move on kinvey for Windows dektop application and mobile application. so it's possible right  ?

Kinvey is good but it dont support deployment yet, you have to use third party to deploy your mob app

 

Hi Wani,

Actually, I have not started any production mode development yet. I am just trying to learn Kinvey Rest API using in C#.

I made a test use case:

Adding Books and their Editors Information on Kinvey
Books and Editors have one-to-many relation (One Book can have many Editors).

When I posted this thread, at that time I did not know how to Call Rest API CRUD requests from C#. But After Some Struggle,I can now CRUD on Kinvey using C#
below is Code sample For Post Request.

 ////Insertion
                Books st = new Books();
                st.BookName = "C#";
                st.Title = "Intro to C#";
                Editors ed = new Editors();
                ed.EditorName = "Junaid";
                ed.EditorAge = 28;
                st.Editors.Add(ed);
                Editors ed1 = new Editors();
                ed.EditorName = "Obaid";
                ed.EditorAge = 27;
                st.Editors.Add(ed1);
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Books));
                MemoryStream mem = new MemoryStream();
                ser.WriteObject(mem, st);
                // string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
                WebClient webClient = new WebClient();
                webClient.Headers["Content-type"] = "application/json";
                webClient.Encoding = Encoding.UTF8;
                byte[] credentialBuffer = new UTF8Encoding().GetBytes("zaidmirza" + ":" + "zaidmirza");
                string authToken = Convert.ToBase64String(credentialBuffer);
                string authHeaderValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Basic {0}", authToken);
                webClient.Headers["Authorization"] = authHeaderValue;
                byte[] data = webClient.UploadData("http://baas.kinvey.com/appdata/:appkey/Books", "POST", mem.ToArray());
                MemoryStream stream = new MemoryStream(data);
                DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(Books));
                Books result = obj.ReadObject(stream) as Books;

 I made two DataContracts  for Json Serialization and Deserialization in C# named "Books","Editors".
I made Editors as ICollection in Books Contract as you can see below


 

namespace KinveyUD
{
    [DataContract]
    class Books
    {
        public Books()
        {
            this.Editors = new HashSet<Editors>();
        }
        [DataMember]
        public string BookName { get; set; }
        [DataMember]
        public string Title { get; set; }
        [DataMember]
        public string _id { get; set; }
        [DataMember(EmitDefaultValue = false)]
        public virtual ICollection<Editors> Editors { get; set; }
    }
}

 Now My problem is that. I want to Insert References on Kinvey from C#.
I made Books Collection and Editor Collection on kinvey App.
But confused how to add one Book with many Editiors.
How KinveyRef Objects to miantain ?

As you can see in above POST request sample code. Im adding Editors in Books Object then Posting Books on Kinvey. In this way , Editors are not being saved on Editors Collection on kinvey but Editors are being saved as array value in Books Record

see below image

.

But I want to maintain Kinvey Standard methods for references by using _type,KinveyRef,_Id etc
Please tell me how to do that




 

Login or Signup to post a comment