Example #1
0
        public void Post(Shared.Face face)
        {
            var catalog = new Database.Catalog();

            catalog.Faces.Add(Utils.ToDatabase(face));
            catalog.SaveChanges();
        }
Example #2
0
 public static Database.Face ToDatabase(Shared.Face f)
 {
     return(new Database.Face()
     {
         FaceId = f.FaceId,
         Age = f.Age,
         Gender = f.Gender,
         Cat = f.Cat,
         Bitmap = f.Bitmap
     });
 }
Example #3
0
 public static Face ToClient(Shared.Face f)
 {
     return(new Face()
     {
         FaceId = f.FaceId,
         Age = f.Age,
         Gender = f.Gender,
         Cat = f.Cat,
         Bitmap = f.Bitmap
     });
 }
        private async Task <bool> SaveToDb()
        {
            bool result = true;

            try
            {
                //if (categories.Count > 0)
                var req = await client.DeleteAsync("api/faces"); //PostAsJsonAsync("api /faces", newface);

                req.EnsureSuccessStatusCode();
                foreach (var cat in categories)
                {
                    foreach (var face in cat.Faces)
                    {
                        var newface = new Shared.Face()
                        {
                            FaceId = face.FaceId,
                            Age    = face.Age,
                            Gender = face.Gender,
                            Cat    = face.Cat,
                            Bitmap = face.Bitmap,
                        };
                        var r = await client.PostAsJsonAsync("api/faces", newface);

                        r.EnsureSuccessStatusCode();
                    }
                    result = true;
                }
            }
            catch (System.Net.Http.HttpRequestException)
            {
                result = false;
                //MessageBox.Show("Не удается установить соединение сервером");
            }
            return(result);
        }