public ActionResult StoreAdd(StoreViewModel model) { try { //驗證授權:管理員 var pass = roleAuth.AdminAuth(); if (pass == true) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "Admin"; } else { TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!"; return(RedirectToAction("Login", "Home")); } StoreOperation op = new StoreOperation(); var result = op.Add(model); TempData["result"] = result; return(RedirectToAction(nameof(Store))); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(RedirectToAction("Logout", "Home")); } }
public OperationRequest(StoreOperation storeOperation, string tag, long id, string objectToUpdate = "") { StoreOperation = storeOperation; Tag = tag; ID = id; ObjectToUpdate = objectToUpdate; }
public bool Store <T>(StoreOperation operation, T datakey, int expires) where T : DataKey { datakey.Initialize(m_formatter); int flags; var bytes = datakey.Save(out flags); var key = m_keyEncoder.GetBytes(datakey.Key); m_commandWriter.Store(new StorePacket() { Operation = operation, Key = key, Flags = flags, Expires = expires, Value = bytes, Version = datakey.Version }, Options.NoReply); var succeed = true; return(m_factory.Context(key)((connection, state) => { m_builder.WriteTo(connection.Writer); if (!Options.NoReply) { var commandReader = m_factory.CreateCommandReader( m_factory.CreatePacketParser(connection.Reader, m_buffer)); succeed = commandReader.ReadStored(); } }) && succeed); }
public void Store(StoreOperation operation) { // Arrange var packet = new StorePacket() { Expires = 1000, Flags = 101, Key = new byte[] { 7 }, Operation = operation, Value = new ArraySegment <byte>(new byte[] { 46, 62 }), Version = 4363431212 }; m_mockPacketBuilder.Setup(builder => builder.Reset()).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteOperation((RequestOperation)packet.Operation)).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteNoReply()).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteVersion(packet.Version)).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteFlags(packet.Flags)).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteExpires(packet.Expires)).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteKey(packet.Key)).Returns(m_mockPacketBuilder.Object); m_mockPacketBuilder.Setup(builder => builder.WriteValue(packet.Value)).Returns(m_mockPacketBuilder.Object); // Act m_writer.Store(packet, true); // Assert }
/// <summary> /// 顯示所有教室資訊 照館別排列 /// </summary> /// <returns></returns> public ActionResult Classroom() { try { //驗證授權:管理員 var pass = roleAuth.AdminAuth(); if (pass == true) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "Admin"; } else { TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!"; return(RedirectToAction("Login", "Home")); } StoreOperation storeOperation = new StoreOperation(); ClassroomOperation classroomOperation = new ClassroomOperation(); //取得所有館別ID var allStore = storeOperation.Get().Select(c => c.StoreNo); //取得所有教室 var allClassroom = classroomOperation.Get(); List <ClassroomViewModel> LstModel = new List <ClassroomViewModel>(); //根據現有館別歸納出各場館下的教室 foreach (var StoreNo in allStore) { ClassroomViewModel model = new ClassroomViewModel(); model.ClassInfo = new List <Dictionary <string, string> >(); //取得同館別的教室 var LstClsRoom = allClassroom.Where(c => c.Store_No.Equals(StoreNo)).Select(c => c); model.StoreNo = StoreNo; model.StoreName = storeOperation.GetName(StoreNo); //取得同館別所有教室的Id及名稱 foreach (var item in LstClsRoom) { var DicClsInfo = new Dictionary <string, string>(); DicClsInfo.Add(item.ClassroomNo, item.Name); model.ClassInfo.Add(DicClsInfo); } LstModel.Add(model); } return(View(LstModel)); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(RedirectToAction("Logout", "Home")); } }
protected override bool TryParseArguments(ImmutableList <IMessageData> arguments) { if (arguments.Count != 3) { return(false); } string storeType = MessageData.GetString(arguments[0], Encoding.ASCII); _messageRange = arguments[1] as NumberRangeMessageData; _valueList = arguments[2] as ListMessageData; if (string.IsNullOrEmpty(storeType) || _messageRange == null || _valueList == null) { return(false); } Match argumentMatch = ArgumentPattern.Match(storeType); if (!argumentMatch.Success) { return(false); } switch (argumentMatch.Groups[1].Value) { case "": _operation = StoreOperation.Set; break; case "+": _operation = StoreOperation.Add; break; case "-": _operation = StoreOperation.Remove; break; default: return(false); } _command = argumentMatch.Groups[2].Value; if (!KnownCommands.Contains(_command, StringComparer.OrdinalIgnoreCase)) { return(false); } _silent = string.Equals(argumentMatch.Groups[3].Value, ".SILENT", StringComparison.OrdinalIgnoreCase); return(true); }
public void Store(StoreOperation operation, string optionsString, bool connectSucceed, bool storeSucceed) { // Arrange var options = new ProtocolOptions(optionsString); var protocol = new DefaultProtocol(m_mockFactory.Object, options); var datakey = new DataKey <int>("Key1") { Value = 12345, Version = 556 }; int flags = 10101; var key = new byte[] { }; var value = new ArraySegment <byte>(new byte[] { }); StorePacket packet = null; m_mockObjectFormatter.Setup(formatter => formatter.Serialize <int>(12345, out flags)).Returns(value); m_mockEncoder.Setup(encoder => encoder.GetBytes("Key1")).Returns(key); m_mockCommandWriter.Setup(writer => writer.Store(It.IsAny <StorePacket>(), options.NoReply)) .Callback <StorePacket, bool>((p, nr) => packet = p); m_mockFactory.Setup(factory => factory.Context(key)) .Returns <byte[]>(state => (Action2 <IClientConnection, object> action) => { if (connectSucceed) { action(m_mockClientConnection.Object, state); } return(connectSucceed); }); if (connectSucceed) { m_mockClientConnection.SetupGet(connection => connection.Writer).Returns(m_mockBinaryWriter.Object); m_mockPacketBuilder.Setup(builder => builder.WriteTo(m_mockBinaryWriter.Object)).Returns(0); if (!options.NoReply) { m_mockClientConnection.SetupGet(connection => connection.Reader).Returns(m_mockBinaryReader.Object); m_mockFactory.Setup(factory => factory.CreatePacketParser(m_mockBinaryReader.Object, It.IsAny <Buffer <byte> >())).Returns(m_mockPacketParser.Object); m_mockFactory.Setup(factory => factory.CreateCommandReader(m_mockPacketParser.Object)).Returns(m_mockCommandReader.Object); m_mockCommandReader.Setup(reader => reader.ReadStored()).Returns(storeSucceed); } } // Act var result = protocol.Store(operation, datakey, 100); // Assert Assert.Equal(connectSucceed && (options.NoReply || storeSucceed), result); Assert.NotNull(packet); Assert.Equal(100, packet.Expires); Assert.Equal(flags, packet.Flags); Assert.Equal(key, packet.Key); Assert.Equal(operation, packet.Operation); Assert.Equal(value, packet.Value); Assert.Equal(556, packet.Version); }
/// <summary> /// 各館資訊 /// </summary> /// <returns></returns> //[CommonAuthorize] public ActionResult StoreInfo() { try { //驗證授權:一般會員及訪客 //RoleAuthManager roleAuth = new RoleAuthManager(); var pass = roleAuth.UserGuestAuth(); if (pass == 0) { ViewBag.UserName = roleAuth.UserName(); } else if (pass == 1) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "User"; } else if (pass == 2) { ViewBag.RoleName = "Admin"; ViewBag.UserName = roleAuth.UserName(); TempData["Msg"] = "無權限瀏覽該網頁,請登入會員或以訪客身分瀏覽,謝謝!"; return(RedirectToAction("Login", "Home")); } StoreOperation storeOp = new StoreOperation(); var AllStore = storeOp.Get();//取得所有館別 List <StoreInfoViewModel> stores = new List <StoreInfoViewModel>(); foreach (var item in AllStore) { StoreInfoViewModel storeVModel = new StoreInfoViewModel(); storeVModel.Name = item.Name; storeVModel.Address = item.Address; storeVModel.Tel = item.Tel; storeVModel.Service = item.ServiceInfo; storeVModel.Parking = item.ParkingInfo; storeVModel.MemberInCount = item.AccessLimit; stores.Add(storeVModel); } return(View(stores)); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(View()); } }
private static bool Store(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt) { if (value == null) { return(false); } using (StoreOperation s = new StoreOperation(pool, mode, key, value, casValue, validFor, expiresAt)) { s.Execute(); return(s.Success); } }
private static bool Store(ServerPool pool, StoreCommand mode, string key, byte[] value, ulong casValue, int offset, int length, TimeSpan validFor, DateTime expiresAt) { if (value == null) { return(false); } using (StoreOperation s = new StoreOperation(pool, mode, key, new ArraySegment <byte>(value, offset, length), casValue, validFor, expiresAt)) { s.Execute(); return(s.Success); } }
/// <summary> /// 取得所有館別資料 /// </summary> /// <returns></returns> public ActionResult Store() { try { //驗證授權:管理員 var pass = roleAuth.AdminAuth(); if (pass == true) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "Admin"; } else { TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!"; return(RedirectToAction("Login", "Home")); } StoreOperation op = new StoreOperation(); var allStore = op.Get(); List <StoreViewModel> lstModel = new List <StoreViewModel>(); foreach (var item in allStore) { StoreViewModel model = new StoreViewModel(); model.StoreNo = item.StoreNo; model.Name = item.Name; model.Address = item.Address; model.Tel = item.Tel; model.ServiceInfo = item.ServiceInfo; model.ParkingInfo = item.ParkingInfo; model.MemberInCnt = item.MemberInCnt.ToString(); model.AccessLimit = item.AccessLimit.ToString(); lstModel.Add(model); } return(View(lstModel)); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(RedirectToAction("Logout", "Home")); } }
/// <summary> /// 編輯選取的館別資料 /// </summary> /// <param name="id">館別id</param> /// <returns></returns> public ActionResult StoreEdit(string id) { try { //驗證授權:管理員 var pass = roleAuth.AdminAuth(); if (pass == true) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "Admin"; } else { TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!"; return(RedirectToAction("Login", "Home")); } StoreOperation op = new StoreOperation(); var store = op.GetInfo(id); StoreViewModel model = new StoreViewModel() { StoreNo = store.StoreNo, Name = store.Name, Address = store.Address, Tel = store.Tel, ServiceInfo = store.ServiceInfo, ParkingInfo = store.ParkingInfo, MemberInCnt = store.MemberInCnt.ToString(), AccessLimit = store.AccessLimit.ToString() }; return(View(model)); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(RedirectToAction("Logout", "Home")); } }
} //選擇館別 public void listStoreItems() { List <StoreCheckboxListItem> checkList = new List <StoreCheckboxListItem>(); //從館別資料表取得目前所有館別資料 StoreOperation store = new StoreOperation(); var allStore = store.Get().ToList(); //根據館別新增對應的Checkbox foreach (Store item in allStore) { checkList.AddRange(new[] { new StoreCheckboxListItem() { DisplayText = item.Name, No = item.StoreNo, IsChecked = false } }); } stores = checkList; }
/// <summary> /// 顯示我的預約課程紀錄 /// </summary> /// <returns></returns> public ActionResult MyBooking() { try { //驗證授權:一般會員 var pass = roleAuth.UserAuth(); if (pass == true) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "User"; } else { TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!"; return(RedirectToAction("Logout", "Home")); } //取得會員Id var UserEmail = User.Identity.Name; MemberOperation member = new MemberOperation(); var id = member.Get(UserEmail).MemberNo; CourseOperation co = new CourseOperation(); var nowdata = co.GetBooking(id); //尚未結束之預約課程 var pastdata = co.GetPastBooking(id); //已結束之預約課程 CourseTypeOperation cto = new CourseTypeOperation(); ClassroomOperation classroom = new ClassroomOperation(); StoreOperation so = new StoreOperation(); TeacherOperation to = new TeacherOperation(); BookingGroupViewModel booking = new BookingGroupViewModel(); booking.FutureBooking = new List <FutureBookingViewModel>(); booking.PastBooking = new List <PastBookingViewModel>(); foreach (var item in nowdata) { FutureBookingViewModel fbv = new FutureBookingViewModel() { CourseNo = item.CourseNo, //課程代號 CourseName = cto.Get(item.CourseType_No).Name, //課程名稱 Date = item.ClassDate.ToShortDateString(), //日期 Classroom = classroom.Get(item.Classroom_No).Name, //教室 Store = so.GetName(classroom.Get(item.Classroom_No).Store_No), //場館 Time = item.StartTime.ToShortTimeString() + " ~ " + item.EndTime.ToShortTimeString(), //上課時間 Teacher = to.GetName(item.Teacher_No) //教練名字 }; booking.FutureBooking.Add(fbv); } foreach (var item in pastdata) { PastBookingViewModel pbv = new PastBookingViewModel() { CourseNo = item.CourseNo, //課程代號 CourseName = cto.Get(item.CourseType_No).Name, //課程名稱 Date = item.ClassDate.ToShortDateString(), //日期 Classroom = classroom.Get(item.Classroom_No).Name, //教室 Store = so.GetName(classroom.Get(item.Classroom_No).Store_No), //場館 Time = item.StartTime.ToShortTimeString() + " ~ " + item.EndTime.ToShortTimeString(), //上課時間 Teacher = to.GetName(item.Teacher_No) //教練名字 }; booking.PastBooking.Add(pbv); } return(View(booking)); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(RedirectToAction("Logout", "Home")); } }
//[CommonAuthorize] public ActionResult Index() { try { RoleAuthManager roleAuth = new RoleAuthManager(); var pass = roleAuth.UserGuestAuth(); if (pass == 0) { ViewBag.UserName = roleAuth.UserName(); } else if (pass == 1) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "User"; } else if (pass == 2) { ViewBag.RoleName = "Admin"; ViewBag.UserName = roleAuth.UserName(); TempData["Msg"] = "無權限瀏覽該網頁,請登入會員或以訪客身分瀏覽,謝謝!"; return(RedirectToAction("Login", "Home")); } StoreOperation storeOp = new StoreOperation(); var AllStore = storeOp.Get(); //取得所有館別 ClassroomOperation clsroomOp = new ClassroomOperation(); var AllStoreClassRoom = clsroomOp.Get(AllStore); //取得所有館別的教室 CourseOperation crsItemOp = new CourseOperation(); CourseTypeOperation crsOp = new CourseTypeOperation(); List <IndexViewModel> Lstmodel = new List <IndexViewModel>(); //取得每個館別的資料 foreach (var store in AllStore) { IndexViewModel model = new IndexViewModel(); model.CourseInfo = new List <string>(); model.Store = store.Name; model.AccessLimit = store.AccessLimit.ToString(); model.AccessNow = store.MemberInCnt.ToString(); //取得該館的所有教室 var StoreClassRoom = clsroomOp.Get(store); //若教室為一對一教練課用 跳過 foreach (var Room in StoreClassRoom) { if (Room.Name.Equals("一對一場地")) { continue; } var RoomName = Room.Name; var LstCourse = crsItemOp.Get(Room);//取得教室的所有課程 //取得教室目前課程 var NowCourse = from c in LstCourse where c.CourseType_No != "Ch05" && c.ClassDate.Equals(DateTime.Now.Date) && c.StartTime <= DateTime.Now && DateTime.Now <= c.EndTime select c.CourseType_No; //教室目前有課程 if (NowCourse.Count() > 0) { //取得教室名稱與目前課程名稱 var tmpNowCourse = NowCourse.ToList(); var courseName = crsOp.Get(tmpNowCourse[0]).Name; model.CourseInfo.Add(RoomName + ":" + courseName); } //教室目前沒有課程 else { //取得教室名稱 紀錄目前無課程 model.CourseInfo.Add(RoomName + ":目前無課程"); } } Lstmodel.Add(model); } return(View(Lstmodel)); } catch (Exception ex) { TempData["Msg"] = ex.ToString(); return(View()); } }
public MaskingDecoration(IStore decorated, StoreOperation mask) : base(decorated) { this.AllowedOperations = mask; }
/// <summary> /// constrains the operations so that only the ones specified are enabled /// </summary> /// <param name="decorated"></param> /// <param name="mask"></param> /// <returns></returns> public static MaskingDecoration AllowOperations(this IStore decorated, StoreOperation mask) { Condition.Requires(decorated).IsNotNull(); return new MaskingDecoration(decorated, mask); }
public static void RequestOperation_Contains_StoreOperation(RequestOperation ro, StoreOperation so) { // Arrange // Act Assert.Equal((int)ro, (int)so); // Assert }
/// <summary> /// constrains the operations so that only the ones specified are enabled /// </summary> /// <param name="decorated"></param> /// <param name="mask"></param> /// <returns></returns> public static MaskingDecoration AllowOperations(this IStore decorated, StoreOperation mask) { Condition.Requires(decorated).IsNotNull(); return(new MaskingDecoration(decorated, mask)); }
/// <summary> /// 註冊確認及存取 /// </summary> /// <param name="reg"></param> /// <returns></returns> public int CheckAddMember(RegisterGroupViewModel reg) { int flg = 0; try { var allMember = Get(); //電話,Email相同 視為同一個會員 var check = allMember.Where(s => s.Tel == reg.Register.Tel || s.Email == reg.Register.Email); //會員資料重複 if (check.Count() >= 1) { flg = -1; } //新增會員 else { using (GymEntity db = new GymEntity()) { StoreOperation store = new StoreOperation(); //var allStore = store.Get(); //會員選擇的館別編號 var chkStoreNo = from c in reg.StoreCheckList.stores where c.IsChecked == true select c.No; //會員密碼加密 var CryptographyPwd = reg.Register.Password.PasswordCryptography(); if (chkStoreNo.Count() > 0) { Member addMember = new Member { Email = reg.Register.Email, Birthday = reg.Register.Birthday, Tel = reg.Register.Tel, Password = CryptographyPwd, Sex = reg.Register.Sex, PassWay = reg.Register.PassWay, Role_No = reg.Register.RoleNo, CreateTime = reg.Register.CreateTime, LastLoginTime = reg.Register.LastLoginTime, IsLogin = reg.Register.IsLogin, Status = reg.Register.Status, Name = reg.Register.Name, }; //新增會員可出入館別資料 foreach (var No in chkStoreNo) { addMember.Store.Add(db.Store.Where(m => m.StoreNo == No).FirstOrDefault()); } db.Member.Add(addMember); //處理資料庫儲存 bool saveFailed; do { saveFailed = false; try { db.SaveChanges(); flg = 0; } catch (DbUpdateConcurrencyException ex) { saveFailed = true; ex.Entries.Single().Reload(); } catch (Exception) { flg = -99; } } while (saveFailed); } else { //沒有選擇館別 flg = -2; } } } return(flg); } catch (Exception) { flg = -99; return(flg); } }