Пример #1
0
        public IActionResult AddParamter(Parameters parameter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            parameterService.AddParameter(parameter);
            return(NoContent());
        }
        public IActionResult HomeLinkAdd(IFormFile file, string ParameterText, int IsSync, string Link, int HomeLinkOrderNo)
        {
            ExcelHepler      Helper           = new ExcelHepler(_hostingEnvironment);
            ParameterService parameterService = new ParameterService(_context);
            FileService      FileService      = new FileService(_hostingEnvironment, _context);
            string           userId           = _userManager.GetUserId(HttpContext.User);
            string           userName         = HttpContext.User.Identity.Name;

            m_ConfigurationPartial ViewModel = new m_ConfigurationPartial();

            if (!string.IsNullOrEmpty(Link))
            {
                string ErrorMsg = string.Empty;

                PDC_Parameter NewParameter = new PDC_Parameter();
                NewParameter.IsSync         = IsSync == 1 ? true : false;
                NewParameter.OrderNo        = HomeLinkOrderNo;
                NewParameter.ParameterText  = ParameterText;
                NewParameter.ParameterGroup = "Configuration_HomeLink";
                NewParameter.Creator        = userId;
                NewParameter.CreatorName    = userName;
                NewParameter.CreatorDate    = DateTime.Now;


                if (parameterService.AddParameter(ref NewParameter, ref ErrorMsg))
                {
                    PDC_File NewFile = new PDC_File();
                    NewFile.SourceID     = NewParameter.ParameterID;
                    NewFile.FunctionName = "Configuration_HomeLink";
                    NewFile.FileType     = 5;
                    NewFile.FileName     = Link;
                    NewFile.FileCategory = 2;
                    NewFile.Creator      = userId;
                    NewFile.CreatorName  = userName;
                    NewFile.CreatorDate  = DateTime.Now;
                    FileService.FileAdd(ref NewFile);

                    ViewModel.m_HomeLink     = NewParameter;
                    ViewModel.m_HomeLinkFile = NewFile;
                }
            }
            else
            {
                //存檔並返回檔案路徑
                string FilePath = Helper.SaveAndGetExcelPath(file);
                if (FilePath != "Error")
                {
                    ViewModel.m_HomeLink.IsSync         = IsSync == 1 ? true : false;
                    ViewModel.m_HomeLink.OrderNo        = HomeLinkOrderNo;
                    ViewModel.m_HomeLink.ParameterText  = ParameterText;
                    ViewModel.m_HomeLink.ParameterGroup = "Configuration_HomeLink";
                    ViewModel.m_HomeLink.Creator        = "m901c018";
                    ViewModel.m_HomeLink.CreatorDate    = DateTime.Now;
                    ViewModel.m_HomeLink.CreatorName    = "Mike";
                    _context.PDC_Parameter.Add(ViewModel.m_HomeLink);
                    _context.SaveChanges();

                    ViewModel.m_HomeLinkFile.SourceID      = ViewModel.m_HomeLink.ParameterID;
                    ViewModel.m_HomeLinkFile.FunctionName  = "Configuration_HomeLink";
                    ViewModel.m_HomeLinkFile.FileFullName  = Path.GetFileName(FilePath);
                    ViewModel.m_HomeLinkFile.FileName      = file.FileName;
                    ViewModel.m_HomeLinkFile.FileExtension = Path.GetExtension(FilePath);
                    ViewModel.m_HomeLinkFile.FileType      = 2;
                    ViewModel.m_HomeLinkFile.FileCategory  = 1;
                    ViewModel.m_HomeLinkFile.FileSize      = file.Length;
                    ViewModel.m_HomeLinkFile.Creator       = "m901c018";
                    ViewModel.m_HomeLinkFile.CreatorDate   = DateTime.Now;
                    ViewModel.m_HomeLinkFile.CreatorName   = "Mike";

                    _context.PDC_File.Add(ViewModel.m_HomeLinkFile);
                    _context.SaveChanges();
                }
            }
            //存檔並返回檔案路徑UserManager<IdentityUser>
            //string FilePath = Helper.SaveAndGetExcelPath(file);



            return(Json(ViewModel));
        }