/// <summary> /// 更新預約資訊 /// </summary> /// <param name="clientData"></param> /// <returns></returns> public static bool Update(Interview.Models.Container.ClientData clientData) { try { using (var context = new HouseRulesEntities()) { //var item = context.ClientData.FirstOrDefault(x => x.ID == clientData.ID); var item = context.ClientData.FirstOrDefault(x => x.ID == clientData.ID); if (item == null) { return(false); } item.ClientName = clientData.ClientName; item.Sex = clientData.Sex; item.City = clientData.City; item.Address = clientData.Address; item.Mobile = clientData.Mobile; item.Budget = clientData.Budget; item.UpdateDate = DateTime.Now; context.SaveChanges(); } return(true); } catch { return(false); } }
/// <summary> /// 抓所有預約資訊的ViewModel /// </summary> /// <returns></returns> public static List <Interview.ViewModel.ClientDataViewModel> GetClientsViewModel() { try { var query = new List <Interview.Models.Container.ClientData>(); using (var context = new HouseRulesEntities()) { query = context.ClientData.Where(x => x.Status == 1).ToList(); } var clientList = new List <Interview.ViewModel.ClientDataViewModel>(); foreach (var item in query) { clientList.Add( new Interview.ViewModel.ClientDataViewModel { Id = item.ID, ClientName = item.ClientName, Sex = item.Sex, City = item.City, Address = item.Address, Mobile = item.Mobile, Budget = item.Budget, }); } return(clientList); } catch { return(new List <Interview.ViewModel.ClientDataViewModel>()); } }
/// <summary> /// 檢查後台帳號登入 /// </summary> /// <param name="account">帳號</param> /// <param name="password">密碼</param> /// <param name="isLoginAction">是否為登入動作</param> /// <returns></returns> public static Interview.Models.Container.AdminAccount GetAccount(string account, string password, bool isLoginAction) { try { using (var context = new HouseRulesEntities()) { var encryptPassword = Utility.SiteSecurity.Encrypt(password); if (string.IsNullOrWhiteSpace(account) || string.IsNullOrWhiteSpace(encryptPassword)) { return(null); } var query = context.AdminAccount.FirstOrDefault(x => x.Account == account && x.Password == encryptPassword); if (query != null) { return(query); } return(null); } } catch { throw; } }
/// <summary> /// 抓指定的keyvalue /// </summary> /// /// <returns></returns> public static KeyValue GetKeyValueById(int keyId) { try { using (var context = new HouseRulesEntities()) { return(context.KeyValue.FirstOrDefault(x => x.Status == true && x.KeyID == keyId)); } } catch { return(new KeyValue()); } }
/// <summary> /// 抓全部的keyvalue /// </summary> /// <returns></returns> public static List <KeyValue> GetKeyValues() { try { using (var context = new HouseRulesEntities()) { return(context.KeyValue.Where(x => x.Status == true).ToList()); } } catch { return(new List <KeyValue>()); } }
/// <summary> /// 抓指定預約資訊 /// </summary> /// <param name="id"></param> /// <returns></returns> public static Interview.Models.Container.ClientData GetClientById(int id) { try { var item = new Interview.Models.Container.ClientData(); using (var context = new HouseRulesEntities()) { item = context.ClientData.FirstOrDefault(x => x.Status == 1 && x.ID == id); } return(item); } catch { return(new Interview.Models.Container.ClientData()); } }
/// <summary> /// 抓所有預約資訊 /// </summary> /// <returns></returns> public static List <Interview.Models.Container.ClientData> GetClients() { try { var item = new List <Interview.Models.Container.ClientData>(); using (var context = new HouseRulesEntities()) { item = context.ClientData.Where(x => x.Status == 1).ToList(); } return(item); } catch { return(new List <Interview.Models.Container.ClientData>()); } }
/// <summary> /// 新增後台帳號 /// </summary> /// <param name="userAccount"></param> /// <returns></returns> public static bool Insert(Interview.Models.Container.AdminAccount userAccount) { try { using (var context = new HouseRulesEntities()) { context.AdminAccount.Add(userAccount); context.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }
/// <summary> /// 新增預約資訊 /// </summary> /// <param name="clientData"></param> /// <returns></returns> public static bool Insert(Interview.Models.Container.ClientData clientData) { try { using (var context = new HouseRulesEntities()) { clientData.CreateDate = DateTime.Now; clientData.UpdateDate = DateTime.Now; clientData.Status = 1; context.ClientData.Add(clientData); context.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// 更新上下架狀態 /// </summary> /// <param name="id"></param> /// <param name="status"></param> /// <returns></returns> public static bool EditStatus(int id, int status) { try { using (var context = new HouseRulesEntities()) { var clientData = context.ClientData.FirstOrDefault(x => x.ID == id); if (clientData == null) { return(false); } clientData.UpdateDate = DateTime.Now; clientData.Status = status; context.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }