public async Task <TreasureMap> Update(TreasureMap treasureMap) { _context.TreasureMaps.Update(treasureMap); await _context.SaveChangesAsync(); return(treasureMap); }
public async Task <Guid> CreateAsync(User user, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (_context.Users.Any(x => x.Username == user.Username)) { throw new AppException("Username \"" + user.Username + "\" is already taken"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; user.Id = Guid.NewGuid(); _context.Users.Add(user); var created = await _context.SaveChangesAsync(); if (created < 1) { throw new InvalidOperationException("Could not create user."); } return(user.Id); }
public async Task <Guid> CreateGemAsync( Guid treasureMapId, Guid iconId, string name, string description, string address, double latitude, double longitude, string notes, string imageUrl, string website, string phone, string yelpUrl, string googleUrl, string menuUrl) { var treasureMap = await _context.TreasureMaps .SingleOrDefaultAsync(r => r.Id == treasureMapId); if (treasureMap == null) { throw new ArgumentException("Invalid treasure map ID."); } var id = Guid.NewGuid(); var newGem = _context.Gems.Add(new GemEntity { Id = id, TreasureMapId = treasureMapId, IconId = iconId, Name = name, Description = description, Address = address, Latitude = latitude, Longitude = longitude, Notes = notes, ImageUrl = imageUrl, Website = website, Phone = phone, YelpUrl = yelpUrl, GoogleUrl = googleUrl, MenuUrl = menuUrl, CreateDate = DateTime.Now, ModDate = DateTime.Now }); var created = await _context.SaveChangesAsync(); if (created < 1) { throw new InvalidOperationException("Could not create gem."); } return(id); }
public async Task <Guid> CreateIconAsync(string name, string url) { var id = Guid.NewGuid(); var newIcon = _context.Icons.Add(new IconEntity { Id = id, Name = name, Url = url }); var created = await _context.SaveChangesAsync(); if (created < 1) { throw new InvalidOperationException("Could not create icon."); } return(id); }
public async Task <DBNull> CreateRouteLineAsync(Guid treasureMapId, double startLatitude, double startLongitude, double endLatitude, double endLongitude) { var treasureMap = await _context.TreasureMaps .SingleOrDefaultAsync(r => r.Id == treasureMapId); if (treasureMap == null) { throw new ArgumentException("Invalid treasure map ID."); } var maxSequence = await _context.RouteLines.MaxAsync(x => (int?)x.Sequence); if (maxSequence != null) { maxSequence++; } var id = Guid.NewGuid(); var newRouteLine = _context.RouteLines.Add(new RouteLineEntity { Id = id, TreasureMapId = treasureMapId, StartLatitude = startLatitude, StartLongitude = startLongitude, EndLatitude = endLatitude, EndLongitude = endLongitude, Sequence = maxSequence ?? 0 }); var created = await _context.SaveChangesAsync(); if (created < 1) { throw new InvalidOperationException("Could not create routeLine."); } return(DBNull.Value); }