Example #1
0
        public static async Task <HttpResponseMessage> ComplimentWriteRunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "compliment/write")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("ComplimentWriteRunAsync request..");

            var ret = new ComplimentResponse();

            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

                var request = JsonConvert.DeserializeObject <ComplimentRequest>(requestBody);
                var res     = await StellaRepository.ComplimentWriteAsync(request);

                if (res >= 1)
                {
                    ret.code = 1;
                }
            }
            catch (MySqlException ex)
            {
                ret.code    = 2;
                ret.message = ex.Message;
            }
            catch (Exception ex)
            {
                ret.code    = 3;
                ret.message = ex.Message;
            }

            return(ret.ObjectToHttpMessage());
        }
Example #2
0
        public static async Task <HttpResponseMessage> CompetitorReadAsync(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "competitor/read")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("CompetitorReadAsync request");

            var ret = new CompetitorResponse();

            try
            {
                var res = await StellaRepository.CompetitorReadAsync();

                ret.code = 1;
                ret.data = new Competitor()
                {
                    luna_email = res.luna_email,
                    reg_dt     = res.reg_dt,
                    content    = res.content
                };
            }
            catch (MySqlException ex)
            {
                ret.code    = 2;
                ret.message = ex.Message;
            }
            catch (Exception ex)
            {
                ret.code    = 3;
                ret.message = ex.Message;
            }

            return(ret.ObjectToHttpMessage());
        }
Example #3
0
        public static async Task <HttpResponseMessage> GetStatisticAlimtalkMonthlyRunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "statistics/alimtalk/monthly")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetStatisticAlimtalkMonthlyRunAsync request..");

            var ret = new GetStatisticAlimtalkMonthlyResponse();

            string month = req.Query["month"];

            try
            {
                var inputMonth = Convert.ToDateTime(month);
                var prevMonth  = inputMonth.AddMonths(-1);

                var response = await StellaRepository.GetStatisticsAlimtalkMonthlyAsync(prevMonth.ToString("yyyyMM"), inputMonth.ToString("yyyyMM"));

                if (response.Count() > 0)
                {
                    var preCount = (from item in response
                                    where item.send_month.Equals(prevMonth.ToString("yyyyMM"))
                                    let total = item.api_send_count + item.auto_send_count + item.manual_send_count
                                                select total).FirstOrDefault();

                    ret = (from item in response
                           where item.send_month.Equals(inputMonth.ToString("yyyyMM"))
                           let total = item.api_send_count + item.auto_send_count + item.manual_send_count
                                       let gap = (float)total - (float)preCount
                                                 select new GetStatisticAlimtalkMonthlyResponse()
                    {
                        Data = new StatisticAlimtalkMonthly()
                        {
                            ApiSendCount = item.api_send_count,
                            AutoSendCount = item.auto_send_count,
                            ManualSendCount = item.manual_send_count,
                            TotalSendCount = total,
                            Gap = gap,
                            Increase = (gap / (float)total) * 100
                        },
                        code = 1
                    }).FirstOrDefault();
                }
                else
                {
                    ret.code = 2;
                }
            }
            catch (FormatException ex)
            {
                log.LogError($"GetStatisticAlimtalkMonthlyRunAsync {ex.Message}");
                ret.code = 3;
            }


            return(ret.ObjectToHttpMessage());
        }
Example #4
0
        public static async Task <HttpResponseMessage> SetStatisticAlimtalkDailyRunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "statistics/alimtalk/daily/write")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("SetStatisticAlimtalkDailyRunAsync request..");

            var ret = new BaseResponse();

            try
            {
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

                var request = JsonConvert.DeserializeObject <StatisticsAlimtalkDaily>(requestBody);
                var res     = await StellaRepository.SetStatisticsAlimtalkDailyAsync(request);

                if (res >= 1)
                {
                    ret.code = 1;
                }
            }
            catch (FormatException ex)
            {
                log.LogError($"SetStatisticAlimtalkDailyRunAsync {ex.Message}");
                ret.code    = 3;
                ret.message = ex.Message;
            }
            catch (MySqlException ex)
            {
                log.LogError($"SetStatisticAlimtalkDailyRunAsync {ex.Message}");
                ret.code    = 4;
                ret.message = ex.Message;
            }
            catch (Exception ex)
            {
                log.LogError($"SetStatisticAlimtalkDailyRunAsync {ex.Message}");
                ret.code    = 5;
                ret.message = ex.Message;
            }

            return(ret.ObjectToHttpMessage());
        }
Example #5
0
        public static async Task <IActionResult> ComplimentReadRunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "compliment/read")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request..");

            string name = req.Query["name"];

            var res = await StellaRepository.ComplimentReadAsync();

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

            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed succe44ssfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {res.from_luna_email}. This HTTP triggered function executed successfully.";

            return(new OkObjectResult(responseMessage));
        }