예제 #1
0
 public PostVO(PostDto postDto)
 {
     this.PostId = postDto.PostId;
     this.PicFileName = postDto.PicFileName;
     this.PicFileName2 = postDto.PicFileName2;
     this.DocFileName = postDto.DocFileName;
     this.SortNo = postDto.SortNo;
     this.Flag = postDto.Flag;
     this.Quantity = postDto.Quantity;
     this.ShowDate = postDto.ShowDate;
     this.CloseDate = postDto.CloseDate;
     this.Type = postDto.Type;
     this.LinkUrl = postDto.LinkUrl;
     this.IsRecommend = postDto.IsRecommend;
     this.Price = postDto.Price;
     this.SellPrice = postDto.SellPrice;
     this.IsTemp = postDto.IsTemp;
     this.CustomField1 = postDto.CustomField1;
     this.CustomField2 = postDto.CustomField2;
     this.MemberName = postDto.MemberName;
     this.MemberPhone = postDto.MemberPhone;
     this.ProductSer = postDto.ProductSer;
     this.WarrantySuppliers = postDto.WarrantySuppliers;
     this.Wholesalers = postDto.Wholesalers;
     this.MemberId = postDto.MemberId;
     this.Store = postDto.Store;
     this.Title = postDto.Title;
     this.Summary = postDto.Summary;
     this.HtmlContent = postDto.HtmlContent;
     this.KeyWord = postDto.KeyWord;
     this.UpdateId = postDto.UpdateId;
     this.ServerId = postDto.ServerId;
     this.NeedUpdate = postDto.NeedUpdate;
     this.CreatedBy = postDto.CreatedBy;
     this.UpdatedBy = postDto.UpdatedBy;
     this.CreatedDate = postDto.CreatedDate;
     this.UpdatedDate = postDto.UpdatedDate;
 }
        // POST api/<controller>
        public HttpResponseMessage Post(PostDto postDto)
        {
            if (postDto != null)
            {
                try
                {
                    PostVO postVO = null;
                    //檢查是否有ServerId 有的話把狀態改成刪除, 重新建立一筆
                    if (postDto.ServerId != 0)
                    {
                        PostVO oldPostVO = m_PostService.GetPostById(postDto.ServerId);
                        if (oldPostVO != null)
                        {
                            oldPostVO.NeedUpdate = false;
                            oldPostVO.Flag = 0;
                            oldPostVO.UpdateId = "系統API";
                            m_PostService.UpdatePost(oldPostVO);
                        }
                    }

                    postVO = new PostVO(postDto);
                    postVO.Node = m_PostService.GetNodeById(2);
                    postVO.PostId = 0;
                    postVO.ServerId = 0;
                    postVO.NeedUpdate = false;
                    postVO.UpdateId = "系統API";
                    FixTimeZone(postVO);

                    //有memberId 就要用Ser去查Server的Member
                    if (!string.IsNullOrWhiteSpace(postDto.MemberId) && !string.IsNullOrWhiteSpace(postDto.ProductSer))
                    {
                        Dictionary<string, string> conditions = new Dictionary<string, string>();
                        conditions.Add("Status", "1");
                        conditions.Add("KeyWord", postDto.ProductSer);
                        conditions.Add("Store", postDto.Store);

                        IList<MemberVO> memberList = m_MemberService.GetMemberList(conditions);
                        if (memberList != null && memberList.Count > 0 && postDto.ProductSer.Equals(memberList[0].PhoneSer))
                        {
                            postVO.MemberId = memberList[0].MemberId.ToString();
                        }
                        else
                        {
                            postVO.MemberId = "";
                        }
                    }

                    postVO = m_PostService.CreatePost(postVO);
                    postVO.ServerId = postVO.PostId;

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