예제 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Get rates request!");

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  token       = data?.token;

            var id = JWTTokenBuilder.ValidateJwtToken(token);

            if (string.IsNullOrEmpty(id))
            {
                return(new UnauthorizedResult());
            }

            string CategoryId          = data?.CategoryId;
            string OrganisationName    = data?.OrganisationName;
            string Title               = data?.Title;
            string PercentageDiscount  = data?.PercentageDiscount; //should be int or string????????
            string FixedDiscount       = data?.FixedDiscount;
            string OrganisationAddress = data?.OrganisationAddress;
            string City             = data?.City;
            string Email            = data?.Email;
            string Phone            = data?.Phone;
            bool   NationalValidty  = data?.NationalValidity;
            string StartDate        = data?.StartDate;
            string ExpiryDate       = data?.ExpiryDate;
            string ImagePath        = data?.ImagePath;
            string OfferDescription = data?.OfferDescription;

            if (string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(OfferDescription) || string.IsNullOrEmpty(ImagePath) || string.IsNullOrEmpty(StartDate) || string.IsNullOrEmpty(ExpiryDate) || string.IsNullOrEmpty(Phone))
            {
                return(new BadRequestObjectResult("Invalid Inputs"));
            }

            /*
             *
             * if (!News.Categories.Contains(category))
             * {
             *  return new BadRequestObjectResult("Invalid Category");
             * }
             */

            Database.CreateOffers(CategoryId, OrganisationName, Title, PercentageDiscount, FixedDiscount, OrganisationAddress, City, Email, Phone, NationalValidty, StartDate, ExpiryDate, ImagePath, OfferDescription);
            return(new OkObjectResult(new BaseResponse(token, "Offer created successfuly!!!!")));
        }
예제 #2
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger, ISampleService sampleService, JWTTokenBuilder jWTTokenBuilder)
 {
     _logger          = logger;
     _sampleService   = sampleService;
     _jWTTokenBuilder = jWTTokenBuilder;
 }