Ejemplo n.º 1
0
        public ObservableCollection <Location> SearchLocations(string searchText)
        {
            var           i      = 0;
            AlgoliaClient client = new AlgoliaClient(ConfigurationManager.AppSettings["algolia.applicationId"], ConfigurationManager.AppSettings["algolia.apiKey"]);
            Index         index  = client.InitIndex("testing");

            var res = index.Search(new Query(searchText));

            Console.WriteLine(res["hits"]);

            var count   = res.Count;
            var results = JsonConvert.DeserializeObject <List <Location> >(res["hits"].ToString());

            Locations = new ObservableCollection <Location>();

            //Locations.Clear();

            foreach (var location in results)
            {
                i++;
                location.Index = i;
                Locations.Add(location);
            }

            return(Locations);
        }
        public void TestRetryStrategy_Build()
        {
            var applicationId = "test";
            var mockHttp      = new MockHttpMessageHandler();
            var hosts         = new string[] { applicationId + "-1.algolianet.com", applicationId + "-2.algolianet.com" };

            mockHttp.When(HttpMethod.Get, "https://" + hosts[0] + "/1/indexes/").Respond(HttpStatusCode.RequestTimeout);
            mockHttp.When(HttpMethod.Get, "https://" + hosts[0] + "/1/indexes/test/settings").Respond("application/json", "{\"fromFirstHost\":[]}");
            mockHttp.When(HttpMethod.Get, "https://" + hosts[0] + "/1/indexes/test/browse").Respond("application/json", "{\"fromFirstHost\":[]}");

            mockHttp.When(HttpMethod.Get, "https://" + hosts[1] + "/1/indexes/").Respond("application/json", "{\"fromSecondHost\":[]}");
            mockHttp.When(HttpMethod.Get, "https://" + hosts[1] + "/1/indexes/test/settings").Respond("application/json", "{\"fromSecondHost\":[]}");
            mockHttp.When(HttpMethod.Get, "https://" + hosts[1] + "/1/indexes/test/browse").Respond("application/json", "{\"fromSecondHost\":[]}");

            var client = new AlgoliaClient("test", "test", hosts, mockHttp);

            client._dsnInternalTimeout = 2;
            Assert.AreEqual(JObject.Parse("{\"fromSecondHost\":[]}").ToString(), client.ListIndexes().ToString());

            //first host back up again but no retry because lastModified < _dsnInternalTimeout, stick with second host
            Assert.AreEqual(JObject.Parse("{\"fromSecondHost\":[]}").ToString(), client.InitIndex("test").GetSettings().ToString());
            Thread.Sleep(10000);
            //lastModified > _dsnInternalTimeout, retry on first host
            Assert.AreEqual(JObject.Parse("{\"fromFirstHost\":[]}").ToString(), client.InitIndex("test").Browse().ToString());
        }
Ejemplo n.º 3
0
        public void TestClientWithMock()
        {
            var client = new AlgoliaClient("test", "test", null, getEmptyHandler());

            Assert.Equal(JObject.Parse("{\"items\":[]}").ToString(), client.ListIndexes().ToString());
            Assert.Equal(JObject.Parse("{\"results\":[]}").ToString(), client.InitIndex("{indexName}").GetObjects(new string[] { "myID" }).ToString());
        }
Ejemplo n.º 4
0
 public void TestInitialize()
 {
     _testApiKey        = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY");
     _testApplicationID = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID");
     _client            = new AlgoliaClient(_testApplicationID, _testApiKey);
     _index             = _client.InitIndex(safe_name("àlgol?à-csharp"));
 }
Ejemplo n.º 5
0
 public BaseTest()
 {
     _testApiKey        = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY");
     _testApplicationID = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID");
     _client            = new AlgoliaClient(_testApplicationID, _testApiKey);
     _index             = _client.InitIndex(GetSafeName("àlgol?à-csharp"));
     _indexHelper       = new IndexHelper <TestModel>(_client, GetSafeName("àlgol?à-csharp"));
 }
Ejemplo n.º 6
0
        public void TestInitialize()
        {
            var testApiKey        = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY") ?? "MY-ALGOLIA-API-KEY";
            var testApplicationID = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID") ?? "MY-ALGOLIA-APPLICATION-ID";

            _client      = new AlgoliaClient(testApplicationID, testApiKey);
            _indexHelper = new IndexHelper <TestModel>(_client, GetSafeName("algolia-csharp"));
        }
