public MapObject ToDBModel()
        {
            var mo = new MapObject()
            {
                Address     = UserData.ZoneAdress,
                ObjectType  = UserData.ZoneSmokingType,
                TypeID      = UserData.ZoneType,
                CreateDate  = DateTime.Now,
                CreatorID   = (Guid)Membership.GetUser().ProviderUserKey,
                Name        = UserData.ZoneName,
                Description = UserData.ZoneDescr,
            };

            if (HasPolygon)
            {
                var coords =
                    Polygon.Select(
                        (x, index) =>
                        new MapCoord()
                {
                    IsMarker = false, XPos = x.Lat, YPos = x.Lng, OrderNum = index, MapObject = mo
                }).ToList();
            }

            var mainCoord = new MapCoord()
            {
                IsMarker  = true,
                XPos      = Marker.Lat,
                YPos      = Marker.Lng,
                OrderNum  = 0,
                MapObject = mo
            };

            if (UserData.ZonePhoto.IsFilled())
            {
                var fi    = new FileInfo(HttpContext.Current.Server.MapPath(UserData.ZonePhoto));
                var photo = new MapObjectPhoto()
                {
                    MapObject = mo, RawData = fi.ToBinary()
                };
            }

            return(mo);
        }
        public virtual ContentResult AddObject(string qs)
        {
            var    objData = new PointData().FromJson <PointData>(qs);
            string msg     = "1";

            if (!AccessHelper.IsAuthClient)
            {
                msg = "Для добавления точки необходимо авторизоваться на сайте";
            }
            else
            {
                if (objData.UserData.ID == 0)
                {
                    try
                    {
                        var data = objData.ToDBModel();
                        db.MapObjects.InsertOnSubmit(data);
                        db.SubmitChanges();

                        MailingList.Get("AddNotification")
                        .WithReplacements(
                            new[]
                        {
                            new MailReplacement("{OBJTYPE}", objData.HasPolygon ? "зона" : "объект"),
                            new MailReplacement("{LINK}", AccessHelper.SiteUrl + data.CommentPageLink)
                        }
                            .
                            ToList()).Send();


                        msg = "1";
                    }
                    catch (Exception e)
                    {
                        msg = e.Message;
                    }
                }
                else
                {
                    try
                    {
                        var dbmodel = db.MapObjects.First(x => x.ID == objData.UserData.ID);


                        if (dbmodel.CreatorID != AccessHelper.CurrentUserKey && !AccessHelper.IsMaster)
                        {
                            msg = "У вас нет прав на редактирование этой точки";
                        }
                        else
                        {
                            dbmodel.LoadPossibleProperties(objData.ToDBModel(), new string[] { "ID" });

                            if (objData.UserData.ZonePhoto.IsFilled())
                            {
                                db.MapObjectPhotos.DeleteAllOnSubmit(
                                    db.MapObjectPhotos.Where(x => x.ObjectID == objData.UserData.ID));
                            }

                            db.MapCoords.DeleteAllOnSubmit(db.MapCoords.Where(x => x.ObjectID == objData.UserData.ID));

                            db.SubmitChanges();

                            if (objData.HasPolygon)
                            {
                                var coords =
                                    objData.Polygon.Select(
                                        (x, index) =>
                                        new MapCoord()
                                {
                                    IsMarker  = false,
                                    XPos      = x.Lat,
                                    YPos      = x.Lng,
                                    OrderNum  = index,
                                    MapObject = dbmodel
                                }).ToList();
                            }

                            var mainCoord = new MapCoord()
                            {
                                IsMarker  = true,
                                XPos      = objData.Marker.Lat,
                                YPos      = objData.Marker.Lng,
                                OrderNum  = 0,
                                MapObject = dbmodel
                            };

                            if (objData.UserData.ZonePhoto.IsFilled())
                            {
                                var fi    = new FileInfo(HttpContext.Server.MapPath(objData.UserData.ZonePhoto));
                                var photo = new MapObjectPhoto()
                                {
                                    MapObject = dbmodel, RawData = fi.ToBinary()
                                };
                            }

                            db.SubmitChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        msg = e.Message;
                    }
                }
            }
            return(new ContentResult()
            {
                Content = msg,
                ContentEncoding = Encoding.UTF8
            });
        }