public bool DeleteItem(IDbConnection connection, BookmarkOut bm, int currentUserId)
        {
            var bookmark = GetUserBookmarkById(connection, currentUserId, bm.Id);

            Delete(connection, bookmark.Id);
            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// </summary>
 /// <param name="bm"></param>
 /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
 /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
 /// <returns></returns>
 public async Task <bool> BookmarkDeleteItem(BookmarkOut bm)
 {
     return(await _contextAction(connection =>
     {
         var cr = _getCurrentUser(connection);
         return _gUserBookmarkService.DeleteItem(connection, bm, cr.UserId);
     }));
 }
Esempio n. 3
0
 /// <summary>
 /// </summary>
 /// <param name="bm"></param>
 /// <exception cref="ArgumentNullException">Error.ConnectionUserNotExist</exception>
 /// <exception cref="ArgumentNullException">Error.ConnectionUserNotConnected</exception>
 /// <returns></returns>
 public async Task <object> BookmarkAddBookmark(BookmarkOut bm)
 {
     return(await _contextAction(connection =>
     {
         var cr = _getCurrentUser(connection);
         var crPremium = cr.GetPremiumDataModel(connection, _storeService);
         var hasPremium = !crPremium.Finished;
         return
         _gUserBookmarkService.AddBookmark(connection, bm, cr.UserId, hasPremium, _mapInfoService,
                                           _gGeometryPlanetService, _systemService, _gSectorsService);
     }));
 }
        public object AddBookmark(IDbConnection connection, BookmarkOut bm, int currentUserId, bool hasPremium,
                                  IMapInfoService mapInfoService, IGGeometryPlanetService geometryPlanetService, ISystemService systemService, IGSectorsService gSectorsService)
        {
            _saveNewBookmark(connection, bm, currentUserId, hasPremium, geometryPlanetService, systemService, gSectorsService);
            if (bm.IsFull)
            {
                return(GetPlanshetViewData(connection, mapInfoService, currentUserId));
            }

            if (string.Equals(BookmarkOut.Planet, bm.TypeName, StringComparison.CurrentCultureIgnoreCase))
            {
                var item    = GetUserBookmark(connection, currentUserId, bm.TypeId, bm.ObjectId);
                var outData = mapInfoService.GetPlanetOutData(connection, item, currentUserId);
                if (outData == null)
                {
                    throw new Exception(Error.NoData);
                }
                return(outData);
            }

            if (string.Equals(BookmarkOut.Star, bm.TypeName, StringComparison.CurrentCultureIgnoreCase))
            {
                var item    = GetUserBookmark(connection, currentUserId, bm.TypeId, bm.ObjectId);
                var outData = mapInfoService.GetSystemOutData(connection, item);
                if (outData == null)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                return(outData);
            }

            if (string.Equals(BookmarkOut.Sector, bm.TypeName, StringComparison.CurrentCultureIgnoreCase))
            {
                var item    = GetUserBookmark(connection, currentUserId, bm.TypeId, bm.ObjectId);
                var outData = mapInfoService.GetSectorOutData(connection, item);
                if (outData == null)
                {
                    throw new Exception(Error.NoData);
                }
                return(outData);
            }
            throw new NotImplementedException();
        }
        private void _saveNewBookmark(IDbConnection connection, BookmarkOut bm, int currentUserId, bool hasPremium, IGGeometryPlanetService geometryPlanetService, ISystemService systemService, IGSectorsService gSectorsService)
        {
            var hasData = false;

            if (_isFull(connection, currentUserId, hasPremium))
            {
                throw new Exception(Error.BookMarkLimitDone);
            }

            if (string.Equals(BookmarkOut.Planet, bm.TypeName, StringComparison.CurrentCultureIgnoreCase))
            {
                var planetTypeId = geometryPlanetService.GetPlanetType(connection, bm.ObjectId);
                if (planetTypeId == 0)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                hasData =
                    (GetUserBookmark(connection, currentUserId, planetTypeId, bm.ObjectId) !=
                     null);
                bm.TypeId = planetTypeId;
            }

            else if (string.Equals(BookmarkOut.Star, bm.TypeName, StringComparison.CurrentCultureIgnoreCase))
            {
                var starTypeId = systemService.GetDetailSystemBySystemId(connection, bm.ObjectId, i => i.TypeId);

                if (starTypeId == 0)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                hasData   = (GetUserBookmark(connection, currentUserId, starTypeId, bm.ObjectId) != null);
                bm.TypeId = starTypeId;
            }

            else if (string.Equals(BookmarkOut.Sector, bm.TypeName, StringComparison.CurrentCultureIgnoreCase))
            {
                var sectorTypeId = gSectorsService.GetById(connection, (short)bm.ObjectId, i => i.TypeId);
                if (sectorTypeId == 0)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }

                hasData   = (GetUserBookmark(connection, currentUserId, sectorTypeId, bm.ObjectId) != null);
                bm.TypeId = sectorTypeId;
            }
            else
            {
                throw new NotImplementedException();
            }

            if (hasData)
            {
                throw new Exception(Error.BookmarkIsExist);
            }
            AddOrUpdate(connection, new UserBookmarkDataModel
            {
                UserId   = currentUserId,
                TypeId   = bm.TypeId,
                ObjectId = bm.ObjectId
            });
        }