Beispiel #1
0
        //將產品加到我的最愛
        public string AddToFavorite(int ProductID)
        {
            var pdName = db.Product.Where(r => r.ProductID == ProductID).FirstOrDefault().ProductName;
            var fa     = db.FavoriteList.Where(r => r.MemberID == tMember.fMemberId && r.ProductID == ProductID);

            if (fa.Count() == 0)
            {
                try
                {
                    FavoriteList fv = new FavoriteList()
                    {
                        MemberID = tMember.fMemberId, ProductID = ProductID
                    };
                    db.FavoriteList.Add(fv);
                    db.SaveChanges();
                    return($"已成功將 {pdName} 加入我的最愛");
                }
                catch (Exception)
                {
                    return($"出現錯誤!請稍後再嘗試!");
                }
            }
            else
            {
                return("我的最愛裡已有此件商品");
            }
        }
        public bool Add(int p_member_id, int p_categoryid, int p_source_id, int?p_content_id, string p_message)
        {
            try
            {
                SingleApartmentEntities db   = new SingleApartmentEntities();
                Information             info = new Information();

                info.InformationDate       = DateTime.Now;
                info.InformationCategoryID = p_categoryid;  //訊息分類來源
                info.DocumentID            = p_source_id;   //可能是訂單號碼, 房號 ......

                if (p_content_id != null)
                {
                    InformationContent rowContent = db.InformationContent.Where(c => c.ContentID == p_content_id).FirstOrDefault();
                    if (rowContent != null)
                    {
                        //InformationSource此欄位可以是null
                        info.InformationSource = p_content_id;              //訊息ContentID

                        if (!string.IsNullOrEmpty(p_message))
                        {
                            info.InformationContent = rowContent.ContentText + p_message;
                        }
                        else
                        {
                            info.InformationContent = rowContent.ContentText;   //訊息內容
                        }
                    }
                    else
                    {
                        info.InformationContent = "基本資料未輸入, 請洽系統管理員";
                    }
                }
                else
                {
                    info.InformationContent = "Empty Message!";
                }

                info.MemberID = p_member_id;
                info.Priority = "Normal";
                info.Read_YN  = "N";
                info.Status   = "Open";
                db.Information.Add(info);
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }