/// <summary>
        /// 取得所有的分類列表。
        /// </summary>
        public AllCatalogResult Get()
        {
            ObjectCache cache = MemoryCache.Default;
            var cacheData = cache.Get("AllCatalogResult") as AllCatalogResult;
            if (cacheData != null)
                return cacheData;
            ShoppingEntities shoppingEntities = new ShoppingEntities();
            var allCatalogResult = new CommonLibrary.AllCatalog.AllCatalogResult();
            allCatalogResult.Status = 1;
            try
            {
                var listCatalogLevel1 = shoppingEntities.Catalog
                    .Include("CatalogMapping")
                    .Include("Catalog1")
                    .Include("Catalog1.CatalogMapping")
                    .Include("Catalog1.Catalog1")
                    .Include("Catalog1.Catalog1.CatalogMapping")
                    .Where(r => r.ParentCatalogId == null);

                foreach (var catalogLevel1 in listCatalogLevel1)
                {
                    var CatalogDataLevel1 = new CommonLibrary.AllCatalog.Catalog();
                    CatalogDataLevel1.CatalogId = catalogLevel1.CatalogId;
                    CatalogDataLevel1.CatalogName = catalogLevel1.CatalogName;
                    CatalogDataLevel1.LinkType = catalogLevel1.LinkType;
                    CatalogDataLevel1.LinkURL = catalogLevel1.LinkURL;
                    CatalogDataLevel1.listPrdouctId = catalogLevel1.CatalogMapping.Select(r => r.ProductId).ToList();
                    foreach (var catalogLevel2 in catalogLevel1.Catalog1)
                    {
                        var CatalogDataLevel2 = new CommonLibrary.AllCatalog.Catalog();
                        CatalogDataLevel2.CatalogId = catalogLevel2.CatalogId;
                        CatalogDataLevel2.CatalogName = catalogLevel2.CatalogName;
                        CatalogDataLevel2.LinkType = catalogLevel2.LinkType;
                        CatalogDataLevel2.LinkURL = catalogLevel2.LinkURL;
                        CatalogDataLevel2.listPrdouctId = catalogLevel2.CatalogMapping.Select(r => r.ProductId).ToList();
                        CatalogDataLevel1.listCatalogData.Add(CatalogDataLevel2);
                        foreach (var catalogLevel3 in catalogLevel2.Catalog1)
                        {
                            var catalogDataLevel3 = new CommonLibrary.AllCatalog.Catalog();
                            catalogDataLevel3.CatalogId = catalogLevel3.CatalogId;
                            catalogDataLevel3.CatalogName = catalogLevel3.CatalogName;
                            catalogDataLevel3.LinkType = catalogLevel3.LinkType;
                            catalogDataLevel3.LinkURL = catalogLevel3.LinkURL;
                            catalogDataLevel3.listPrdouctId = catalogLevel3.CatalogMapping.Select(r => r.ProductId).ToList();
                            CatalogDataLevel2.listCatalogData.Add(catalogDataLevel3);
                        }
                    }
                    allCatalogResult.Data.Add(CatalogDataLevel1);
                }
            }
            catch (Exception ex) { allCatalogResult.Status = 99; allCatalogResult.ErrorMessage = ex.Message; }
            CacheItemPolicy policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(30) };
            cache.Add("AllCatalogResult", allCatalogResult, policy);
            return allCatalogResult;
        }
 /// <summary>
 /// 會員註冊。
 /// </summary>
 /// <param name="registerViewModel">註冊資訊</param>
 public CommonLibrary.DataResult Post(CommonLibrary.Member.RegisterViewModel registerViewModel)
 {
     var dataResult = new CommonLibrary.DataResult();
     dataResult.Status = 1;
     try
     {
         ShoppingEntities entity = new ShoppingEntities();
         if (entity.Member.Any(r => r.Email == registerViewModel.Email)) { dataResult.Status = 100; dataResult.ErrorMessage = "EMail重複"; return dataResult; }
         if (entity.Member.Any(r => r.Phone == registerViewModel.Email)) { dataResult.Status = 101; dataResult.ErrorMessage = "手機號碼重複"; return dataResult; }
         var member = new EntityDataModel.Member();
         member.MemberName = registerViewModel.MemberName;
         member.MemberImage = registerViewModel.MemberImage;
         member.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(registerViewModel.Password, "SHA1");
         member.Nickname = registerViewModel.Nickname;
         member.Phone = registerViewModel.Phone;
         member.Email = registerViewModel.Email;
         entity.Member.Add(member);
         entity.SaveChanges();
     }
     catch (Exception ex) { dataResult.Status = 99; dataResult.ErrorMessage = ex.Message; }
     return dataResult;
 }
Beispiel #3
0
 /// <summary>
 /// 會員登入。
 /// </summary>
 /// <param name="loginViewModel">登入資訊</param>
 public CommonLibrary.Member.MemberResult Post(CommonLibrary.Member.LoginViewModel loginViewModel)
 {
     var memberResult = new CommonLibrary.Member.MemberResult();
     memberResult.Status = 1;
     try
     {
         ShoppingEntities entity = new ShoppingEntities();
         var member = entity.Member.FirstOrDefault(r => r.Email == loginViewModel.Email);
         if (member == null) { memberResult.Status = 102; memberResult.ErrorMessage = "查無此帳號"; return memberResult; }
         var memberPassword = member.Password;
         var loginPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(loginViewModel.Password, "SHA1");
         if (memberPassword != loginPassword) { memberResult.Status = 101; memberResult.ErrorMessage = "帳號或密碼錯誤"; return memberResult; }
         memberResult.Data.MemberId = member.MemberId;
         memberResult.Data.Email = member.Email;
         memberResult.Data.Phone = member.Phone;
         memberResult.Data.MemberName = member.MemberName;
         memberResult.Data.Nickname = member.Nickname;
         memberResult.Data.MemberImage = member.MemberImage;
     }
     catch (Exception ex) { memberResult.Status = 99; memberResult.ErrorMessage = ex.Message; }
     return memberResult;
 }