public async Task <IActionResult> DeleteRoom(int id) { var room = _roomRepo.GetRoomById(id); if (room == null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } if (!await _authHelpers.CheckDormitoryMembership(User, room.Dormitory)) { return(ControllerHelpers.ShowAccessDeniedErrorPage(this)); } foreach (var user in room.Occupants) { await _userManager.RemoveFromRoleAsync(user, "Occupant"); } var dormitoryId = _roomRepo.DeleteRoom(id); if (dormitoryId == null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } return(RedirectToAction(nameof(Rooms), new { id = dormitoryId })); }
public IActionResult Details(int?id) { if (id == null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } var dormitory = _dormitoryRepo.GetSingleById(id.Value); if (dormitory == null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } var model = new DormitoryDetailsViewModel { Dormitory = dormitory, Manager = dormitory.Manager, Porters = dormitory.Porters.ToList(), Laundries = dormitory.Laundries.ToList(), Announcements = _announcementRepo.GetDormitoryAnnouncements(dormitory.DormitoryId) }; return(View(model)); }
public static IServiceCollection ConfigureApiBehavior(this IServiceCollection services) { services.Configure <ApiBehaviorOptions>(options => { options.InvalidModelStateResponseFactory = context => { var descriptor = context.ActionDescriptor.CastTo <ControllerActionDescriptor>(); if (descriptor.MethodInfo.CustomAttributes .Any(x => x.AttributeType == typeof(DontWrapInvalidModelStateAttribute)) //todo test for controller! || descriptor.ControllerTypeInfo.CustomAttributes .Any(x => x.AttributeType == typeof(DontWrapInvalidModelStateAttribute))) { var errors = context.ModelState.ToDictionary(); LogFactory.GetLogger(descriptor.ControllerTypeInfo) .LogError("Validation error: {Values}", errors); var result = new BadRequestObjectResult(context.ModelState); return(result); } return(ControllerHelpers.BadRequest(context.ModelState).ToActionResult()); }; }); return(services); }
private IEnumerator Attach(GameObject target, Transform parent, string productId) { Debug.Log("Attaching"); yield return(ControllerHelpers.AttachModelById(target, parent, productId, GLTFMaterial, GLTFMaterial)); target.transform.localPosition = Camera.main.transform.position; target.transform.Rotate(new Vector3(-90, 0, 0)); Debug.Log(target.transform.position); Debug.Log(target.transform.rotation.eulerAngles.ToString()); // Do what ever extra procesing ... controllersInProgress.Remove(productId); renderedCount++; if (RenderOnlyOne) { StopListening(); } if (ShowPartNames) { var partsRenderer = GetComponent <MotionControllerPartsLabelRenderer>(); if (partsRenderer != null) { partsRenderer.MotionController = target; } } }
/** * Recieves the gathered digits and transfers the call to the number provided */ public static void gatherAndTransfer() { post("/transfer/number", ((request, response) => { string json = ControllerHelpers.getBody(request); BandwidthCallbackMessageVoice callbackMessageVoice = APIHelper.JsonDeserialize <BandwidthCallbackMessageVoice>(json); Response res = new Response(); if ("gather".Equals(callbackMessageVoice.EventType)) { string transferTo = callbackMessageVoice.Digits; transferTo = "+1" + transferTo.Replace("#", ""); PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.Number = transferTo; PhoneNumber[] phoneNumbers = { phoneNumber }; Transfer transfer = new Transfer(); transfer.PhoneNumbers = phoneNumbers; transfer.TransferCallerId = callbackMessageVoice.From; res.Add(transfer); } return(res.ToXml()); })); }
public override ActionResult Index(RenderModel model) { //var mainPanels = model.Content.Children; //var panelsFolder = mainPanels.FirstOrDefault(n => n.DocumentTypeAlias == "himuPanels"); //var vm = new HimuHomeVM(CurrentPage); //vm.ContactFormSent = false; //if (panelsFolder != null) //{ // var panels = panelsFolder.Children.OrderBy(p=>p.SortOrder) // .ToList(); // vm.Panels = panels; // var panelTitles = panelsFolder.Children // .Where(p => int.Parse(p.GetProperty("haveMenuItem").DataValue.ToString()) == 1 && p.DocumentTypeAlias != "himuTopPanel") // .Select(p => p.GetProperty("menuTitle").DataValue.ToString()) // .ToList(); // vm.PanelTitles = panelTitles; //} var vModel = ControllerHelpers.GetHomeModel(CurrentPage, model, false); return(base.Index(vModel)); }
public void TestGetOrCreateUserCreate() { var user = ControllerHelpers.GetOrCreateUser("*****@*****.**", _usersContext); Assert.AreEqual("*****@*****.**", user.UserId); Assert.AreEqual(0, user.CompletedCourses.Count); }
//============================================ GET: Edit ======================================================================== // GET: Transactions/Edit/5 public ActionResult Edit(int?id) { ControllerHelpers helper = new ControllerHelpers(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Transaction transaction = db.Transaction.Find(id); if (transaction == null) { return(HttpNotFound()); } TransactionViewModel viewModel = new TransactionViewModel(); ApplicationUser currUser = db.Users.Find(User.Identity.GetUserId()); if (currUser == null) { return(RedirectToAction("Login", "Account")); } List <AccountKey> AccountDisplay = helper.GetAccountDisplay(currUser); viewModel.editTransaction = transaction; viewModel.AccountId = new SelectList(AccountDisplay, "Id", "InstitutionName"); viewModel.CategoryId = new SelectList(db.Category, "Id", "Name"); viewModel.TypeTransactionId = new SelectList(db.TypeTransaction, "Id", "Name"); return(View(viewModel)); }
public async Task <IActionResult> ManageRoomUsers( int id, string currentFilter, string searchString, int?page) { var room = _roomRepo.GetRoomById(id); if (room == null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } if (!await _authHelpers.CheckDormitoryMembership(User, room.Dormitory)) { return(ControllerHelpers.ShowAccessDeniedErrorPage(this)); } if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewData["CurrentFilter"] = searchString; var users = !String.IsNullOrEmpty(searchString) ? _userRepo.GetUsersWithEmailLike(searchString) : _userRepo.Users.ToList(); var dormitory = room.Dormitory; var adminEmail = RolesData.AdminEmail ?? "*****@*****.**"; var usersWithoutDormitory = users .Where(x => x.DormitoryManagerId == null && x.DormitoryPorterId == null && x.RoomId == null && !x.NormalizedEmail.Equals(adminEmail)) .ToList(); var thisDormitoryUsers = users .Where(x => x.DormitoryPorterId == null && x.DormitoryManagerId == null && dormitory.Rooms.Any(z => z.Id == x.RoomId)) .ToList(); users = usersWithoutDormitory.Concat(thisDormitoryUsers).ToList(); int pageSize = 10; var model = new ManageRoomUsersViewModel() { Room = room, Users = new PaginatedList <ApplicationUser>(users, users.Count, page ?? 1, pageSize) }; return(View(model)); }
public async Task <ActionResult <ForaViewModel[]> > GetFora() { List <ForaViewModel> foraIndexItemViewModels = new List <ForaViewModel>(); List <Forum> fora = null; try { fora = await _context.Fora.ToListAsync(); } catch (Exception exception) { Console.WriteLine($"Reading fora tabe threw an exception {exception.Message}"); } foreach (Forum forum in fora) { ForaViewModel foraIndexItemViewModel = new ForaViewModel(); foraIndexItemViewModel.InjectFrom(forum); foraIndexItemViewModel.ThreadCount = await ControllerHelpers.GetThreadCountAsync(forum, _context).ConfigureAwait(false); foraIndexItemViewModel.LastThread = "Empty"; if (foraIndexItemViewModel.ThreadCount > 0) { LastForumThread LastThread = await ControllerHelpers.GetLatestThreadDataAsync(forum, _context).ConfigureAwait(false); foraIndexItemViewModel.LastThread = LastThread.Forum.Title + ": " + LastThread.Title + "By - " + LastThread.Author.UserName; } foraIndexItemViewModels.Add(foraIndexItemViewModel); } return(foraIndexItemViewModels.ToArray()); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["RequestForm"] = "register"; ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Firstname = model.Firstname, Lastname = model.Lastname }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = ControllerHelpers.EmailConfirmationLink(Url, user.Id, code, Request.Scheme); await ControllerHelpers.SendEmailConfirmationAsync(_emailSender, model.Email, callbackUrl); await _signInManager.PasswordSignInAsync(model.Email, model.Password, isPersistent : true, lockoutOnFailure : false); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(ReturnIndexView(model)); }
private IEnumerator Attach(GameObject target, Transform parent, InteractionSource source) { yield return(ControllerHelpers.AttachModel(target, parent, source, GLTFMaterial, GLTFMaterial)); if (AnimateControllerModel) { var newControllerInfo = new MotionControllerInfo() { }; newControllerInfo.LoadInfo(target.GetComponentsInChildren <Transform>(), this); controllerInfoForAnimation.Add(source.id, newControllerInfo); TraceHelper.Log("Controller added for animation"); } if (ShowDebugAxis) { if (source.handedness == InteractionSourceHandedness.Left) { axisRendererLeft = target.AddComponent <AxisRenderer>(); } else { axisRendererRight = target.AddComponent <AxisRenderer>(); } } }
protected IActionResult View(string controller, string action) { var viewFullQualifiedName = ControllerHelpers .GetFullQualifiedName(controller, action); return(new ActionResult(viewFullQualifiedName)); }
public async Task <JsonResult> Delete(int id) { string currentUserId = HttpContext.User.GetUserId(); Dictionary <string, object> response = new Dictionary <string, object>(); ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, currentUserId); if (user.EvernoteCredentials == null) { response["error"] = "You must authenticate with Evernote"; return(Json(response)); } IEvernoteService evernoteService = new EvernoteServiceSDK1(user.EvernoteCredentials); Bookmark bookmark = _dataAccess.GetBookmarkById(id); if (bookmark == null) { response["error"] = "Unable to delete bookmark: no such bookmark"; return(Json(response)); } if (bookmark.UserId != currentUserId) { response["error"] = "Unable to delete bookmark: user not authorised"; return(Json(response)); } _dataAccess.DeleteBookmark(bookmark); return(Json(response)); }
public async Task <IActionResult> AddWashingMachine(WashingMachine model) { var laundryId = model.LaundryId; var machinePosition = model.Position; var laundry = _laundryRepo.GetLaundryById(laundryId); if (!await _authHelpers.CheckDormitoryMembership(User, laundry.Dormitory)) { return(ControllerHelpers.ShowAccessDeniedErrorPage(this)); } if (_washingMachineRepo.WashingMachines.Any(x => x.Position == machinePosition && x.LaundryId == laundryId)) { var dayViewModel = CreateDayViewModel(laundry.DormitoryId, DateTime.Today); dayViewModel.AddWashingMachineError = "There is washing machine with the same number in this laundry."; dayViewModel.WashingMachineToAdd = new WashingMachine { Position = laundry.Position, LaundryId = laundryId }; return(View(nameof(Day), dayViewModel)); } var machine = _washingMachineRepo.AddWashingMachine(laundryId, machinePosition); return(RedirectToDayByLaundryId(machine.LaundryId, DateTime.Now.Date)); }
public JsonResult CheckAnswer(int QuestionId, String Query) { DataDifferencesModel differences; try { if (Query.Contains("Answer") && QuestionId != 41) { throw new Exception("You can't use the answer table in your answer"); } Database db = new Database(_da); Boolean correct = db.CheckAnswer(QuestionId, Query, GetActiveUser(), out differences); var exerciseService = IocContainer.Container.GetInstance <IExerciseService>(); _da.LogUserQuery(GetCurrentUserId(), Query, QuestionId, UsersActionsTypes.CheckAnswer); if (correct) { exerciseService.MarkQuestionAsAnswered(QuestionId, GetActiveUser()); } String differencesHTML = ControllerHelpers.RenderViewToString(this.ControllerContext, "AnswerDifferences", differences); return(Json(new { correctAnswer = correct, differences = differencesHTML })); } catch (Exception ex) { return(Json(new { error = ControllerHelpers.TranslateQueryException(ex.Message) })); } }
protected IActionResult <TModel> View <TModel>(TModel model, [CallerMemberName] string caller = "") { var controllerName = ControllerHelpers.GetControllerName(this); var viewFullQualifiedName = ControllerHelpers.GetFullQualifiedName(controllerName, caller); return(new ActionResult <TModel>(viewFullQualifiedName, model)); }
public StaffDTO GetDepartmentLeader(Guid departmentId) { var result = new StaffDTO(); SessionManager.DoWork(session => { Staff st = ControllerHelpers.GetCurrentStaff(session); //Nếu ở bộ môn vào ko có chức vụ => giảng viên if (st.StaffInfo.Subject != null && st.StaffInfo.Position == null) { //Lấy trưởng bộ môn Staff staff = session.Query <Staff>().FirstOrDefault(s => s.StaffInfo.Subject != null && s.StaffInfo.Subject.Id == st.StaffInfo.Subject.Id && s.StaffInfo.Position != null && s.StaffInfo.Position.AgentObjectType.Id == 6); if (staff != null) { result = ParseStaff(staff); } } else { if (departmentId != Guid.Empty) { Staff staff = session.Query <Staff>().FirstOrDefault(s => s.Department.Id == departmentId && (s.StaffInfo.Position.AgentObjectType.Id == 3 || s.StaffInfo.Position.AgentObjectType.Id == 5)); if (staff != null) { result = ParseStaff(staff); } } } }); return(result); }
public async Task <IActionResult> AssignPorter(int dormitoryId, string porterEmail) { var dormitory = _dormitoryRepo.GetSingleById(dormitoryId); if (dormitory == null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } if (!await _authHelpers.CheckDormitoryMembership(User, dormitory)) { return(ControllerHelpers.ShowAccessDeniedErrorPage(this)); } var user = _userRepo.GetUserByEmail(porterEmail); user.DormitoryPorterId = dormitoryId; _userRepo.AssignDormitoryAsPorter(user, dormitory); if (await _userManager.IsInRoleAsync(user, "Porter") == false) { await _userManager.AddToRoleAsync(user, "Porter"); } return(RedirectToAction("Details", new { id = dormitoryId })); }
// GET: BankAccounts/Details/5 public ActionResult Details(int?id) { AccountDetailViewModel viewModel = new AccountDetailViewModel(); ControllerHelpers helper = new ControllerHelpers(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } viewModel.Account = db.Account.Find(id); viewModel.Transactions = db.Transaction.Where(db => db.AccountId == viewModel.Account.Id).ToList(); if (viewModel.Account == null) { return(HttpNotFound()); } ApplicationUser currUser = db.Users.Find(User.Identity.GetUserId()); if (currUser == null) { return(RedirectToAction("Login", "Account")); } List <Transaction> currTransactions = helper.GetTransactions(currUser); List <AccountKey> AccountDisplay = helper.GetAccountDisplay(currUser); viewModel.currTransactions = currTransactions; viewModel.AccountId = new SelectList(AccountDisplay, "Id", "InstitutionName"); viewModel.CategoryId = new SelectList(db.Category, "Id", "Name"); viewModel.TypeTransactionId = new SelectList(db.TypeTransaction, "Id", "Name"); return(View(viewModel)); }
public ActionResult Delete(string id) { var oid = ControllerHelpers.GetObjectId(id); var model = contactService.GetContact(oid).ToModel(); return(View(model)); }
public async Task <IActionResult> CancelReservation(int reservationId) { var reservation = _reservationRepo.GetReservationById(reservationId); if (!await _authHelpers.CheckDormitoryMembership(User, reservation.WashingMachine.Laundry.Dormitory)) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } var userId = _userManager.GetUserId(User); var roomId = _userRepo.GetUserById(userId).RoomId; if (_reservationRepo.GetHourReservation(reservation.WashingMachineId, reservation.StartTime) == null || _reservationRepo.IsFaultAtTime(reservation.WashingMachineId, reservation.StartTime) || reservation.StartTime < DateTime.Now || roomId != reservation.RoomId && roomId != null) { return(ControllerHelpers.Show404ErrorPage(this, _localizer)); } // ReSharper disable once PossibleNullReferenceException _reservationRepo.RemoveReservation(reservation); return(RedirectToDayByLaundryId(reservation.WashingMachine.LaundryId, reservation.StartTime)); }
public IActionResult Index(string returnUrl = null) { HomeIndexViewModel model; if (_signInManager.IsSignedIn(User)) { var userId = _userManager.GetUserId(User); var user = _userRepo.GetUserById(userId); int?dormitoryId = user.Room?.DormitoryId ?? user.DormitoryManagerId ?? user.DormitoryPorterId; if (dormitoryId != null) { model = new HomeIndexViewModel() { DayViewModel = ControllerHelpers.CreateDayViewModel(dormitoryId.Value, DateTime.Today.Date, userId, _laundryRepo, _reservationRepo, _userRepo), Announcements = _announcementRepo.GetDormitoryAnnouncements(dormitoryId.Value), Dormitory = user.Room?.Dormitory ?? user.DormitoryManager ?? user.DormitoryPorter }; return(View(model)); } RedirectToAction(nameof(DormitoryController.Index), "Dormitory"); } ViewData["ReturnUrl"] = returnUrl; model = new HomeIndexViewModel() { LoginViewModel = new LoginViewModel(), RegisterViewModel = new RegisterViewModel() }; return(View(model)); }
private IEnumerator Attach(GameObject target, Transform parent, InteractionSource source) { yield return(ControllerHelpers.AttachModel(target, parent, source, GLTFMaterial, GLTFMaterial)); inProgressSources.Remove(source.id); FinishControllerSetup(target, source.handedness.ToString(), source.id); if (ShowDebugAxis) { TraceHelper.LogOnUnityThread("Attaching Debug Axis to " + source.handedness); if (source.handedness == InteractionSourceHandedness.Left) { axisRendererLeft = target.AddComponent <AxisRenderer>(); } else { axisRendererRight = target.AddComponent <AxisRenderer>(); } } #if SKIPNPUTMODULE WinMRSnippets.Samples.Input.MotionControllerInputModule.Instance.AddController(source.id); WinMRSnippets.Samples.Input.MotionControllerInputModule.Instance.AddController(source.id); #endif }
protected IActionResult View([CallerMemberName] string caller = "") { var controllerName = ControllerHelpers.GetControllerName(this); // child controller var viewFullQualifiedName = ControllerHelpers.GetFullQualifiedName(controllerName, caller); return(new ActionResult(viewFullQualifiedName)); }
public async Task <JsonResult> Put(string guid, decimal percentageRead) { string currentUserId = HttpContext.User.GetUserId(); Dictionary <string, object> response = new Dictionary <string, object>(); ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, currentUserId); if (user.EvernoteCredentials == null) { response["error"] = "You must authenticate with Evernote"; return(Json(response)); } IEvernoteService evernoteService = new EvernoteServiceSDK1(user.EvernoteCredentials); Bookmark bookmark = _dataAccess.GetAutomaticBookmark(currentUserId, guid); if (bookmark == null) { bookmark = new Bookmark() { NoteGuid = guid, Type = BookmarkType.Automatic, UserId = currentUserId, Updated = DateTime.Now }; } bookmark.PercentageRead = percentageRead; bookmark.Updated = DateTime.Now; _dataAccess.SaveBookmark(bookmark); return(Json(response)); }
public static bool IsAllowPlanMaking(Guid currentUserId, Guid normalstaffId, NHibernate.ISession session) { bool result = false; //SessionManager.DoWork(session => //{ Staff supervisor = ControllerHelpers.GetCurrentStaff(session); Staff normalStaff = session.Query <Staff>().SingleOrDefault(s => s.Id == normalstaffId); if (supervisor.Id != normalStaff.Id) { if (supervisor != null) { if (supervisor.StaffInfo.Position != null) { switch (supervisor.StaffInfo.Position.AgentObjectType.Id) { case (int)AgentObjectTypes.PhongBan: { if ((normalStaff.StaffInfo.Position == null || normalStaff.StaffInfo.Position.AgentObjectType.Id == 7) && normalStaff.Department.Id == supervisor.Department.Id) { result = true; } } break; case (int)AgentObjectTypes.Khoa: { if ((normalStaff.StaffInfo.Position == null || normalStaff.StaffInfo.Position.AgentObjectType.Id == 8) && normalStaff.Department.Id == supervisor.Department.Id) { result = true; } } break; case (int)AgentObjectTypes.HieuTruong: { if (normalStaff.StaffInfo.Position != null && normalStaff.StaffInfo.Position.AgentObjectType.Id == 11 && normalStaff.Department.Id == supervisor.Department.Id) { result = true; } else if (normalStaff.StaffInfo.Position != null) { result = true; } } break; } } } } else { return(true); } return(result); }
protected IActionResult <TModel> View <TModel> (TModel model, string controller, string action) { var viewFullQuilifiedName = ControllerHelpers.GetVeiwFullQualifiedName(controller, action); return(new ActionResult <TModel>(viewFullQuilifiedName, model)); }
public String GetAnswerPreview(int QuestionId) { Database db = new Database(_da); QuestionModel question = _da.GetQuestion(QuestionId); DataTable results = db.ExecuteUserQuery(QuestionId, question.AnswerTemplate, -1); return(ControllerHelpers.RenderViewToString(this.ControllerContext, "ExecuteUserQuery", results)); }
protected IActionResult View([CallerMemberName] string caller = "") { string controllername = ControllerHelpers.GetControllerName(this); string fullQualifiedName = ControllerHelpers.GetFullQualifiedName(controllername, caller); return(new ActionResult(fullQualifiedName)); }