[工作日誌] 2019-12-06

[工作日誌] 2019-12-06

# 需完成

   1. 填寫KPI自評 (已完成)

   2. 操作SKG測試環境,run團險、團險簡式及商務旅平險情境 (已完成)

# 學習目標

   1. .NET Core API

       https://medium.com/@laroccanicola/creating-our-first-web-api-with-net-core-2-and-visual-studio-code-on-linux-ubuntu-d5d3458ae989

# 會議

   1. 數位軌跡-如何埋Code

       Celebrus

        - 使用者行為蒐集

       - 與Google Analytics(GA)相似

      - 不同在於Celebrus會詳實記錄使用者行為(輸入資料、點擊位置等);GA則是提供統計報表

      - Celebrus於Web使用方式:在欲蒐集行為的頁面引入Celebrus.js  

 2. 商品評議會議

       - 三課:投資型商品批註修改

      - 一課:報酬率計算方式調整


# .NET Core API

 https://medium.com/@laroccanicola/creating-our-first-web-api-with-net-core-2-and-visual-studio-code-on-linux-ubuntu-d5d3458ae989

    建立.NET Core API專案

dotnet new webapi -n {ProjectName}      # 範例: dotnet new webapi -n DotnetCoreAPI

    加入Models資料夾,新增Products.cs

    Products.cs

using System;

namespace Models
{
    public class Products
    {
        public string Code { get; set; }
        public string Description { get; set; }
        public string Um { get; set; }
        public string CodStat { get; set; }
        public int PcCart { get; set; }      
        public double NetWeight { get; set; }
        public string State { get; set; }
        public DateTime CreationDate { get; set; }
        public double Price { get; set; }
    }
}

       新增ProductsController.cs

       ProductsController.cs

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Models;

namespace Controllers
{
    [Produces("application/json")]
    [Route("api/products")]
    public class ProductsController
    {
        Products[] products = new Products[]
        {
            new Products {Code = "014600301", Description = "BARILLA FARINA 1 KG", Um = "PZ", PcCart = 24, NetWeight = 1, Price = 1.09 },
            new Products {Code = "013500121", Description = "BARILLA PASTA GR.500 N.70 1/2 PENNE", Um = "PZ", PcCart = 30, NetWeight = 0.5, Price = 1.3},
            new Products {Code = "007686402", Description = "FINDUS FIOR DI NASELLO 300 GR", Um = "PZ", PcCart = 8, NetWeight = 0.3, Price = 6.46},
            new Products {Code = "057549001", Description = "FUNDUS CROCCOLE 400 GR", Um = "PZ", PcCart = 12, NetWeight = 0.4, Price = 5.97}
        };

        [HttpGet]
        public IEnumerable<Products> ListAllProducts()
        {
            return products;
        }

        [HttpGet("code/{codart}")]
        public IEnumerable<Products> ListProductsByCode(string codart)
        {
            IEnumerable<Products> retVal = 
                from g in products 
                where g.Code.Equals(codart)
                select g;

            return retVal;
        }

        [HttpGet("description/{desart}")]
        public IEnumerable<Products> ListProductsByDescription(string desart)
        {
            IEnumerable<Products> retVal = 
                from g in products
                where g.Description.ToUpper().Contains(desart.ToUpper())
                orderby g.Code
                select g;

            return retVal;
        }
    }
}

       按下F5,開啟debug模式,測試是否成功