public IActionResult Subscribe([FromBody] SubscriptionInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(ResponseViewModel.Ok(_subscriptionAppService.MakeSubscription(model).Result)));
        }
Beispiel #2
0
        /// <summary>
        /// Make Subscription
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ResponseViewModel> MakeSubscription(SubscriptionInputModel model)
        {
            var plot = _plotService.AllPlots().FirstOrDefault(x => x.Id == model.PlotId);

            if (plot == null)
            {
                return(NotFound(ResponseMessageViewModel.INVALID_PLOT, ResponseErrorCodeStatus.INVALID_PLOT));
            }

            var currentUser = await _userManager.FindByIdAsync(_httpContextAccessor.HttpContext.User.GetLoggedInUserId <int>().ToString());

            return(Ok(_mapper.Map <Subscription, SubscriptionViewModel>(_subscriptionService.Subscribe(currentUser.Id, currentUser.OrganizationTypeId ?? 1, model.PlotId))));
        }
Beispiel #3
0
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "subscriptions")]
            SubscriptionInputModel subscription,
            ClaimsPrincipal user,
            [CosmosDB("products", "subscriptions", ConnectionStringSetting = "CosmosDBConnection")]
            out Subscription notification
            )
        {
            if (!user.Identity.IsAuthenticated)
            {
                notification = null;
                return(new UnauthorizedResult());
            }

            notification = new Subscription()
            {
                Id          = Guid.NewGuid(),
                PhoneNumber = subscription.PhoneNumber,
                ProductId   = subscription.ProductId
            };

            return(new NoContentResult());
        }