public async Task <HttpResponseMessage> Post()
        {
            var stream = await Request.Content.ReadAsStreamAsync();

            MemoryStream memStr = new MemoryStream();

            try
            {
                stream.CopyTo(memStr);
                stream.Close();
                var bitmap       = new Bitmap(memStr);
                var currentFrame = new Image <Bgr, Byte>(bitmap);
                var face         = _detection.DetectMultiScale(currentFrame, _cascadePrecision, 0);

                if (face.Length > 0)
                {
                    Image <Gray, byte> grayFaceImage = currentFrame.Convert <Gray, byte>().Copy(face[0]).Resize(_grayFaceImageSize, _grayFaceImageSize, Inter.Cubic);
                    MemoryStream       memoryStream  = new MemoryStream();
                    grayFaceImage.ToBitmap().Save(memoryStream, ImageFormat.Png);
                    return(JsonResponse.JsonHttpResponse <Object>(memoryStream.ToArray()));
                }
                else
                {
                    return(JsonResponse.JsonHttpResponse <Object>(false));
                }
            }
            catch (Exception e)
            {
                return(JsonResponse.JsonHttpResponse <Object>(null));
            }
        }
Пример #2
0
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var credentials = JsonConvert.DeserializeObject <FrontendUser>(jsonContent);

            if (_mInputValidator.UsernameTaken(credentials.username))
            {
                return(JsonResponse.JsonHttpResponse <object>(
                           ConfigurationManager.AppSettings["usernameError"]));
            }

            if (_mInputValidator.EmailTaken(credentials.email))
            {
                return(JsonResponse.JsonHttpResponse <object>(
                           ConfigurationManager.AppSettings["emailError"]));
            }

            var user = new User
            {
                Nickname = credentials.username, Password = credentials.password, Email = credentials.email,
                Name     = credentials.firstName, Surname = credentials.lastName
            };
            var result = await _mUserRepository.Add(user);

            return(JsonResponse.JsonHttpResponse <object>(true));
        }
        //GET: api/User
        //public bool Get()
        //{
        //return _mUserPresenter.GetUserList();
        //}

        //// GET: api/User/5
        //public IHttpActionResult Get(string username)
        //{
        //    var foundUser = _mUserRepository.GetList().FirstOrDefault(user => user.Nickname == username);
        //    if (foundUser == null)
        //    {
        //        return NotFound();
        //    }
        //    return Ok(foundUser);
        //}

        // POST: api/User
        //public void Post([FromBody]string value)
        //{
        //}

        //PUT: api/UserRegistration/5
        public async Task <HttpResponseMessage> Put()
        {
            HttpContent requestContent = Request.Content;
            string      jsonContent    = await requestContent.ReadAsStringAsync();

            var credentials = JsonConvert.DeserializeObject <User>(jsonContent);

            if (_mInputValidator.UsernameTaken(credentials.Nickname))
            {
                return(JsonResponse.JsonHttpResponse <Object>(StaticStrings.noUser));
            }
            else if (_mInputValidator.EmailTaken(credentials.Email))
            {
                return(JsonResponse.JsonHttpResponse <Object>(StaticStrings.EmailErr));
            }
            else
            {
                _mUserRepository.Add(credentials);
                return(JsonResponse.JsonHttpResponse <Object>(true));
            }

            //if (!_mInputValidator.UsernameTaken(credentials.Nickname)
            //    || !_mInputValidator.EmailTaken(credentials.Email))
            //{
            //    _mUserRepository.Add(credentials);
            //    return JsonResponse.JsonHttpResponse<Object>(true);
            //}
            //else
            //{
            //    return JsonResponse.JsonHttpResponse<Object>(false);
            //}
        }
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            return(JsonResponse.JsonHttpResponse <object>(_bookPresenter.GetUserHistoryBooks(jsonContent)));
        }
        public async Task <HttpResponseMessage> Post()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            return(JsonResponse.JsonHttpResponse <object>(_takenBookPresenter.IsTaken(jsonContent)));
        }
        public async Task <HttpResponseMessage> Post()
        {
            var requestContent = Request.Content;
            var book           = await requestContent.ReadAsStringAsync();

            return(JsonResponse.JsonHttpResponse <object>
                       (_reviewPresenter.GetBookReviews(book)));
        }
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var isbn = JsonConvert.DeserializeObject <Code>(jsonContent);

            _book = _bookPresenter.FindBookByCode(isbn.isbnCode);
            if (_book != null)
            {
                return(JsonResponse.JsonHttpResponse <object>(_book));
            }
            return(JsonResponse.JsonHttpResponse <object>(null));
        }
