public async Task <IActionResult> ProcessPayment([FromBody] PaymentRequestViewModel model) { if (!ModelState.IsValid) { return(BadRequest(SmartJsonResult <PaymentResponseViewModel> .Failure(GetModelStateErrors(ModelState)))); } // ReSharper disable once PossibleInvalidOperationException model.UserId = CurrentUser.UserId.Value; //var connection = HttpContext.Features.Get<IHttpConnectionFeature>(); //model.CustomerIP = connection?.RemoteIpAddress?.ToString();ca model.CustomerIP = HttpContext.Connection.RemoteIpAddress?.ToString() ?? "127.0.0.1"; model.UserEmail = CurrentUser.Email; model.UserName = CurrentUser.Name; model.UserLastName = CurrentUser.LastName; var request = _mapper.Map <PaymentRequest>(model); request.notifyUrl = Url.Action("Notify", "Payment", new { area = "Portal" }, "http"); request.continueUrl = Url.Action("ShopContinue", "Home", new { area = "Portal" }, "http"); var payuServiceResult = await _payuService.ProcessPaymentAsync(request, model.UserId, OrderPlace.Website); if (payuServiceResult.IsValid) { return(Ok(SmartJsonResult <PaymentResponseViewModel> .Success(_mapper.Map <PaymentResponseViewModel>(payuServiceResult.Result)))); } return(BadRequest(SmartJsonResult <PaymentResponseViewModel> .Failure(payuServiceResult.ValidationErrors))); }
public async Task <IActionResult> SendQuickMessage([FromBody] QuickMessageViewModel model) { if (ModelState.IsValid) { //Cant be null coz user is logged in // ReSharper disable once PossibleInvalidOperationException model.UserId = CurrentUser.UserId.Value; var adminAccountResult = await _userService.GetAdminAccountIdAsync(); if (!adminAccountResult.IsValid) { return(BadRequest(SmartJsonResult.Failure(adminAccountResult.ValidationErrors))); } model.ReceiverUserId = adminAccountResult.Result; var serviceRequest = _mapper.Map <PortalMessageDto>(model); serviceRequest.Starter = true; var createResult = await _portalMessageService.CreateAsync(serviceRequest); if (createResult.IsValid) { return(Ok(SmartJsonResult <QuickMessageViewModel> .Success(model, "Wiadomość wysłana, dziękujemy za wsparcie :)"))); } return(BadRequest(SmartJsonResult.Failure(createResult.ValidationErrors))); } return(BadRequest(GetModelStateErrors(ModelState))); }
public async Task <IActionResult> ReplyPortalMessage([FromBody] ReplyMessageViewModel model) { if (ModelState.IsValid) { // ReSharper disable once PossibleInvalidOperationException var validateMessageResult = await _portalMessageService.ValidateMessageRecipents(CurrentUser.UserId.Value, model.PreviousMessageId); if (!validateMessageResult.IsValid) { return(BadRequest(SmartJsonResult.Failure(validateMessageResult.ValidationErrors))); } PrepareReplyMessageModel(model, validateMessageResult.Result); var serviceRequest = _mapper.Map <PortalMessageDto>(model); serviceRequest.Starter = false; var createResult = await _portalMessageService.CreateAsync(serviceRequest); if (createResult.IsValid) { return(Ok(SmartJsonResult <PortalMessageItemViewModel> .Success(_mapper.Map <PortalMessageItemViewModel>(createResult.Result), "Wiadomość została wysłana"))); } return(BadRequest(SmartJsonResult.Failure(createResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> LoginWeb([FromBody] ApplicationUser applicationUser) { if (!ModelState.IsValid) { return(ReturnBadRequestWithModelErrors()); } var userLoginResult = await _userService.LoginAsync(applicationUser.Email, applicationUser.Password); if (!userLoginResult.IsValid) { _logger.LogInformation($"Invalid username ({applicationUser.Email}) or password ({applicationUser.Password})"); return(BadRequest(SmartJsonResult.Failure("Invalid credentials."))); } var identity = GetClaimsIdentity(userLoginResult); var encodedJwt = await CreateJwtToken(applicationUser.Email, identity); // Serialize and return the response var response = new { access_token = encodedJwt, expires_in = (int)_jwtOptions.ValidFor.TotalSeconds }; var json = JsonConvert.SerializeObject(SmartJsonResult <object> .Success(response), _serializerSettings); return(new OkObjectResult(json)); }
public async Task <IActionResult> OrderDateRangeList([FromBody] SmartParkListDateRangeRequestViewModel model) { if (!ModelState.IsValid) { model = new SmartParkListDateRangeRequestViewModel { DateFrom = DateTime.Today.AddDays(-6), DateTo = DateTime.Now }; } var dateFrom = model.DateFrom; var dateTo = model.DateTo; // ReSharper disable once PossibleInvalidOperationException var userId = CurrentUser.UserId.Value; var serviceResult = await _orderService.GetAllAsync(x => x.Date >= dateFrom && x.Date <= dateTo && x.UserId == userId); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <SmartParkListWithDateRangeViewModel <ShopOrderItemViewModel> > .Success(new SmartParkListWithDateRangeViewModel <ShopOrderItemViewModel> { ListItems = serviceResult.Result.OrderByDescending(x => x.Date).Select(_mapper.Map <ShopOrderItemViewModel>), DateTo = model.DateTo, DateFrom = model.DateFrom }))); } return(BadRequest(SmartJsonResult <SmartParkListWithDateRangeViewModel <ShopOrderItemViewModel> > .Failure(serviceResult.ValidationErrors))); }
public async Task <IActionResult> DateRangeList([FromBody] SmartParkListDateRangeRequestViewModel model) { if (!ModelState.IsValid) { model = new SmartParkListDateRangeRequestViewModel { DateFrom = DateTime.Today.AddDays(-6), DateTo = DateTime.Now }; } var dateFrom = model.DateFrom; var dateTo = model.DateTo; var serviceResult = await _entityService.GetAllAdminAsync(x => x.Date >= dateFrom && x.Date <= dateTo); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <SmartParkListWithDateRangeViewModel <AdminOrderListItemViewModel> > .Success(new SmartParkListWithDateRangeViewModel <AdminOrderListItemViewModel> { ListItems = serviceResult.Result.Select(_mapper.Map <AdminOrderListItemViewModel>), DateTo = model.DateTo, DateFrom = model.DateFrom }))); } return(BadRequest(SmartJsonResult <SmartParkListWithDateRangeViewModel <AdminOrderListItemViewModel> > .Failure(serviceResult.ValidationErrors))); }
public virtual async Task <IActionResult> ListAsync() { var serviceResult = await GetAllAsync(); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <IEnumerable <TListViewModel> > .Success(serviceResult.Result.Select(_mapper.Map <TListViewModel>)))); } return(BadRequest(SmartJsonResult <IEnumerable <TListViewModel> > .Failure(serviceResult.ValidationErrors))); }
public override async Task <IActionResult> ListAsync() { var serviceResult = await _entityService.GetAllAdminAsync(); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <IEnumerable <AdminOrderListItemViewModel> > .Success(serviceResult.Result.Select(_mapper.Map <AdminOrderListItemViewModel>)))); } return(BadRequest(SmartJsonResult <IEnumerable <AdminOrderListItemViewModel> > .Failure(serviceResult.ValidationErrors))); }
public virtual IActionResult List() { var serviceResult = _entityService.GetAll(); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <IEnumerable <TListViewModel> > .Success(serviceResult.Result.Select(_mapper.Map <TListViewModel>)))); } return(BadRequest(SmartJsonResult <IEnumerable <TListViewModel> > .Failure(serviceResult.ValidationErrors))); }
public async Task <IActionResult> GetUnreadClustersCount() { // ReSharper disable once PossibleInvalidOperationException var messagesGetResult = await _portalMessageService.GetPortalMessageClusterForCurrentUserAsync(CurrentUser.UserId.Value); if (messagesGetResult.IsValid) { var jsonResult = _mapper.Map <PortalMessageClustersViewModel>(messagesGetResult.Result); return(Ok(SmartJsonResult <PortalMessageClustersViewModel> .Success(jsonResult))); } return(BadRequest(SmartJsonResult.Failure(messagesGetResult.ValidationErrors))); }
public async Task <SmartJsonResult <GetUserApiModel> > CheckAccount([FromBody] CheckAccountApiModel model) { if (!ModelState.IsValid) { return(SmartJsonResult <GetUserApiModel> .Failure(GetModelStateErrors(ModelState))); } var checkAccountExistResult = await _userService.GetByEmailAsync(model.Email); return(checkAccountExistResult.IsValid ? SmartJsonResult <GetUserApiModel> .Success(_mapper.Map <GetUserApiModel>(checkAccountExistResult.Result)) : SmartJsonResult <GetUserApiModel> .Failure(checkAccountExistResult.ValidationErrors)); }
public async Task <SmartJsonResult <bool> > ChangeEmail([FromBody] ChangeEmailApiModel model) { if (!ModelState.IsValid) { return(SmartJsonResult <bool> .Failure(GetModelStateErrors(ModelState))); } var changeEmailResult = await _userService.ChangeEmailAsync(model.Email, model.NewEmail, model.Password); return(changeEmailResult.IsValid ? SmartJsonResult <bool> .Success(true) : SmartJsonResult <bool> .Failure(changeEmailResult.ValidationErrors)); }
public override async Task <IActionResult> Edit([FromBody] AdminUserEditViewModel model) { if (ModelState.IsValid) { var serviceResult = await _entityService.AdminEditAsync(_mapper.Map <UserBaseDto>(model), model.OldEmail); if (serviceResult.IsValid) { return(Ok(SmartJsonResult.Success("Edycja użytkownika zakończona pomyślnie"))); } return(BadRequest(SmartJsonResult.Failure(serviceResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public virtual async Task <IActionResult> Delete([FromBody] TDeleteViewModel model) { if (ModelState.IsValid) { var serviceResult = await _entityService.DeleteAsync(model.Id); if (serviceResult.IsValid) { return(Ok(SmartJsonResult.Success("Operacja usunięcia zakończona pomyślnie."))); } return(BadRequest(SmartJsonResult.Failure(serviceResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public virtual async Task <IActionResult> Edit([FromBody] TEditViewModel model) { if (ModelState.IsValid) { var serviceResult = await _entityService.EditAsync(_mapper.Map <TDto>(model)); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <TListViewModel> .Success(_mapper.Map <TListViewModel>(serviceResult.Result), "Edycja zakończona pomyślnie"))); } return(BadRequest(SmartJsonResult.Failure(serviceResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public override async Task <IActionResult> Create([FromBody] AdminPriceTresholdCreateViewModel model) { if (ModelState.IsValid) { var serviceResult = await _entityService.CreateAsync(_mapper.Map <PriceTresholdBaseDto>(model)); return(Json(serviceResult.IsValid ? SmartJsonResult <AdminPriceTresholdListItemViewModel, PrcAdminCreateInfo> .Success(_mapper.Map <AdminPriceTresholdListItemViewModel>(serviceResult.Result), serviceResult.SecondResult, GetSuccessNotificationForCreate(serviceResult.SecondResult)) : SmartJsonResult.Failure(serviceResult.ValidationErrors))); } return(Json(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public virtual async Task <IActionResult> Create([FromBody] TCreateViewModel model) { if (ModelState.IsValid) { var serviceResult = await _entityService.CreateAsync(_mapper.Map <TDto>(model)); if (serviceResult.IsValid) { return(Ok(SmartJsonResult <TListViewModel> .Success(_mapper.Map <TListViewModel>(serviceResult.Result)))); } return(BadRequest(SmartJsonResult.Failure(serviceResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> GetSettingsIndexData() { var serviceResult = await _userService.GetUserDataWithLastGateUsage(CurrentUser.UserId.Value); if (serviceResult.IsValid) { var viewModel = _mapper.Map <UserBaseViewModel>(serviceResult.Result); viewModel.LastGateOpenDate = serviceResult.SecondResult != null ? $"{serviceResult.SecondResult.DateOfUse.ToLongDateString()} - {serviceResult.SecondResult.DateOfUse.ToShortTimeString()}" : "Brak wyjazdów"; return(Ok(SmartJsonResult <UserBaseViewModel> .Success(viewModel))); } return(BadRequest(SmartJsonResult <UserBaseViewModel> .Failure(serviceResult.ValidationErrors))); }
public async Task <IActionResult> RecoverPrc([FromBody] AdminPriceTresholdDeleteViewModel model) { if (ModelState.IsValid) { var recoverUserResult = await _entityService.RecoverPriceTresholdAsync(model.Id); if (recoverUserResult.IsValid) { return(Ok(SmartJsonResult.Success(recoverUserResult.SuccessNotifications.First()))); } return(BadRequest(SmartJsonResult.Failure(recoverUserResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> RecoverUser([FromBody] AdminUserDeleteViewModel model) { if (ModelState.IsValid) { var recoverUserResult = await _entityService.RecoverUserAsync(model.Id); if (recoverUserResult.IsValid) { return(Ok(SmartJsonResult.Success("Operacja przywrócenia użytkownika zakończona pomyślnie."))); } return(BadRequest(SmartJsonResult.Failure(recoverUserResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> GetUserOrders() { // ReSharper disable once PossibleInvalidOperationException var userId = CurrentUser.UserId.Value; var userOrdersResult = await _orderService.GetAllAsync(x => x.UserId == userId); if (userOrdersResult.IsValid) { var viewModel = userOrdersResult.Result.Take(5).Select(_mapper.Map <ShopOrderItemViewModel>); return(Ok(SmartJsonResult <IEnumerable <ShopOrderItemViewModel> > .Success(viewModel))); } return(BadRequest(SmartJsonResult <IEnumerable <ShopOrderItemViewModel> > .Failure(userOrdersResult.ValidationErrors))); }
public async Task <IActionResult> FakeDeleteCluster([FromBody] FakeDeleteClusterViewModel model) { if (ModelState.IsValid) { // ReSharper disable once PossibleInvalidOperationException var fakeDeleteClusterResult = await _portalMessageService.FakeDeleteCluster(CurrentUser.UserId.Value, model.StarterMessageId); if (!fakeDeleteClusterResult.IsValid) { return(BadRequest(SmartJsonResult.Failure(fakeDeleteClusterResult.ValidationErrors))); } return(Ok(SmartJsonResult <bool> .Success(true, "Konwersacja została poprawnie usunięta."))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> Register([FromBody] RegisterViewModel model) { if (ModelState.IsValid) { var userCreateResult = await _userService.CreateAsync(_mapper.Map <UserBaseDto>(model), model.Password); if (userCreateResult.IsValid) { await _messageService.SendMessageAsync(EmailType.Register, userCreateResult.Result, GetAppBaseUrl()); return(Ok(SmartJsonResult.Success("Twoje konto zostało utworzone pomyślnie, czas się zalogować! :)"))); } return(BadRequest(SmartJsonResult.Failure(userCreateResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> SetDisplayed([FromBody] SetDisplayedMessageViewModel model) { if (ModelState.IsValid) { var message = await _portalMessageService.GetAsync(model.MessageId); if (message != null) { message.Result.IsDisplayed = true; await _portalMessageService.EditAsync(message.Result); return(Ok(SmartJsonResult.Success())); } } return(BadRequest(SmartJsonResult.Failure())); }
public async Task <SmartJsonResult <PaymentCardResponse> > ProcessCardPayment([FromBody] PaymentRequestApiModel model) { if (ModelState.IsValid) { model.CustomerIP = HttpContext.Connection.RemoteIpAddress?.ToString() ?? "127.0.0.1"; var request = _mapper.Map <PaymentCardRequest>(model); request.notifyUrl = Url.Action("Notify", "Payment", new { area = "Portal" }, "http"); var payuServiceResult = await _payuService.ProcessCardPaymentAsync(request, model.UserId, OrderPlace.Panel); if (payuServiceResult.IsValid) { return (SmartJsonResult <PaymentCardResponse> .Success(payuServiceResult.Result)); } return(SmartJsonResult <PaymentCardResponse> .Failure(payuServiceResult.ValidationErrors)); } return(SmartJsonResult <PaymentCardResponse> .Failure(GetModelStateErrors(ModelState))); }
public async Task <SmartJsonResult <bool> > ForgotPassword([FromBody] ForgotApiModel model) { if (!ModelState.IsValid) { return(SmartJsonResult <bool> .Failure(GetModelStateErrors(ModelState))); } var changePasswordTokenResult = await _userService.GetPasswordChangeTokenAsync(model.Email); var changePasswordUrl = $"{Url.Action("RedirectFromToken", "Token", null, "http")}?id={changePasswordTokenResult.SecondResult}"; await _messageService.SendMessageAsync(EmailType.ResetPassword, changePasswordTokenResult.Result, GetAppBaseUrl(), new Dictionary <string, string> { { "ChangePasswordLink", changePasswordUrl } }); return(changePasswordTokenResult.IsValid ? SmartJsonResult <bool> .Success(true) : SmartJsonResult <bool> .Failure(changePasswordTokenResult.ValidationErrors)); }
public async Task <IActionResult> GetPrices() { var currentPricesResult = await _priceTresholdService.GetAllAsync(); if (currentPricesResult.IsValid) { var pricesViewModels = currentPricesResult.Result.Select(_mapper.Map <PriceTresholdShopItemViewModel>).ToList(); var defaultPrice = pricesViewModels.First(); defaultPrice.IsDeafult = true; for (var i = 1; i < pricesViewModels.Count; i++) { var price = pricesViewModels[i]; price.PercentDiscount = 100 - Convert.ToInt32((price.PricePerCharge * 100) / defaultPrice.PricePerCharge); } return(Json(SmartJsonResult <IEnumerable <PriceTresholdShopItemViewModel> > .Success(pricesViewModels))); } return(Json(SmartJsonResult <IEnumerable <PriceTresholdShopItemViewModel> > .Failure(currentPricesResult.ValidationErrors))); }
public async Task <IActionResult> GetChartData([FromBody] ChartDataRequest model) { if (ModelState.IsValid) { var serviceRequest = _mapper.Map <ChartRequestDto>(model); // ReSharper disable once PossibleInvalidOperationException serviceRequest.UserId = CurrentUser.UserId.Value; var chartDataResult = await _chartService.GetDataAsync(serviceRequest); if (chartDataResult.IsValid) { return(Ok(SmartJsonResult <ChartDataReturnModel> .Success(_mapper.Map <ChartDataReturnModel>(chartDataResult.Result)))); } return(BadRequest(SmartJsonResult.Failure(chartDataResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
public async Task <IActionResult> GetDefaultChartData() { if (ModelState.IsValid) { // ReSharper disable once PossibleInvalidOperationException var chartDataAndPreferencesResult = await _chartService.GetDefaultDataAsync(CurrentUser.UserId.Value); if (chartDataAndPreferencesResult.IsValid) { var result = new { gateUsagesData = _mapper.Map <ChartDataReturnModel>(chartDataAndPreferencesResult.Result.FirstOrDefault(x => x.Key == ChartType.GateOpenings).Value), ordersData = _mapper.Map <ChartDataReturnModel>(chartDataAndPreferencesResult.Result.FirstOrDefault(x => x.Key == ChartType.Orders).Value), }; return(Ok(SmartJsonResult <object, ChartPreferencesReturnModel> .Success(result, _mapper.Map <ChartPreferencesReturnModel>(chartDataAndPreferencesResult.SecondResult)))); } return(BadRequest(SmartJsonResult.Failure(chartDataAndPreferencesResult.ValidationErrors))); } return(BadRequest(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }
protected IActionResult ReturnBadRequestWithModelErrors() { return(new BadRequestObjectResult(SmartJsonResult.Failure(GetModelStateErrors(ModelState)))); }