Пример #1
0
 public async Task SaveFigureAsync(Guid id, double area)
 {
     using (var db = new FigureContext())
     {
         db.Add(new db.Figure()
         {
             Id   = id,
             Area = area
         });
         await db.SaveChangesAsync();
     }
 }
Пример #2
0
        public async Task <Double> GetAreaAsync(Guid id)
        {
            using (var db = new FigureContext())
            {
                var figure = await db.Figures.FindAsync(id);

                if (figure == null)
                {
                    throw new BusinessLogicException($"Figure {id} not found");
                }
                return(figure.Area);
            }
        }
Пример #3
0
 public bl.Figure Load(Guid id)
 {
     using (var db = new FigureContext())
     {
         var figure = db.Figures.Find(id);
         if (figure == null)
         {
             return(null);
         }
         return(JsonConvert.DeserializeObject <bl.Figure>(figure.Data, new JsonSerializerSettings {
             TypeNameHandling = TypeNameHandling.All
         }));
     }
 }
Пример #4
0
 public void Save(bl.Figure figure)
 {
     using (var db = new FigureContext())
     {
         db.Add(new db.Figure()
         {
             Id   = figure.Id,
             Data = JsonConvert.SerializeObject(figure, new JsonSerializerSettings {
                 TypeNameHandling = TypeNameHandling.All
             })
         });
         db.SaveChanges();
     }
 }