Ejemplo n.º 7
0
        public AlgoliaService()
        {
            client = new AlgoliaClient(
                DotNetEnv.Env.GetString("ALGOLIA_APPLICATION_ID"),
                DotNetEnv.Env.GetString("ALGOLIA_MEDIA_KEY")
                );

            mediaIndex = client.InitIndex(DotNetEnv.Env.GetString("ALGOLIA_MEDIA_INDEX"));
        }
Ejemplo n.º 8
0
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;

            algoliaClient = new AlgoliaClient("<APPLICATION_ID>", "<SEARCH_ONLY_API_KEY>");
            algoliaIndex  = algoliaClient.InitIndex("packages");
        }
        private AlgoliaClient CreateSearchClient(CommerceContext context)
        {
            if (_algoliaSearchClient != null)
            {
                return(_algoliaSearchClient);
            }

            var algoliaPolicy = PipelineBlockHelper.GetAlgoliaPolicy(context);

            _algoliaSearchClient = new AlgoliaClient(algoliaPolicy.ApplicationId, algoliaPolicy.SearchApiKey);
            return(_algoliaSearchClient);
        }
Ejemplo n.º 10
0
 public IActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid && model != null)
     {
         if (model.Email == null || model.Email == "" || model.Firstname == null ||
             model.Firstname == "" || model.Lastname == null || model.Lastname == "" || model.Password == null || model.Password == "")
         {
             ViewData["Error"] = "Field missing";
             return(RedirectToAction("Index"));
         }
         try
         {
             Core.Models.User user = new Core.Models.User
             {
                 Email       = model.Email,
                 Password    = Users.HashPassword(model.Password),
                 Firstname   = model.Firstname,
                 Lastname    = model.Lastname,
                 Nickname    = $"{model.Firstname.ToLower()}.{model.Lastname.ToLower()}",
                 Description = "",
                 Gender      = "",
                 Phone       = "",
                 Picture     = "",
                 AccessToken = "",
                 Private     = false
             };
             var userInDb = DataAccess.User.Add(user);
             if (userInDb == null)
             {
                 ViewData["Error"] = "Impossible to save the current user";
                 return(RedirectToAction("Index"));
             }
             userInDb.objectID = user.Id.ToString();
             AlgoliaClient client = new AlgoliaClient(_configuration.GetValue <string>("Algolia:AppId"),
                                                      _configuration.GetValue <string>("Algolia:AppSecret"));
             Index usersIndex = client.InitIndex(_configuration.GetValue <string>("Algolia:IndexUser"));
             usersIndex.AddObject(userInDb);
             DataAccess.User.Update(userInDb);
             Helper.AppHttpContext.HttpContext.Session.SetObject <long>("currentUserId", userInDb.Id);
             return(Redirect(_configuration.GetValue <string>("RedirectFront")));
         }
         catch (Exception e)
         {
             ViewData["Error"] = "Impossible to save the current user\n" + e.Message;
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 11
0
        public static async Task Run(
            [CosmosDBTrigger("database", "collection", ConnectionStringSetting = "CosmoDB")]
            IReadOnlyList <Document> documents)
        {
            var client = new AlgoliaClient(AlgoliaApplicationId, AlgoliaApiKey);
            var index  = client.InitIndex(AlgoliaIndex);

            foreach (var document in documents)
            {
                document.SetPropertyValue("objectID", document.Id);
                await index.AddObjectAsync(document);
            }
        }
Ejemplo n.º 12
0
        public DataService()
        {
            if (ConfigurationManager.AppSettings != null)
            {
                AlgoliaApplicationID = ConfigurationManager.AppSettings["algolia.applicationId"];
                AlgoliaApiKey        = ConfigurationManager.AppSettings["algolia.apiKey"];
                AlgoliaIndex         = ConfigurationManager.AppSettings["algolia.index"];
                HelpSGFAPIRoot       = ConfigurationManager.AppSettings["helpsgf.apiroot"];
            }

            _client = new AlgoliaClient(AlgoliaApplicationID, AlgoliaApiKey);
            _index  = _client.InitIndex(AlgoliaIndex);
        }
Ejemplo n.º 13
0
        public BaseTest()
        {
            _testApiKey        = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY");
            _testApplicationID = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID");
            _client            = new AlgoliaClient(_testApplicationID, _testApiKey);
            _index             = _client.InitIndex(GetSafeName("àlgol?à-csharp"));
            _analytics         = new Analytics(_client);
            _indexHelper       = new IndexHelper <TestModel>(_client, GetSafeName("àlgol?à-csharp"));

            _testApiKeyMCM        = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY_MCM");
            _testApplicationIDMCM = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID_MCM");
            _clientMCM            = new AlgoliaClient(_testApplicationIDMCM, _testApiKeyMCM);
            _userID = GetUniqueUserID("csharp-client");
        }
Ejemplo n.º 14
0
        public async void BadClientCreation()
        {
            string[] _hosts = new string[] { "localhost.algolia.com:8080", "" };
            try
            {
                new AlgoliaClient("", _testApiKey);
                Assert.Fail();
            }
            catch (Exception)
            { }
            try
            {
                new AlgoliaClient(_testApplicationID, "");
                Assert.Fail();
            }
            catch (Exception)
            { }
            try
            {
                new AlgoliaClient(_testApplicationID, "", _hosts);
                Assert.Fail();
            }
            catch (Exception)
            { }
            try
            {
                new AlgoliaClient("", _testApiKey, _hosts);
                Assert.Fail();
            }
            catch (Exception)
            { }
            try
            {
                var badClient = new AlgoliaClient(_testApplicationID, _testApiKey, null);
                Assert.Fail();
            }
            catch (Exception)
            { }
            try
            {
                var badClient = new AlgoliaClient(_testApplicationID, _testApiKey, _hosts);
                await badClient.ListIndexes();

                Assert.Fail();
            }
            catch (Exception)
            { }
        }
        public void TestDnsTimeout()
        {
            var hosts = new List <string> {
                _testApplicationID + "-dsn.algolia.biz",
                _testApplicationID + "-dsn.algolia.net",
                _testApplicationID + "-1.algolianet.com",
                _testApplicationID + "-2.algolianet.com",
                _testApplicationID + "-3.algolianet.com"
            };

            var _client = new AlgoliaClient(_testApplicationID, _testApiKey, hosts);

            _client.setTimeout(0.5, 0.5);
            var startTime = DateTime.Now;
            var index     = _client.ListIndexes();

            Assert.IsTrue(startTime.AddSeconds(0.5) < DateTime.Now);
        }
Ejemplo n.º 16
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Create our Algolia client
            var algoliaClient = new AlgoliaClient("<APPLICATION_ID>", "<ADMIN_API_KEY>");

            // Create our index helper
            var indexHelper = new IndexHelper <Package>(algoliaClient, "packages", "Id");

            // Store our index helper in an application variable.
            // We don't want to create a new one each time
            // because it will impact performance.
            Application.Add("PackageIndexHelper", indexHelper);
        }
Ejemplo n.º 17
0
        public ObservableCollection <Location> FilterLocations(string filterString)
        {
            var           i      = 0;
            AlgoliaClient client = new AlgoliaClient(ConfigurationManager.AppSettings["algolia.applicationId"], ConfigurationManager.AppSettings["algolia.apiKey"]);
            Index         index  = client.InitIndex("testing");

            string filterQuerystring = "";
            var    filterStrings     = filterString.Split(',');

            foreach (var filter in filterStrings)
            {
                if (!string.IsNullOrEmpty(filterQuerystring))
                {
                    filterQuerystring += " AND ";
                }

                filterQuerystring += "service_types:" + "\"" + filter + "\"";
            }

            var query = new Query();

            query.SetFilters(filterQuerystring);

            var res = index.Search(query);

            Console.WriteLine(res["hits"]);

            var count   = res.Count;
            var results = JsonConvert.DeserializeObject <List <Location> >(res["hits"].ToString());

            Locations = new ObservableCollection <Location>();

            //Locations.Clear();

            foreach (var location in results)
            {
                i++;
                location.Index = i;
                Locations.Add(location);
            }

            return(Locations);
        }
Ejemplo n.º 18
0
        public void Process(PipelineArgs args)
        {
            Log.Info("InitIndexes", this);
            var client = new AlgoliaClient(Settings.ApiApplicationId, Settings.ApiAdminKey);

            var indexes = client.ListIndexes().GetValue("items").ToObject <List <IndexInfo> >();

            indexes = indexes.Where(i => i.Name.StartsWith(Settings.PageIndexesPrefix)).ToList();

            Log.Info("Number of indexes:" + indexes.Count, this);

            foreach (IndexInfo indexInfo in indexes)
            {
                var index = client.InitIndex(indexInfo.Name);

                Log.Info("Index:" + indexInfo.Name, this);

                var settings = index.GetSettings().ToObject <IndexSettings>();

                if (settings.AttributesToIndex == null)
                {
                    // settings.AttributesToIndex = new List<string> { "title", "content", "name" };
                    settings.AttributesToIndex = Settings.IndexingSettings.IncludedFields
                                                 .Where(f => f.Indexed)
                                                 .Select(f => f.FieldName)
                                                 .ToList();

                    settings.AttributesForFaceting = Settings.IndexingSettings.IncludedFields
                                                     .Where(f => f.FieldType == FieldType.Facet)
                                                     .Select(f => f.FieldName)
                                                     .ToList();
                    var idsFields = settings.AttributesForFaceting.Select(a => a + "_ids").ToList();
                    settings.AttributesForFaceting.AddRange(idsFields);

                    index.SetSettings(JObject.FromObject(settings), true);
                }
            }
        }
 public void TestTimeoutHandling()
 {
     _client.setTimeout(0.001, 0.001);
     try
     {
         _client.ListIndexes();
         _client = new AlgoliaClient(_testApplicationID, _testApiKey);
         _index  = _client.InitIndex(safe_name("àlgol?à-csharp"));
         Assert.Fail("Should throw an error");
     }
     catch (AlgoliaException)
     {
         // Reset
         _client = new AlgoliaClient(_testApplicationID, _testApiKey);
         _index  = _client.InitIndex(safe_name("àlgol?à-csharp"));
     }
     catch (OperationCanceledException)
     {
         _client = new AlgoliaClient(_testApplicationID, _testApiKey);
         _index  = _client.InitIndex(safe_name("àlgol?à-csharp"));
         Assert.Fail("Should throw an AlgoliaException");
     }
 }
 public AlgoliaMonitorIndex()
 {
     _client = new AlgoliaClient(Settings.AlgoliaAppId, Settings.AlgoliaAdminApiKey);
     _index  = _client.InitIndex(Settings.AlgoliaMonitorsIndex);
 }
Ejemplo n.º 21
0
        public async Task <IActionResult> FacebookLoginCallback(string returnUrl = null, string remoteError = null)
        {
            string codeString  = HttpContext.Request.Query["code"].ToString();
            string stateString = HttpContext.Request.Query["state"].ToString();

            if (codeString == null || stateString == null || codeString == "" || stateString == "")
            {
                _logger?.LogInformation($"Impossible to connect. Code: { codeString } and state { stateString } are invalid");
                return(RedirectToAction("Index"));
            }
            string url = "https://graph.facebook.com/v3.0/oauth/access_token?client_id=";

            url += _configuration.GetValue <string>("Facebook:AppId");
            url += "&redirect_uri=";
            url += _configuration.GetValue <string>("Facebook:redirectUri") + "&client_secret=";
            url += _configuration.GetValue <string>("Facebook:AppSecret");
            url += "&code=" + codeString;

            string accessToken = await GetAccessToken(url);

            if (accessToken == null || accessToken == "")
            {
                _logger?.LogInformation($"Impossible to connect. Access Token: { accessToken } is invalid");
                return(RedirectToAction("Index"));
            }

            var client  = new Facebook.Client.FacebookClient();
            var service = new Facebook.Service.FacebookService(client);
            var account = await service.GetAccountAsync(accessToken);

            if (account == null || account.Email == null || account.Email == "")
            {
                _logger?.LogInformation($"Impossible to connect. Impossible to get account information");
                return(RedirectToAction("Index"));
            }

            var currentUser = GetApplicationUser(account, accessToken);
            var userDB      = GetTypeUser(currentUser);

            userDB.Password    = Users.HashPassword(accessToken);
            userDB.AccessToken = accessToken;
            try
            {
                var userInDb = await DataAccess.User.GetFromEmail(userDB.Email);

                if (userInDb == null)
                {
                    //First connection
                    userDB = DataAccess.User.Add(userDB);
                    AlgoliaClient algolia = new AlgoliaClient(_configuration.GetValue <string>("Algolia:AppId"),
                                                              _configuration.GetValue <string>("Algolia:AppSecret"));
                    Index usersIndex = algolia.InitIndex(_configuration.GetValue <string>("Algolia:IndexUser"));
                    userDB.objectID = userDB.Id.ToString();
                    usersIndex.AddObject(userDB);
                    DataAccess.User.Update(userDB);
                }
                else
                {
                    userDB             = userInDb;
                    userDB.Password    = Users.HashPassword(accessToken);
                    userDB.AccessToken = accessToken;
                    DataAccess.User.Update(userDB);
                }
            }
            catch (Exception e)
            {
                _logger?.LogInformation($"Impossible to connect. Impossible to save account information\n" + e.Message);
                return(RedirectToAction("Index"));
            }

            _logger?.LogInformation("User connected");

            _signInManager.Context.Session.SetObject("currentToken", accessToken);
            await _signInManager.Context.Session.CommitAsync();

            Response.Cookies.Append(".Amstramgram.Cookie", userDB.AccessToken);

            return(Redirect(_configuration.GetValue <string>("RedirectFront")));
        }
 public AlgoliaRepository(IAlgoliaConfig algoliaConfig)
 {
     _client    = new AlgoliaClient(algoliaConfig.ApplicationId, algoliaConfig.FullApiKey);
     _indexName = algoliaConfig.IndexName;
     _index     = _client.InitIndex(_indexName);
 }
Ejemplo n.º 23
0
 public Search()
 {
     client = new AlgoliaClient("H32KJL7TN3", "ded83594a24bb787256ec5c09acfd98d");
     db     = new ADBContext();
     this.AddIndexes();
 }
Ejemplo n.º 24
0
 public void TestCleanup()
 {
     _client.DeleteIndex(safe_name("àlgol?à-csharp"));
     _client = null;
 }
Ejemplo n.º 25
0
 public void TestCleanup()
 {
     _client.DeleteIndex(GetSafeName("algolia-csharp"));
     _client = null;
 }
Ejemplo n.º 26
0
 public AlgoliaService()
 {
     client = new AlgoliaClient(APPLICATION_ID, API_KEY);
     index  = client.InitIndex(BUSINESS_INDEX);
 }
Ejemplo n.º 27
0
        public AmstramgramMutation(IMapper mapper, IConfiguration configuration)
        {
            Name = "Mutation";

            AlgoliaClient client = new AlgoliaClient(configuration.GetValue <string>("Algolia:AppId"),
                                                     configuration.GetValue <string>("Algolia:AppSecret"));
            Index usersIndex    = client.InitIndex(configuration.GetValue <string>("Algolia:IndexUser"));
            Index picturesIndex = client.InitIndex(configuration.GetValue <string>("Algolia:IndexPictures"));
            Index tagsIndex     = client.InitIndex(configuration.GetValue <string>("Algolia:IndexTags"));

            Field <UserType>(
                "createUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserInputType> > {
                Name = "user"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.User>("user");
                var user = DataAccess.User.Add(data);
                if (user != null)
                {
                    data.objectID = data.Id.ToString();
                    usersIndex.AddObject(data);
                    //Save object id
                    DataAccess.User.Update(data);
                }
                return(mapper.Map <User>(user));
            }
                );

            Field <UserType>(
                "updateUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserInputType> > {
                Name = "user"
            }
                    ),
                resolve: context =>
            {
                var data     = context.GetArgument <Core.Models.User>("user");
                var userInDb = DataAccess.User.Get(data.Id).Result;
                if (userInDb == null || userInDb.Id == 0)
                {
                    //User doesn't exist
                    return(null);
                }
                data.objectID    = userInDb.objectID;
                data.AccessToken = userInDb.AccessToken;
                bool result      = DataAccess.User.Update(data);
                if (result)
                {
                    usersIndex.PartialUpdateObject(JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(data)));
                }
                return(mapper.Map <User>(result ? data : null));
            }
                );

            Field <PictureType>(
                "createPicture",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PictureInputType> > {
                Name = "picture"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.Picture>("picture");
                if (DataAccess.User.Get(data.UserId).Result == null)
                {
                    return(null);
                }
                var date       = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
                data.CreatedAt = date;
                data.UpdatedAt = date;
                var picture    = DataAccess.Picture.Add(data);
                foreach (var tag in data.Tags)
                {
                    tagsIndex.AddObject(tag);
                }
                data.objectID = data.Id.ToString();
                picturesIndex.AddObject(data);
                DataAccess.Picture.Update(data);
                return(mapper.Map <Picture>(picture));
            }
                );

            Field <CommentType>(
                "createComment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <CommentInputType> > {
                Name = "comment"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.Comment>("comment");
                if (DataAccess.User.Get(data.UserId).Result == null || DataAccess.Picture.Get(data.PictureId).Result == null)
                {
                    return(null);
                }
                if (data.Text == "")
                {
                    return(null);
                }
                var date       = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
                data.CreatedAt = date;
                var comment    = DataAccess.Comment.Add(data);
                return(mapper.Map <Comment>(comment));
            }
                );

            Field <CommentType>(
                "deleteComment",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <CommentInputType> > {
                Name = "comment"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.Comment>("comment");
                if (DataAccess.User.Get(data.UserId).Result == null || DataAccess.Picture.Get(data.PictureId).Result == null)
                {
                    return(null);
                }
                DataAccess.Comment.Delete(data);
                return(mapper.Map <Comment>(data));
            }
                );

            Field <LikeType>(
                "createLike",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LikeInputType> > {
                Name = "like"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.Like>("like");
                if (DataAccess.User.Get(data.UserId).Result == null || DataAccess.Picture.Get(data.PictureId).Result == null)
                {
                    return(null);
                }
                if (DataAccess.Like.Find(data.UserId, data.PictureId) != null)
                {
                    return(null);
                }
                var date       = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
                data.CreatedAt = date;
                var like       = DataAccess.Like.Add(data);
                return(mapper.Map <Like>(like));
            }
                );

            Field <LikeType>(
                "deleteLike",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LikeInputType> > {
                Name = "like"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.Like>("like");
                if (DataAccess.User.Get(data.UserId).Result == null || DataAccess.Picture.Get(data.PictureId).Result == null)
                {
                    return(null);
                }
                var like = DataAccess.Like.Find(data.UserId, data.PictureId);
                if (like == null)
                {
                    return(null);
                }
                DataAccess.Like.Delete(like);
                return(mapper.Map <Like>(like));
            }
                );

            Field <UserFollowerType>(
                "createFollower",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserFollowerInputType> > {
                Name = "follower"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.UserFollower>("follower");
                if (DataAccess.User.Get(data.UserId).Result == null || DataAccess.User.Get(data.FollowerId).Result == null)
                {
                    return(null);
                }
                if (data.UserId == data.FollowerId)
                {
                    return(null);
                }
                if (DataAccess.UserFollower.Find(data.UserId, data.FollowerId) != null)
                {
                    return(null);
                }
                var follower = DataAccess.UserFollower.Add(data);
                return(mapper.Map <UserFollower>(follower));
            }
                );

            Field <UserFollowerType>(
                "deleteFollower",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserFollowerInputType> > {
                Name = "follower"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.UserFollower>("follower");
                if (DataAccess.User.Get(data.UserId).Result == null || DataAccess.User.Get(data.FollowerId).Result == null)
                {
                    return(null);
                }
                var follower = DataAccess.UserFollower.Find(data.UserId, data.FollowerId);
                if (follower == null)
                {
                    return(null);
                }
                DataAccess.UserFollower.Delete(follower);
                return(mapper.Map <UserFollower>(follower));
            }
                );

            Field <UserType>(
                "registerUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserInputType> > {
                Name = "user"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.User>("user");
                if (data.Email == null || data.Email == "" || data.Password == null || data.Password == "")
                {
                    return(null);
                }
                data.Password = Helper.Users.HashPassword(data.Password);
                var user      = DataAccess.User.Add(data);
                user.objectID = data.Id.ToString();
                usersIndex.AddObject(data);
                DataAccess.User.Update(data);
                Helper.AppHttpContext.HttpContext.Response.Cookies.Append(".Amstramgram.Cookie", user.Password);
                return(mapper.Map <User>(user));
            }
                );

            Field <UserType>(
                "connectUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <UserInputType> > {
                Name = "user"
            }
                    ),
                resolve: context =>
            {
                var data = context.GetArgument <Core.Models.User>("user");
                if (data.Email == null || data.Email == "" || data.Password == null || data.Password == "")
                {
                    return(null);
                }
                data.Password = Helper.Users.HashPassword(data.Password);
                var user      = DataAccess.User.SignInUser(data).Result;
                Helper.AppHttpContext.HttpContext.Response.Cookies.Append(".Amstramgram.Cookie", user.AccessToken);
                return(mapper.Map <User>(user));
            }
                );
        }