public ActionResult DetailPemilu(int id) { RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbDetailPemiluRow> response = new RetrieveResponse <TbDetailPemiluRow>(); TbDetailPemiluRepository repository = new TbDetailPemiluRepository(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.EntityId = id; response = repository.Retrieve(connection, request); } return(PartialView(MVC.Views.Rukuntangga.Questioner._QuestionerDetailPemilu, response.Entity)); }
private void Worker() { while (queue != null) { signal.WaitOne(); if (queue == null) { break; } while (true) { try { DynamicParameters parameters; lock (sync) { if (queue == null || queue.Count == 0) { break; } parameters = queue.Dequeue(); inProgress++; } try { using (var connection = SqlConnections.NewByKey(ConnectionKey)) { connection.Execute(InsertCommand, parameters); } } finally { inProgress--; } } catch (Exception ex) { var internalLogger = Dependency.TryResolve <ILogger>("Internal"); if (internalLogger != null) { internalLogger.Write(LoggingLevel.Fatal, null, ex, this.GetType()); } } } } }
public ActionResult Detailxx(int id = 0) { RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbGaleryRow> response = new RetrieveResponse <TbGaleryRow>(); TbGaleryRepository repository = new TbGaleryRepository(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.EntityId = id; response = repository.Retrieve(connection, request); } return(View(MVC.Views.Rukuntangga.Galery.Detail, response.Entity)); }
public IUserDefinition ByUsername(string username) { if (username.IsEmptyOrNull()) { return(null); } return(TwoLevelCache.Get <UserDefinition>("UserByName_" + username.ToLowerInvariant(), TimeSpan.Zero, TimeSpan.FromDays(1), fld.GenerationKey, () => { using (var connection = SqlConnections.NewByKey("Default")) return GetFirst(connection, new Criteria(fld.Username) == username); })); }
public ActionResult Detail(int id = 0) { ListRequest request = new ListRequest(); ListResponse <TbDetailPemiluRow> response = new ListResponse <TbDetailPemiluRow>(); TbDetailPemiluRepository repository = new TbDetailPemiluRepository(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.Criteria = new Criteria("IdPemilu") == id; response = repository.List(connection, request); } return(View(MVC.Views.Rukuntangga.Questioner.QuestionerDetail, response.Entities)); }
public ActionResult CariAktifitas(string wildCard) { ListRequest request = new ListRequest(); ListResponse <TbDetailJenisKegiatanRow> response = new ListResponse <TbDetailJenisKegiatanRow>(); TbDetailJenisKegiatanRepository repository = new TbDetailJenisKegiatanRepository(); var ud = (UserDefinition)Authorization.UserDefinition; var kodeRt = ud.Ktp.KodeRt; using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.Criteria = new Criteria("NamaKegiatan").Like("%" + wildCard + "%"); response = repository.List(connection, request); } return(PartialView(MVC.Views.Rukuntangga.Aktifitas._AktifitasTerbaru, response.Entities)); }
private List <TbSlideShowRow> GetSlideshow(string kodeRt) { List <TbSlideShowRow> result = new List <TbSlideShowRow>(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { List <TbSlideShowRow> data = connection.List <TbSlideShowRow>(x => x.SelectTableFields().Where(string.Format("KodeRt = '{0}'", kodeRt))); if (data.Count > 0) { result = data; } } return(result); }
public ActionResult Index() { TbKtpRepository repo = new TbKtpRepository(); RetrieveRequest request = new RetrieveRequest(); RetrieveResponse <TbKtpRow> response = new RetrieveResponse <TbKtpRow>(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { var ud = (UserDefinition)Serenity.Authorization.UserDefinition; request.EntityId = ud.Ktp.Id; response = repo.Retrieve(connection, request); } return(View(MVC.Views.Rukuntangga.Profile.ProfileIndex, response.Entity)); }
private TbKtpRow GetDataKtp(string userName) { TbKtpRow result = new TbKtpRow(); using (var connection = SqlConnections.NewByKey("Rukuntangga")) { var data = connection.Query <TbKtpRow>("SpGetKtpFromUsername", param: new { UserName = userName }, commandType: System.Data.CommandType.StoredProcedure); if (data != null) { result = data.FirstOrDefault(); } } return(result); }
public ActionResult CariBerita(string wildCard) { ListRequest request = new ListRequest(); ListResponse <TbDetailJenisInformasiRow> response = new ListResponse <TbDetailJenisInformasiRow>(); TbDetailJenisInformasiRepository repository = new TbDetailJenisInformasiRepository(); //var ud = (UserDefinition)Serenity.Authorization.UserDefinition; //var kodeRt = ud.Ktp.KodeRt; using (var connection = SqlConnections.NewByKey("Rukuntangga")) { request.Criteria = new Criteria("Judul").Like("%" + wildCard + "%"); response = repository.List(connection, request); } return(PartialView(MVC.Views.Rukuntangga.Berita._BeritaTerbaru, response.Entities)); }
public void SqlInsert_WorksWithEnums() { using (var dbContext = NewDbTestContext()) using (var connection = SqlConnections.NewByKey("Serenity")) { new SqlInsert(DisplayOrderRow.TableName) .Set(fld.DisplayOrder, MyEnum32.Value2) .Set(fld.IsActive, 1) .Execute(connection); var row = connection.Single <DisplayOrderRow>(Criteria.Empty); Assert.NotNull(row); Assert.Equal(row.DisplayOrder, (int)MyEnum32.Value2); } }
public object GetData() { var data = new AverageData(); var st = new DataTable(); using (var connection = SqlConnections.NewByKey("Store")) { var s = WarehouseRow.Fields; data.StoreList = connection.List <WarehouseRow>(q => q .SelectTableFields() .Where(s.TenantId == (int)this.Tenant) .OrderBy(s.ShopId, s.Key, s.Date, s.OperationId, s.MoveId)); return(data); } }
private HashSet <int> GetUserRoles(int userId) { var fld = UserRoleRow.Fields; return(TwoLevelCache.GetLocalStoreOnly("UserRoles:" + userId, TimeSpan.Zero, fld.GenerationKey, () => { using (var connection = SqlConnections.NewByKey("Default")) { var result = new HashSet <int>(); connection.List <UserRoleRow>(q => q .Select(fld.RoleId) .Where(new Criteria(fld.UserId) == userId)) .ForEach(x => result.Add(x.RoleId.Value)); return result; } })); }
public ActionResult Activate(string t) { using (var connection = SqlConnections.NewByKey("Default")) using (var uow = new UnitOfWork(connection)) { int userId; try { var bytes = HttpContext.RequestServices .GetDataProtector("Activate").Unprotect(Convert.FromBase64String(t)); using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { var dt = DateTime.FromBinary(br.ReadInt64()); if (dt < DateTime.UtcNow) { return(Error(Texts.Validation.InvalidActivateToken)); } userId = br.ReadInt32(); } } catch (Exception) { return(Error(Texts.Validation.InvalidActivateToken)); } var user = uow.Connection.TryById <UserRow>(userId); if (user == null || user.IsActive != 0) { return(Error(Texts.Validation.InvalidActivateToken)); } uow.Connection.UpdateById(new UserRow { UserId = user.UserId.Value, IsActive = 1 }); BatchGenerationUpdater.OnCommit(uow, UserRow.Fields.GenerationKey); uow.Commit(); return(new RedirectResult("~/Account/Login?activated=" + Uri.EscapeDataString(user.Email))); } }
public static Result <TResponse> UseConnection <TResponse>(this Controller controller, string connectionKey, Func <IDbConnection, TResponse> handler) where TResponse : ServiceResponse, new() { TResponse response; try { using (var connection = SqlConnections.NewByKey(connectionKey)) response = handler(connection); } catch (Exception exception) { response = exception.ConvertToResponse <TResponse>(); } return(new Result <TResponse>(response)); }
public IEnumerable GetData() { var fld = CustomerRow.Fields; var row = new CustomerRow(); var query = new SqlQuery().From(row).SelectTableFields(); if (!OrnekIcerir.IsEmptyOrNull()) { query.Where(fld.Name.Contains(OrnekIcerir)); } using (var connection = SqlConnections.NewByKey("Default")) { return(connection.Query <Item>(query)); } }
public ActionResult Terbaru() { List <TbDetailJenisKegiatanRow> response = new List <TbDetailJenisKegiatanRow>(); var ud = (UserDefinition)Authorization.UserDefinition; var kodeRt = ud.Ktp.KodeRt; using (var connection = SqlConnections.NewByKey("Rukuntangga")) { var parameterValue = connection.TrySingle <TbParameterRow>(q => q.SelectTableFields().Where(new Criteria(TbParameterRow.Fields.Kode) == "002")).Value; var data = connection.Query <TbDetailJenisKegiatanRow>("SpGetDetailJenisKegiatanNewest", param: new { KodeRt = kodeRt, LamaHari = parameterValue }, commandType: System.Data.CommandType.StoredProcedure); if (data != null) { response = (List <TbDetailJenisKegiatanRow>)data; } } return(PartialView(MVC.Views.Rukuntangga.Aktifitas._AktifitasTerbaru, response)); }
public void Vote(int idDetailPemilu) { SaveResponse response = new SaveResponse(); SaveRequest <Entities.TbPollingPemiluRow> request = new SaveRequest <TbPollingPemiluRow>(); TbPollingPemiluRepository repository = new TbPollingPemiluRepository(); TbPollingPemiluRow newRow = new TbPollingPemiluRow(); newRow.IdDetailPemilu = idDetailPemilu; using (var connection = SqlConnections.NewByKey("Rukuntangga")) using (var uow = new UnitOfWork(connection)) { { request.Entity = newRow; response = repository.Create(uow, request); uow.Commit(); } } }
public async new Task <ActionResult> Index() { var host = Request.Url.Host.Replace("www", ""); var index = host.IndexOf("."); var subdomain = host.Substring(0, index); var user = (UserDefinition)Serenity.Authorization.UserDefinition; var t = TenantsRow.Fields; var instagramAccount = ""; using (var c = SqlConnections.NewByKey("Default")) { instagramAccount = c.Query <string>( new SqlQuery() .From(t) .Select(t.InstagramAccount) .Where( new Criteria("[Domain]") == subdomain)) .FirstOrDefault(); } if (instagramAccount != "") { var url = string.Format("https://www.instagram.com/" + instagramAccount + "/?__a=1"); var syncClient = new WebClient(); var content = syncClient.DownloadString(url); // Create the Json serializer and parse the response DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Instagram.RootObject)); Instagram.RootObject instagramData = null; using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content))) { // deserialize the JSON object using the WeatherData type. instagramData = (Instagram.RootObject)serializer.ReadObject(ms); } return(View(MVC.Views.Common.Store.StorePage, instagramData)); } else { return(View(MVC.Views.Common.Store.StorePage)); } }
public ActionResult Index(int serviceTicketId) { var model = new Models.SonyKrediFaturaModel(); using (var connection = SqlConnections.NewByKey("Natro_TvHastanesi")) using (var uow = new UnitOfWork(connection)) { model.ServiceTicket = new MyRepository().Retrieve(uow.Connection, new RetrieveRequest() { EntityId = serviceTicketId }).Entity; model.Customer = new Endpoints.CustomerController().Retrieve(uow.Connection, new RetrieveRequest() { EntityId = model.ServiceTicket.CustomerId }).Entity; } return(View("~/Modules/TvHastanesi/ServiceTicket/SonyKrediFatura.cshtml", model)); }
public ActionResult CreateJoinUs(string parentName, string mobile, string childName, int sex, string birthday) { using (var connection = SqlConnections.NewByKey("Default")) using (var uow = new UnitOfWork(connection)) { connection.InsertAndGetID(new EnListRow { ParentName = parentName, Mobile = mobile, ChildName = childName, Sex = (MemberSex?)sex, Birthday = Convert.ToDateTime(birthday), InsertDate = DateTime.Now, InsertUserId = 1 }); uow.Commit(); return(Content("ok")); } }
private HashSet <string> GetRolePermissions(int userId) { var fld = RolePermissionRow.Fields; return(TwoLevelCache.GetLocalStoreOnly("RolePermissions:" + userId, TimeSpan.Zero, fld.GenerationKey, () => { using (var connection = SqlConnections.NewByKey("Default")) { var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase); connection.List <RolePermissionRow>(q => q .Select(fld.PermissionKey) .Where(new Criteria(fld.RoleId) == userId)) .ForEach(x => result.Add(x.PermissionKey)); return result; } })); }
public ActionResult Index() { var connection = SqlConnections.NewByKey("SistemaOS"); var today = DateTime.Today; var todayTime = new DateTime(today.Year, today.Month, today.Day, 0, 0, 0); var mes1 = new DateTime(today.Year, today.Month, 1, 0, 0, 1); var mes30 = new DateTime(today.Year, today.Month, 30, 0, 0, 1); var model = new DashboardPageModel(); model.QtdeOdermServicoAberto = connection.List <OrdemServicoRow>().Where(x => x.DataAtendimento >= todayTime && (x.Pago == null || x.Pago == false)).Count(); model.QtdeOdermServicoFechado = connection.List <OrdemServicoRow>().Where(x => x.Pago == true).Count(); model.QtdeOdermServicoAndamento = connection.List <OrdemServicoRow>().Where(x => x.DataAtendimento == todayTime && x.Pago == false).Count(); model.QtdeOdermServicoMes = connection.List <OrdemServicoRow>().Where(x => x.DataAtendimento >= mes1 && x.DataAtendimento <= mes30).Count(); model.QtdeNaoDirecionado = connection.List <OrdemServicoRow>().Where(x => x.AvariaPreExistente == "aguardandoFunc").Count(); connection.Close(); return(View(MVC.Views.Common.Dashboard.DashboardIndex, model)); }
private Dictionary <string, bool> GetUserPermissions(int userId) { var fld = UserPermissionRow.Fields; return(TwoLevelCache.GetLocalStoreOnly("UserPermissions:" + userId, TimeSpan.Zero, fld.GenerationKey, () => { using (var connection = SqlConnections.NewByKey("Default")) { var result = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase); connection.List <UserPermissionRow>(q => q .Select(fld.PermissionKey) .Select(fld.Granted) .Where(new Criteria(fld.UserId) == userId)) .ForEach(x => result[x.PermissionKey] = x.Granted ?? true); return result; } })); }
public static Result <TResponse> UseConnection <TResponse>(this Controller controller, string connectionKey, Func <IDbConnection, TResponse> handler) where TResponse : ServiceResponse, new() { TResponse response; try { using (var connection = SqlConnections.NewByKey(connectionKey)) response = handler(connection); } catch (Exception exception) { response = exception.ConvertToResponse <TResponse>(); controller.HttpContext.Response.Clear(); controller.HttpContext.Response.StatusCode = exception is ValidationError ? 400 : 500; controller.HttpContext.Response.TrySkipIisCustomErrors = true; } return(new Result <TResponse>(response)); }
protected override ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary <string, object> parameters) { var uowParam = actionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterType == typeof(IUnitOfWork)); if (uowParam != null) { var connectionKey = controllerContext.Controller.GetType().GetCustomAttribute <ConnectionKeyAttribute>(); if (connectionKey == null) { throw new ArgumentNullException("connectionKey"); } using (var connection = SqlConnections.NewByKey(connectionKey.Value)) using (var uow = new UnitOfWork(connection)) { parameters[uowParam.ParameterName] = uow; var result = base.InvokeActionMethod(controllerContext, actionDescriptor, parameters); uow.Commit(); return(result); } } var cnnParam = actionDescriptor.GetParameters().FirstOrDefault(x => x.ParameterType == typeof(IDbConnection)); if (cnnParam != null) { var connectionKey = controllerContext.Controller.GetType().GetCustomAttribute <ConnectionKeyAttribute>(); if (connectionKey == null) { throw new ArgumentNullException("connectionKey"); } using (var cnn = SqlConnections.NewByKey(connectionKey.Value)) { parameters[cnnParam.ParameterName] = cnn; return(base.InvokeActionMethod(controllerContext, actionDescriptor, parameters)); } } return(base.InvokeActionMethod(controllerContext, actionDescriptor, parameters)); }
public static Result <TResponse> InTransaction <TResponse>(this Controller controller, string connectionKey, Func <IUnitOfWork, TResponse> handler) where TResponse : ServiceResponse, new() { TResponse response; try { using (var connection = SqlConnections.NewByKey(connectionKey)) using (var uow = new UnitOfWork(connection)) { response = handler(uow); uow.Commit(); } } catch (Exception exception) { response = exception.ConvertToResponse <TResponse>(); } return(new Result <TResponse>(response)); }
public ActionResult GetPicturesQuery(int page = 0) { using (var connection = SqlConnections.NewByKey("Default")) using (var uow = new UnitOfWork(connection)) { page = page + 1; var pagesize = 6; var newsList = uow.Connection.List <PicturesRow>(); var total = page * pagesize; var jsonData = new { rows = newsList.Take(total).OrderBy(x => x.PictureId).ToList(), total = newsList.Count, page = page, pagesize = pagesize }; return(Content(jsonData.ToJson(), "application/Json", Encoding.UTF8)); } }
public List<NavigationItemAttribute> GetItems() { var items = new List<NavigationItemAttribute> { new NavigationMenuAttribute(7970, "Basic Samples/Dynamic Navigation", "icon-paper-plane") }; // Add product categories as dynamic navigation items for demo purpose using (var connection = SqlConnections.NewByKey("Northwind")) { var categories = connection.List<CategoryRow>(); foreach (var category in categories) items.Add(new NavigationLinkAttribute(7970, path: "Basic Samples/Dynamic Navigation/" + category.CategoryName.Replace("/", "//"), url: "~/Northwind/Product?cat=" + category.CategoryID, permission: Northwind.PermissionKeys.General, icon: "icon-folder-alt")); } return items; }
protected virtual List <TRow> GetItems() { var list = new List <TRow>(); var loader = new TRow(); var query = new SqlQuery() .From(loader); PrepareQuery(query); ApplyOrder(query); using (var connection = SqlConnections.NewByKey(RowRegistry.GetConnectionKey(loader))) { query.ForEach(connection, delegate() { list.Add(loader.Clone()); }); } return(list); }