Exemplo n.º 1
0
        public ActionResult DeleteUser()
        {
            var authorizationToken = this.Request.Headers["Authorization"].ToString();

            if (authorizationToken == "")
            {
                return(Unauthorized());
            }
            int id = Jwt.GetIdFromToken(authorizationToken);

            if (id == 0)
            {
                return(Unauthorized());
            }
            dynamic result = Repository.DeleteUser(id);

            if (result == null)
            {
                return(NotFound(new { message = "not found" }));
            }
            if (result.ToString() == "ERROR")
            {
                return(BadRequest(new { message = "Error" }));
            }
            return(Ok(new { message = "Done" }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteImage()
        {
            var authorizationToken = this.Request.Headers["Authorization"].ToString();

            if (authorizationToken == "")
            {
                return(Unauthorized());
            }
            int id = Jwt.GetIdFromToken(authorizationToken);

            if (id == 0)
            {
                return(Unauthorized());
            }

            string storePath = "F:/Licenta/matchbox/matchbox-server/Uploads/";
            var    filename  = id.ToString() + ".jpg";

            var path = Path.Combine(storePath, filename);

            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
                return(Ok(new { succes = "true" }));
            }
            else
            {
                return(NotFound(new { message = "File not found" }));
            }
        }
Exemplo n.º 3
0
        public ActionResult ConversationSeen([FromBody] Conversation request)
        {
            var authorizationToken = this.Request.Headers["Authorization"].ToString();

            if (authorizationToken == "")
            {
                return(Unauthorized());
            }
            int id = Jwt.GetIdFromToken(authorizationToken);

            if (id == 0)
            {
                return(Unauthorized());
            }
            dynamic result = Repository.SetConversationToSeen(request, id);

            if (result == null)
            {
                return(NotFound(new { message = "not found" }));
            }
            if (result.ToString() == "ERROR")
            {
                return(BadRequest(new { message = "Error" }));
            }
            return(Ok(result));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UploadImage(IFormCollection form)
        {
            string storePath = "F:/Licenta/matchbox/matchbox-server/Uploads/";

            if (form.Files == null || form.Files[0].Length == 0)
            {
                return(BadRequest(new { message = "" }));
            }
            var authorizationToken = this.Request.Headers["Authorization"].ToString();

            if (authorizationToken == "")
            {
                return(Unauthorized());
            }
            int id = Jwt.GetIdFromToken(authorizationToken);

            if (id == 0)
            {
                return(Unauthorized());
            }

            string filename = id.ToString() + ".jpg";
            var    path     = Path.Combine(storePath, filename);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await form.Files[0].CopyToAsync(stream);
            }

            return(Ok(new { succes = "true" }));
        }
Exemplo n.º 5
0
        public ActionResult GetMatch()
        {
            var authorizationToken = this.Request.Headers["Authorization"].ToString();

            if (authorizationToken == "")
            {
                return(Unauthorized());
            }
            int id = Jwt.GetIdFromToken(authorizationToken);

            if (id == 0)
            {
                return(Unauthorized());
            }
            dynamic result = Repository.GetMatch(id);

            if (result == null)
            {
                return(NotFound(new { message = "not found" }));
            }
            if (result.ToString() == "ERROR")
            {
                return(BadRequest(new { message = "Error" }));
            }

            foreach (var res in result)
            {
                dynamic user1Location = Repository.GetUserLocationInfo(id);
                dynamic user2Location = Repository.GetUserLocationInfo(Convert.ToInt32(res.ID));


                double dist = GeoLocation.distanceBetweenTwoUsers(Convert.ToDouble(user1Location.LATITUDE), Convert.ToDouble(user1Location.LONGITUDE),
                                                                  Convert.ToDouble(user2Location.LATITUDE), Convert.ToDouble(user2Location.LONGITUDE));
                dynamic maxDistResp = Repository.GetUserMaxDistance(id);
                double  maxDistance = Convert.ToDouble(maxDistResp.MAXDISTANCE);

                if (dist <= maxDistance * 1000)
                {
                    int distInKm = (int)(dist / 1000 + 0.5);
                    if (distInKm > 0)
                    {
                        res.MAXDISTANCE = Convert.ToString(distInKm);
                    }
                    else
                    {
                        res.MAXDISTANCE = Convert.ToString(1);
                    }
                    return(Ok(res));
                }
            }
            return(NotFound(new { message = "not found" }));
        }