コード例 #1
0
        public async Task <IActionResult> Post(IFormFile file, string description, string hashTags)
        {
            try
            {
                var id = await _photoService.SaveAsync(file, description, hashTags?.Split('#') ?? new string[0]);

                if (id <= 0)
                {
                    return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse("Photo was not added!")));
                }

                var photoDto = await _photoService.GetAsync(id);

                var photoModel = Mapper.Map <PhotoModel>(photoDto);
                if (photoModel != null)
                {
                    photoModel.SetAddress(Url);
                    photoModel.ShowActions = true;
                }

                return(CreatedJsonResult(JsonResponse.SuccessResponse("Photo was added!", photoModel)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(exception)));
            }
        }
コード例 #2
0
        public async Task <IActionResult> DescriptionAndHashTags(IFormFile file)
        {
            var tempPhotoPath = string.Empty;

            if (!file.ContentType.StartsWith("image/"))
            {
                return(BadRequestJsonResult(JsonResponse.ErrorResponse("Uploaded file must be an image.")));
            }

            try
            {
                tempPhotoPath = await _fileService.SaveAsync(file, _tempPhotosAddress);

                var prediction  = (await _photoProcessingService.ComputePredictionsAsync(tempPhotoPath)).ToArray();
                var description = await _photoService.ComputeDescriptionAsync(prediction);

                var hashTags = await _photoService.ComputeHashTagsAsync(prediction);

                var response = new { description, hashTags = $"#{string.Join("#", hashTags)}" };

                return(OkJsonResult(JsonResponse.SuccessResponse(response)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(GenericErrorMessage)));
            }
            finally
            {
                await _fileService.DeleteAsync(tempPhotoPath);
            }
        }
コード例 #3
0
        public object SavePaymentData(string filepath, PaymentDetailModel model)
        {
            string filename = "payment.txt";
            //string filepath= HttpRequest
            string data = string.Empty;

            data  = "Date : " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss");
            data += ", UserId : " + model.UserId;
            data += ", BSB : " + model.BSB;
            data += ", AccountNo : " + model.AccountNo;
            data += ", AccountName : " + model.AccountName;
            data += ", Reference : " + model.Reference;
            data += ", Amount : " + model.Amount;
            try
            {
                if (!Directory.Exists(filepath))
                {
                    Directory.CreateDirectory(filepath);
                }
                FileSystem.WriteDataToFile(Path.Combine(filepath, filename), data);
                return(JsonResponse.SuccessResponse("Payment completed successfully."));
            }
            catch (Exception ex)
            {
                return(JsonResponse.ErrorResponse(ex));
            }
        }
コード例 #4
0
ファイル: BaseController.cs プロジェクト: jimyu2006/ebooks
        protected static JsonResult JsonError(object messages, object resultsData = null)
        {
            //stops only content/html error with the line "Bad Request" being returned.
            //Response.TrySkipIisCustomErrors = true;      //now set the web.config httpError to passthrough
            if (System.Web.HttpContext.Current != null)
            {
                System.Web.HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }

            var data = JsonResponse.ErrorResponse(messages, resultsData);

            return(new JsonResult()
            {
                Data = data,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #5
0
        private async Task <IActionResult> SearchAction <TRequest>(TRequest model,
                                                                   Func <TRequest, Task <IEnumerable <PhotoModel> > > innerSearchAction)
        {
            try
            {
                var photosModels = await innerSearchAction(model);

                photosModels.ForEach(x => x.SetAddress(Url));

                return(OkJsonResult(JsonResponse.SuccessResponse(photosModels)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(MessagesOptions.GenericErrorMessage)));
            }
        }
コード例 #6
0
        public async Task <IActionResult> GetProfilePhotos(string userName, int currentFeedSize)
        {
            try
            {
                var photosDtos = await _userService.GetPhotosAsync(userName, currentFeedSize);

                var photosModels = Mapper.Map <IEnumerable <PhotoModel> >(photosDtos);
                photosModels.ForEach(x => x.SetAddress(Url));

                return(OkJsonResult(JsonResponse.SuccessResponse(photosModels)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(exception)));
            }
        }
コード例 #7
0
        public ActionResult MakePayment(PaymentDetailModel model)
        {
            var path = Server.MapPath("~/App_Data/SavedData");

            if (ModelState.IsValid)
            {
                PaymentBusiness payClass = new PaymentBusiness();
                return(Json(payClass.SavePaymentData(path, model)));
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                return(Json(JsonResponse.ErrorResponse(messages)));
            }
        }
コード例 #8
0
        private async Task <IActionResult> AdminAction(Func <Task <JsonResponse> > action)
        {
            var watch = Stopwatch.StartNew();

            try
            {
                var result = await action();

                return(OkJsonResult(result));
            }
            catch (Exception exception)
            {
                watch.Stop();
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(new { exception, watch })));
            }
        }
コード例 #9
0
        public async Task <IActionResult> Get(int id)
        {
            try
            {
                var photo = await _photoService.GetAsync(id);

                if (photo == null)
                {
                    return(NotFound());
                }

                return(PhysicalFile(photo.Location, "image/jpg"));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(exception)));
            }
        }
コード例 #10
0
        public async Task <IActionResult> Delete([FromBody] DeletePhotoModel model)
        {
            if (!model.Id.HasValue)
            {
                return(BadRequestJsonResult(JsonResponse.ErrorResponse("Photo id not specified!")));
            }

            try
            {
                await _photoService.DeleteAsync(model.Id.Value);

                return(OkJsonResult(JsonResponse.SuccessResponse("Photo was delete with success!")));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(BadRequest(JsonResponse.ErrorResponse(exception)));
            }
        }
コード例 #11
0
        public async Task <IActionResult> SetProfilePhoto([FromBody] SetProfilePhotoModel model)
        {
            if (!model.Id.HasValue)
            {
                return(BadRequestJsonResult(JsonResponse.ErrorResponse("Photo id not specified!")));
            }

            try
            {
                var result = await _userService.SetProfilePhoto(model.Id.Value);

                if (!result.Succeeded)
                {
                    return(BadRequestJsonResult(JsonResponse.ErrorResponse(result.Errors.Select(x => x.Description))));
                }

                return(OkJsonResult(JsonResponse.SuccessResponse("Profile photo was changed.")));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(BadRequest(JsonResponse.ErrorResponse(MessagesOptions.GenericErrorMessage)));
            }
        }
コード例 #12
0
        public async Task <IActionResult> Get(string userName)
        {
            try
            {
                var user = await _userService.GetWithPhotoAsync(userName);

                var profilePhotoModel = Mapper.Map <PhotoModel>(Mapper.Map <PhotoDto>(user.ProfilePhoto));
                profilePhotoModel?.SetAddress(Url);
                var result = new
                {
                    FullName        = user.UserName,
                    UserName        = user.UserName,
                    ProfilePhoto    = profilePhotoModel,
                    CurrentUserName = _currentUserAccessor.UserName
                };

                return(ReadJsonResult(JsonResponse.SuccessResponse(result)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(exception)));
            }
        }
コード例 #13
0
        public async Task <IActionResult> Prediction(IFormFile file)
        {
            var tempPhotoPath = string.Empty;

            try
            {
                tempPhotoPath = await _fileService.SaveAsync(file, _tempPhotosAddress);

                var prediction = await _photoProcessingService.ComputePredictionsAsync(tempPhotoPath);

                var response = new { prediction };

                return(OkJsonResult(JsonResponse.SuccessResponse(response)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(exception)));
            }
            finally
            {
                await _fileService.DeleteAsync(tempPhotoPath);
            }
        }