public bool SetBlocks(string data)
        {
            SetBlockModel         b     = JsonConvert.DeserializeObject <SetBlockModel>(data);
            var                   picId = Int32.Parse(b.picId);
            List <List <string> > a;

            a = b.bounds;

            using (var dbUse = new UserContext())
            {
                var pic = dbUse.PicturesModels.Find(picId);
                pic.Name          = b.Name;
                pic.NaturalHeight = int.Parse(b.NaturalHeight);
                pic.NaturalWidth  = int.Parse(b.NaturalWidth);
                if (a.Count == 0)
                {
                    dbUse.PositionModels.RemoveRange(pic.PositionModels);
                }
                if (!b.stamps.Any())
                {
                    dbUse.StampPositions.RemoveRange(pic.StampPositions);
                }
                dbUse.Entry(pic).State = EntityState.Modified;
                dbUse.SaveChanges();
            }
            if (a.Count == 0 && !b.stamps.Any())
            {
                return(false);
            }

            using (var dbUse = new UserContext())
            {
                PictureModel picture = dbUse.PicturesModels.Find(picId);

                foreach (var block in a)
                {
                    PositionModel model = picture?.PositionModels.FirstOrDefault(t => t.Id == int.Parse(block[4]));
                    if (model != null)
                    {
                        model.Id         = int.Parse(block[4]);
                        model.PictureId  = picId;
                        model.PosX       = float.Parse(block[0].Replace('.', ','));
                        model.PosY       = float.Parse(block[1].Replace('.', ','));
                        model.Width      = float.Parse(block[2].Replace('.', ','));
                        model.Type       = block[5];
                        model.FontSize   = int.Parse(block[7]);
                        model.Height     = float.Parse(block[6].Replace('.', ','));
                        model.Text       = block[5].Contains("Статичный текст") ? block[8].Replace("\n", "*newline*") : "";
                        model.FontWeight = block[9];
                        model.Alignment  = block[10];


                        if (block[5] == "Статичный текст из бд")
                        {
                            dbUse.AutoTexts.AddOrUpdate(new AutoTextModel
                            {
                                Text = block[8].Replace("\n", "*newline*")
                            });
                        }
                        dbUse.Entry(model).State = EntityState.Modified;
                    }
                    else
                    {
                        model = new PositionModel()
                        {
                            PictureId  = picId,
                            PosX       = float.Parse(block[0].Replace('.', ',')),
                            PosY       = float.Parse(block[1].Replace('.', ',')),
                            Width      = float.Parse(block[2].Replace('.', ',')),
                            Type       = block[5],
                            FontSize   = int.Parse(block[7]),
                            Height     = float.Parse(block[6].Replace('.', ',')),
                            Text       = block[5].Contains("Статичный текст") ? block[8] : "",
                            FontWeight = block[9],
                            Alignment  = block[10]
                        };
                        if (block[5] == "Статичный текст из бд")
                        {
                            dbUse.AutoTexts.AddOrUpdate(new AutoTextModel
                            {
                                Text = block[8]
                            });
                        }
                        dbUse.PositionModels.AddOrUpdate(model);
                    }
                }
                foreach (var stamp in b.stamps)
                {
                    StampPositions stamps = picture.StampPositions.FirstOrDefault(t => t.StampPositionId == stamp.StampPositionId);
                    if (stamps != null)
                    {
                        stamps.Height             = float.Parse(stamp.Height.Replace('.', ','));
                        stamps.Width              = float.Parse(stamp.Width.Replace('.', ','));
                        stamps.PosX               = float.Parse(stamp.PosX.Replace('.', ','));
                        stamps.PosY               = float.Parse(stamp.PosY.Replace('.', ','));
                        stamps.Type               = stamp.Type;
                        dbUse.Entry(stamps).State = EntityState.Modified;
                    }
                    else
                    {
                        stamps = new StampPositions
                        {
                            PicId  = picId,
                            Type   = stamp.Type,
                            Height = float.Parse(stamp.Height.Replace('.', ',')),
                            Width  = float.Parse(stamp.Width.Replace('.', ',')),
                            PosX   = float.Parse(stamp.PosX.Replace('.', ',')),
                            PosY   = float.Parse(stamp.PosY.Replace('.', ','))
                        };
                        dbUse.StampPositions.AddOrUpdate(stamps);
                    }
                }
                foreach (var photo in b.photos)
                {
                    PhotoModel photos = picture.PhotoModels.FirstOrDefault(t => t.PhotoModelId == photo.PhotoModelId);
                    if (photos != null)
                    {
                        photos.Height             = float.Parse(photo.Height.Replace('.', ','));
                        photos.Width              = float.Parse(photo.Width.Replace('.', ','));
                        photos.PosX               = float.Parse(photo.PosX.Replace('.', ','));
                        photos.PosY               = float.Parse(photo.PosY.Replace('.', ','));
                        photos.PhotoModelId       = photo.PhotoModelId;
                        dbUse.Entry(photos).State = EntityState.Modified;
                    }
                    else
                    {
                        photos = new PhotoModel
                        {
                            PicId        = picId,
                            PhotoModelId = photo.PhotoModelId,
                            Height       = float.Parse(photo.Height.Replace('.', ',')),
                            Width        = float.Parse(photo.Width.Replace('.', ',')),
                            PosX         = float.Parse(photo.PosX.Replace('.', ',')),
                            PosY         = float.Parse(photo.PosY.Replace('.', ','))
                        };
                        dbUse.PhotoModel.AddOrUpdate(photos);
                    }
                }
                foreach (var photo in b.images)
                {
                    StaticImageModel photos = picture.StaticImageModels.FirstOrDefault(t => t.StaticImageModelId == photo.StaticImageModelId);
                    if (photos != null)
                    {
                        photos.Height             = float.Parse(photo.Height.Replace('.', ','));
                        photos.Width              = float.Parse(photo.Width.Replace('.', ','));
                        photos.PosX               = float.Parse(photo.PosX.Replace('.', ','));
                        photos.PosY               = float.Parse(photo.PosY.Replace('.', ','));
                        photos.StaticImageModelId = photo.StaticImageModelId;
                        dbUse.Entry(photos).State = EntityState.Modified;
                    }
                    else
                    {
                        photos = new StaticImageModel
                        {
                            PicId = picId,
                            StaticImageModelId = photo.StaticImageModelId,
                            Height             = float.Parse(photo.Height.Replace('.', ',')),
                            Width = float.Parse(photo.Width.Replace('.', ',')),
                            PosX  = float.Parse(photo.PosX.Replace('.', ',')),
                            PosY  = float.Parse(photo.PosY.Replace('.', ','))
                        };
                        dbUse.StaticImageModel.AddOrUpdate(photos);
                    }
                }
                if (a.Count != 0)
                {
                    dbUse.PositionModels.RemoveRange(picture.PositionModels.Where(t => dbUse.Entry(t).State == EntityState.Unchanged));
                }
                if (b.stamps.Any())
                {
                    dbUse.StampPositions.RemoveRange(picture.StampPositions.Where(t => dbUse.Entry(t).State == EntityState.Unchanged));
                }
                dbUse.SaveChanges();
            }

            SendDbUtility.UpdateImage(int.Parse(b.Id), b.Name);
            return(true);
        }
        public ActionResult UpdatePicture(string Name, int Id)
        {
            SendDbUtility.UpdateImage(Id, Name);

            return(RedirectToAction("EditorPattern", "Pattern"));
        }