Exemplo n.º 1
0
 public FileVO(FileDto fileDto)
 {
     this.FileId = fileDto.FileId;
     this.FileNo = fileDto.FileNo;
     this.Content1 = fileDto.Content1;
     this.Content2 = fileDto.Content2;
     this.ShowDate = fileDto.ShowDate;
     this.FileName = fileDto.FileName;
     this.FileName2 = fileDto.FileName2;
     this.FileName3 = fileDto.FileName3;
     this.Flag = fileDto.Flag;
     this.Type = fileDto.Type;
     this.UpdateId = fileDto.UpdateId;
     this.ServerId = fileDto.ServerId;
     this.NeedUpdate = fileDto.NeedUpdate;
     this.CreatedBy = fileDto.CreatedBy;
     this.UpdatedBy = fileDto.UpdatedBy;
     this.CreatedDate = fileDto.CreatedDate;
     this.UpdatedDate = fileDto.UpdatedDate;
 }
        // POST api/<controller>
        public HttpResponseMessage Post(FileDto fileDto)
        {
            if (fileDto != null)
            {
                try
                {
                    FileVO fileVO = null;
                    //檢查是否有ServerId 有的話把狀態改成刪除, 重新建立一筆
                    if (fileDto.ServerId != 0)
                    {
                        FileVO oldFileVO = m_PostFileService.GetFileById(fileDto.ServerId);
                        if (oldFileVO != null)
                        {
                            oldFileVO.NeedUpdate = false;
                            oldFileVO.Flag = 0;
                            oldFileVO.UpdateId = "系統API";
                            m_PostFileService.UpdateFile(oldFileVO);
                        }
                    }

                    fileVO = new FileVO(fileDto);
                    fileVO.FileId = 0;
                    fileVO.ServerId = 0;
                    fileVO.NeedUpdate = false;
                    fileVO.UpdateId = "系統API";
                    FixTimeZone(fileVO);
                    fileVO = m_PostFileService.CreateFile(fileVO);
                    fileVO.ServerId = fileVO.FileId;

                    return Request.CreateResponse<FileDto>(HttpStatusCode.Created, new FileDto(fileVO));
                }
                catch (Exception ex)
                {
                    return Request.CreateResponse(HttpStatusCode.NoContent, ex.ToString());
                }
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.NoContent);
            }
        }