Пример #8
0
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var credentials = JsonConvert.DeserializeObject <FrontendUser>(jsonContent);

            if (Login(credentials))
            {
                var token = JwtManager.GenerateToken(credentials.username);
                return(JsonResponse.JsonHttpResponse(token));
            }

            throw new HttpResponseException(HttpStatusCode.Unauthorized);
        }
        public async Task <HttpResponseMessage> Post()
        {
            var requestContent = Request.Content;
            var user           = await requestContent.ReadAsStringAsync();

            try
            {
                var list = _takenBookPresenter.GetUserTakenBooks(user);
                return(JsonResponse.JsonHttpResponse <object>(list));
            }
            catch (ArgumentNullException)
            {
                return(JsonResponse.JsonHttpResponse <object>(null));
            }
        }
Пример #10
0
        public HttpResponseMessage Get()
        {
            var b = new Book();
            var e = new BookTakingWarning();

            b.Title           = "a";
            b.Author          = "b";
            b.HasToBeReturned = DateTime.Today;
            try
            {
                e.SendWarningEmail("*****@*****.**", (IBook)b);
                return(JsonResponse.JsonHttpResponse("ok"));
            }
            catch (Exception)
            {
                return(JsonResponse.JsonHttpResponse("ne ok"));
            }
        }
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var review = JsonConvert.DeserializeObject <Reviews>(jsonContent);

            try
            {
                await _reviewRepository.Add(review);

                return(JsonResponse.JsonHttpResponse <object>(true));
            }
            catch (Exception)
            {
                return(JsonResponse.JsonHttpResponse <object>(false));
            }
        }
        public async Task <HttpResponseMessage> Put()
        {
            HttpContent requestContent = Request.Content;
            string      jsonContent    = await requestContent.ReadAsStringAsync();

            var imageFromFrontend = JsonConvert.DeserializeObject <FaceImage>(jsonContent);

            try
            {
                await _dataSource.AddFaceImage(imageFromFrontend);

                return(JsonResponse.JsonHttpResponse <Object>(true));
            }
            catch (Exception e)
            {
                return(JsonResponse.JsonHttpResponse <Object>(null));
            }
        }
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var data = JsonConvert.DeserializeObject <Code>(jsonContent);

            try
            {
                if (_takenBookPresenter.IsTaken(data.isbnCode))
                {
                    await _takenBookPresenter.ReturnBook(data.isbnCode, data.user);

                    return(JsonResponse.JsonHttpResponse <object>(true));
                }
                return(JsonResponse.JsonHttpResponse <object>(false));
            }
            catch (Exception)
            {
                return(JsonResponse.JsonHttpResponse <object>(false));
            }
        }
        public async Task <HttpResponseMessage> Post()
        {
            var stream = await Request.Content.ReadAsStreamAsync();

            MemoryStream memStr = new MemoryStream();

            try
            {
                stream.CopyTo(memStr);
                stream.Close();
                string nickname = _recognition.Recognize(FaceRecognision.ImageConverter.PhotoToBgrImage(memStr.ToArray()));

                if (OnLogin(this, nickname))
                {
                    var token = JwtManager.GenerateToken(nickname);
                    return(JsonResponse.JsonHttpResponse(token));
                }
                return(JsonResponse.JsonHttpResponse <Object>(false));
            }
            catch (Exception e)
            {
                return(JsonResponse.JsonHttpResponse <Object>(null));
            }
        }
        public async Task <HttpResponseMessage> Put()
        {
            var requestContent = Request.Content;
            var jsonContent    = await requestContent.ReadAsStringAsync();

            var data = JsonConvert.DeserializeObject <Code>(jsonContent);

            if (!_takenBookPresenter.IsTaken(data.isbnCode))
            {
                await _takenBookPresenter.TakeBook(data.isbnCode, data.user);

                try
                {
                    var returnDate = DateTime.UtcNow.AddDays(30);
                    var s          = returnDate.ToString("MM/dd/yyyy");
                    return(JsonResponse.JsonHttpResponse <object>(s));
                }
                catch (InvalidOperationException)
                {
                    return(JsonResponse.JsonHttpResponse <object>(false));
                }
            }
            return(JsonResponse.JsonHttpResponse <object>(false));
        }
 public HttpResponseMessage Get()
 {
     return(JsonResponse.JsonHttpResponse(_bookPresenter.GetBooks()));
 }