public async Task <ResultObject> DeleteUnit(M_Unit unit) { var resultObj = new ResultObject { RowAffected = -1, ObjectValue = unit }; using (var context = new MasterDbContext(contextOptions)) { using (var transaction = context.Database.BeginTransaction()) { try { MySqlParameter[] sqlParams = new MySqlParameter[] { new MySqlParameter("strId", unit.Id), new MySqlParameter("strDelete_By", unit.Updated_By) }; //Output Parameter no need to define. @`strId` resultObj.RowAffected = await context.Database.ExecuteSqlCommandAsync("call sp_unit_delete( ?, ?)", parameters : sqlParams); transaction.Commit(); return(resultObj); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }
public async Task <List <M_Product_Process> > GetProductProcess(int prodId) { try { using (var context = new MasterDbContext(contextOptions)) { MySqlParameter[] sqlParams = new MySqlParameter[] { new MySqlParameter("strId", prodId) }; var objList = await context.Query <M_Product_ProcessObj>().FromSql("call sp_product_process_get(?)", parameters: sqlParams).ToListAsync(); return(objList.ConvertAll(p => new M_Product_Process { Id = p.Id, ProductId = p.ProductId, ProcessId = p.ProcessId, Is_Active = p.Is_Active, ProcessSeq = p.ProcessSeq, ProcessCode = p.ProcessCode, ProcessName = p.ProcessName })); } } catch (Exception ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { if (Session["logined"] == null) { Response.Redirect("~/Login.aspx"); } if (Request.QueryString["ID"] != null && string.IsNullOrEmpty(Request.QueryString["ID"].ToString()) == false && Request.HttpMethod == "GET") { // get data using (MasterDbContext db = new MasterDbContext()) { var id = Convert.ToInt32(Request.QueryString["ID"].ToString()); var item = db.Types.Find(id); if (item != null) { // set data txtName.Text = item.Name; } else { Response.Redirect("~/Type/List.aspx"); } } } }
////returns patientNumber for new patient (logic: maxPatientNo+1 ) //public static int GetNewPatientNo(string connString) //{ // PatientDbContext patientDbContext = new PatientDbContext(connString); // var maxPatNo = patientDbContext.Patients.DefaultIfEmpty().Max(p => p == null ? 0 : p.PatientNo); // //DefaultIfEmpty().Max(p => p == null ? 0 : p.X) // return maxPatNo.Value + 1; //} // Creates 16 Character UniqueCode based on EMPI logic public static string CreateEmpi(PatientModel obj, string connString) { /* EMPI: 16Characters * 1 -3: district 4-9 : DOB(DDMMYY) 10-12: Name Initials(FML) - X if no middle name 13-16 : Random Number * for eg: Name=Khadka Prasad Oli, District=Kailali, DOB=01-Dec-1990, EMPI= KAI011290KPO8972int districtId = obj.District;*/ MasterDbContext mstDB = new MasterDbContext(connString); string CountrySubDivisionName = (from d in mstDB.CountrySubDivision where d.CountrySubDivisionId == obj.CountrySubDivisionId select d.CountrySubDivisionName).First(); string strCountrySubDivision = CountrySubDivisionName.Substring(0, 3); string strFirstName = obj.FirstName.Substring(0, 1); //Use 'X' if middlename is not there. string strMiddleName = string.IsNullOrEmpty(obj.MiddleName) ? "X" : obj.MiddleName.Substring(0, 1); string strLastName = obj.LastName.Substring(0, 1); string strdateofbrith = obj.DateOfBirth.Value.ToString("ddMMyy"); int randomnos = (new Random()).Next(1000, 10000); var empi = strCountrySubDivision + strdateofbrith + strFirstName + strMiddleName + strLastName + randomnos; obj.EMPI = empi.ToUpper(); return(obj.EMPI); }
public TenantUserDeletedConsumer( ITenantDbContextFactory <MessagingContext> tenantDbContextFactory, MasterDbContext masterDbContext) { this.tenantDbContextFactory = tenantDbContextFactory; this.masterDbContext = masterDbContext; }
public TenantUserCreatedOrUpdatedConsumer( MasterDbContext masterDbContext, ITenantDbContextFactory <MessagingContext> tenantDbContextFactory) { this.masterDbContext = masterDbContext; this.tenantDbContextFactory = tenantDbContextFactory; }
// GET api/personne public IEnumerable <Vehicule> Get() { using (var context = new MasterDbContext()) { return(context.Vehicules.ToList()); } }
public static void SeedHostDb(MasterDbContext context) { //context.Database.Migrate(); context.SuppressAutoSetTenantId = true; CreateHostRoleAndUser(context); }
public bool AddCustomer(CustomerVM custVM) { try { MasterDbContext db = new MasterDbContext(); Customer l_oCust = new Customer(); //l_oCust.groupI = model.groupId; //l_oCust.cust_gstin=model //db.users.Add(l_oUser); //db.SaveChanges(); l_oCust.cust_name = custVM.cust_name; l_oCust.cust_uid_type = custVM.cust_uid_type; l_oCust.cust_uid = custVM.cust_uid; l_oCust.cust_dob = custVM.cust_dob; l_oCust.remarks = custVM.remarks; l_oCust.cust_gstin = custVM.firstfield + custVM.secondField + custVM.thirdfield; db.customers.Add(l_oCust); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public LoadPosts(IJsonPlaceholderApiClient client, MasterDbContext context, IMapper mapper, ILogger <LoadPosts> logger) { _client = client; _context = context; _mapper = mapper; _logger = logger; }
public IEnumerable <Category> GetAll() { using (MasterDbContext db = new MasterDbContext()) { return(db.Categories.AsNoTracking().Where(x => x.Activate == true).ToList()); } }
public MasterManager(ILogger <MasterManager> logger, MasterDbContext masterDbContext, IBus bus) { _logger = logger; _masterDbContext = masterDbContext; _bus = bus; }
public async Task <int> UpdateProductProcess(List <M_Product_Process> lstProdProcess) { int rowaffected = -1; using (var context = new MasterDbContext(contextOptions)) { using (var transaction = context.Database.BeginTransaction()) { try { foreach (M_Product_Process prodpro in lstProdProcess) { MySqlParameter[] sqlParams = new MySqlParameter[] { new MySqlParameter("strProductId", prodpro.ProductId), new MySqlParameter("strProcessId", prodpro.ProcessId), new MySqlParameter("strIs_Active", prodpro.Is_Active), new MySqlParameter("strUpdated_By", prodpro.Updated_By) }; rowaffected += await context.Database.ExecuteSqlCommandAsync("call sp_product_update_process(?, ?, ?, ?)", parameters : sqlParams); } transaction.Commit(); return(rowaffected); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }
public ActionResult AddUser(UserVM model) { MasterDbContext db = new MasterDbContext(); if (!ModelState.IsValid) { return(View(model)); } user l_oUser = new user(); l_oUser.groupId = model.groupId; l_oUser.id = model.id; l_oUser.isActive = model.isActive; l_oUser.userName = model.userName; l_oUser.userPass = ComputeSHA(model.userPass); l_oUser.loginId = model.loginId; db.users.Add(l_oUser); db.SaveChanges(); TempData["SM"] = "User successfully added!"; return(Redirect("UsersList")); //return View(); }
public TenantDeletedConsumer( MasterDbContext masterDbContext, ITenantDbContextFactory <TContext> tenantDbContextFactory) { this.masterDbContext = masterDbContext; this.tenantDbContextFactory = tenantDbContextFactory; }
public int Delete(int ID) { try { using (MasterDbContext db = new MasterDbContext()) { var item = db.Categories.Find(ID); if (item == null) { return(-1); } item.Activate = false; db.SaveChanges(); return(ID); } } catch { } return(-1); }
public async Task <List <M_Location> > GetLocation(int?id) { try { using (var context = new MasterDbContext(contextOptions)) { MySqlParameter[] sqlParams = new MySqlParameter[] { new MySqlParameter("strId", id) }; var objList = await context.Query <M_LocationObj>().FromSql("call sp_location_get(?)", parameters: sqlParams).ToListAsync(); return(objList.ConvertAll(loc => new M_Location { Id = loc.Id, LocationCode = loc.LocationCode, LocationName = loc.LocationName, LocationDesc = loc.LocationDesc, WarehouseId = loc.WarehouseId, WarehouseName = loc.WarehouseName, CompanyCode = loc.CompanyCode, Is_Active = loc.Is_Active, Created_By = loc.Created_By, Created_Date = loc.Created_Date, Updated_By = loc.Updated_By, Updated_Date = loc.Updated_Date })); } } catch (Exception ex) { throw ex; } }
public async Task <ResultObject> DeleteVendor(M_Vendor vendor) { var resultObj = new ResultObject { RowAffected = -1, ObjectValue = vendor }; using (var context = new MasterDbContext(contextOptions)) { using (var transaction = context.Database.BeginTransaction()) { try { MySqlParameter[] sqlParams = new MySqlParameter[] { new MySqlParameter("strId", vendor.Id), new MySqlParameter("strDelete_By", vendor.Updated_By) }; resultObj.RowAffected = await context.Database.ExecuteSqlCommandAsync("call sp_vendor_delete( ?, ?)", parameters : sqlParams); transaction.Commit(); return(resultObj); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }
public Master GetGraphIdFromMUUID(Guid muuid) { Master master = new Master(); try { using (var db = new MasterDbContext()) { master = (from m in db.Master where m.Uuid == MySQLByteArray(muuid) && m.Source == XMLSource.PLANNING.ToString() select m).FirstOrDefault(); Console.WriteLine(master.Id); Console.WriteLine(new Guid(master.Uuid).ToString()); Console.WriteLine(master.SourceEntityId); Console.WriteLine(master.EntityType); Console.WriteLine(master.EntityVersion); Console.WriteLine(master.Source); return(master); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(master); } }
public EfCoreMultiTenantMessageDispatcher(IServiceProvider serviceProvider, ITenantDbContextFactory <TContext> tenantOutboxDbContextFactory, MasterDbContext masterDbContext) { this.serviceProvider = serviceProvider; this.tenantOutboxDbContextFactory = tenantOutboxDbContextFactory; this.masterDbContext = masterDbContext; }
/// <summary> /// 获取当前账套发放出去的模具 /// </summary> /// <param name="request"></param> /// <returns></returns> protected override async Task <IQueryable <Project> > GetQueryable(RequestPageDto request) { var query = (await base.GetQueryable(request)) .Include(o => o.Tenant) .Where(o => MasterDbContext.GetJsonValueNumber(o.Unit.Property, "$.TenantId") == AbpSession.TenantId.Value); return(query); }
public static bool SynchronizationMethod(INode node, MasterDbContext masterDbContext, Server.ServerDbContext serverDbContext) { var oldNodeGroupLinks = masterDbContext.SymNodeGroupLink.Select(x => x).ToDictionary(x => string.Format("[{0}][{1}]", x.SourceNodeGroupId, x.TargetNodeGroupId), x => x); var newNodeGroupLinks = new Dictionary <string, char>(); var newNodeGroupLinkDatas = serverDbContext.Router.Include("SourceNodeGroup").Include("TargetNode.NodeGroup").Where(x => x.ProjectId == node.ProjectId).ToList(); foreach (var data in newNodeGroupLinkDatas) { newNodeGroupLinks.Add(string.Format("[{0}][{1}]", data.SourceNodeGroup.NodeGroupId, data.TargetNode.NodeGroup.NodeGroupId), 'P'); newNodeGroupLinks.Add(string.Format("[{0}][{1}]", data.TargetNode.NodeGroup.NodeGroupId, data.SourceNodeGroup.NodeGroupId), 'W'); } foreach (var nodeGroupLink in newNodeGroupLinks) { if (!oldNodeGroupLinks.ContainsKey(nodeGroupLink.Key)) { var values = nodeGroupLink.Key.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries); // 新增 masterDbContext.SymNodeGroupLink.Add(new SymNodeGroupLink { SourceNodeGroupId = values[0], TargetNodeGroupId = values[1], DataEventAction = nodeGroupLink.Value }); } else { // 修改 var oldNodeGroupLink = oldNodeGroupLinks[nodeGroupLink.Key]; oldNodeGroupLink.DataEventAction = nodeGroupLink.Value; } } foreach (var nodeGroupLink in oldNodeGroupLinks) { if (!newNodeGroupLinks.ContainsKey(nodeGroupLink.Key)) { // 刪除 masterDbContext.SymNodeGroupLink.Remove(nodeGroupLink.Value); } } bool result = false; try { masterDbContext.SaveChanges(); result = true; } catch (Exception e) { LogException(nameof(SynchronizationMethod), e); } return(result); }
// POST api/personne public Vehicule Post([FromBody] Vehicule value) { using (var context = new MasterDbContext()) { context.Vehicules.Add(value); context.SaveChanges(); return(value); } }
public HostedService(MasterDbContext masterDb, SlaveDbContext slaveDb, TestService uowSrv) { _masterDb = masterDb; _slaveDb = slaveDb; _testSrv = uowSrv; var blogs1 = _masterDb.Blog.ToList(); var blogs2 = _slaveDb.Blog.ToList(); }
public static bool Router(MasterDbContext masterDbContext, Server.ServerDbContext serverDbContext) { var oldRouters = masterDbContext.SymRouter.Select(x => x).ToDictionary(x => x.RouterId, x => x); var newRouters = serverDbContext.Router.Include("SourceNodeGroup").Include("TargetNode.NodeGroup").Select(x => x).ToDictionary(x => x.RouterId, x => x); DateTime dateTimeNow = DateTime.Now; foreach (var router in newRouters) { if (!oldRouters.ContainsKey(router.Key)) { // 新增 masterDbContext.SymRouter.Add(new SymRouter { RouterId = router.Value.RouterId, SourceNodeGroupId = router.Value.SourceNodeGroup.NodeGroupId, TargetNodeGroupId = router.Value.TargetNode.NodeGroup.NodeGroupId, RouterType = "default", CreateTime = dateTimeNow, LastUpdateTime = dateTimeNow }); } else { // 修改 var oldRouter = oldRouters[router.Key]; oldRouter.SourceNodeGroupId = router.Value.SourceNodeGroup.NodeGroupId; oldRouter.TargetNodeGroupId = router.Value.TargetNode.NodeGroup.NodeGroupId; oldRouter.CreateTime = dateTimeNow; oldRouter.LastUpdateTime = dateTimeNow; } } foreach (var router in oldRouters) { if (!newRouters.ContainsKey(router.Key)) { // 刪除 masterDbContext.SymRouter.Remove(router.Value); } } bool result = false; try { masterDbContext.SaveChanges(); result = true; } catch (Exception e) { LogException(nameof(Router), e); } return(result); }
public async Task <List <M_Product> > GetProduct(int?id) { try { using (var context = new MasterDbContext(contextOptions)) { MySqlParameter[] sqlParams = new MySqlParameter[] { new MySqlParameter("strId", id) }; var objList = await context.Query <M_ProductObj>().FromSql("call sp_product_get(?)", parameters: sqlParams).ToListAsync(); return(objList.ConvertAll(p => new M_Product { Id = p.Id, ProductCode = p.ProductCode, ProductName = p.ProductName, ProductNameRef = p.ProductNameRef, ProductDesc = p.ProductDesc, MaterialTypeId = p.MaterialTypeId, MaterialType = p.MaterialType, ProductionTypeId = p.ProductionTypeId, ProductionType = p.ProductionType, MachineId = p.MachineId, Machine = p.Machine, UnitId = p.UnitId, Unit = p.Unit, PackageStdQty = p.PackageStdQty, SalesPrice1 = p.SalesPrice1, SalesPrice2 = p.SalesPrice2, SalesPrice3 = p.SalesPrice3, SalesPrice4 = p.SalesPrice4, SalesPrice5 = p.SalesPrice5, GLSalesAccount = p.GLSalesAccount, GLInventAccount = p.GLInventAccount, GLCogsAccount = p.GLCogsAccount, RevisionNo = p.RevisionNo, WarehouseId = p.WarehouseId, Warehouse = p.Warehouse, LocationId = p.LocationId, Location = p.Location, ProductImagePath = p.ProductImagePath, CompanyCode = p.CompanyCode, Is_Active = p.Is_Active, Created_Date = p.Created_Date, Created_By = p.Created_By, Updated_Date = p.Updated_Date, Updated_By = p.Updated_By })); } } catch (Exception ex) { throw ex; } }
//get provider name from providerId public static string GetProviderName(int?providerId, string connString) { MasterDbContext dbContextProvider = new MasterDbContext(connString); EmployeeModel Provider = (from emp in dbContextProvider.Employees where emp.EmployeeId == providerId select emp).FirstOrDefault(); //obj.ProviderName = Provider.Salutation + "." + Provider.FirstName + "." + Provider.LastName + "(" + Provider.Designation + ")"; return(Provider.FullName); }
public TenantCreatedOrUpdatedConsumer(MasterDbContext masterDbContext, IConfiguration configuration, ITenantDbContextFactory <TContext> tenantDbContextFactory, IMemoryCache memoryCache) { this.masterDbContext = masterDbContext; this.configuration = configuration; this.tenantDbContextFactory = tenantDbContextFactory; this.memoryCache = memoryCache; }
protected void Page_Load(object sender, EventArgs e) { using (MasterDbContext db = new MasterDbContext()) { if (Session["logined"] != null) { DataTable data = new DataTable(); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MasterDbContext"].ToString()); //find current user int idUser = Convert.ToInt32(Session["logined"].ToString());; var user = db.Employees.Find(idUser); if (user.Name != "Admin") { tagCreate.Visible = false; } try { con.Open(); string[] selectedCol = new string[] { "st.ID AS ID", "st.Name AS 'Name'", "st.Phone AS 'Phone'", "st.Address AS 'Address'", "pos.Value AS 'Position'", "st.Salary AS 'Salary'", "st.CreatedTime AS 'Created Time'", "st.UpdatedTime AS 'Updated Time'", }; string query = "select " + String.Join(",", selectedCol) + " from Employees st INNER JOIN Positions pos ON st.PositionID = pos.ID where st.Active = 1"; SqlCommand cmd = new SqlCommand(query, con); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(data); GridViewStaff.DataSource = data; GridViewStaff.DataBind(); } catch { } finally { con.Close(); } } else { Response.Redirect("~/Login.aspx"); } } }
public static bool Channel(MasterDbContext masterDbContext, Server.ServerDbContext serverDbContext) { var oldChannels = masterDbContext.SymChannel.Select(x => x).ToDictionary(x => x.ChannelId, x => x); var newChannels = serverDbContext.Channel.Select(x => x).ToDictionary(x => x.ChannelId, x => x); foreach (var channel in newChannels) { if (!oldChannels.ContainsKey(channel.Key)) { // 新增 masterDbContext.SymChannel.Add(new SymChannel { ChannelId = channel.Value.ChannelId, ProcessingOrder = 1, MaxBatchSize = 100000, Enabled = 1, Description = channel.Value.Description }); } else { // 修改 var oldChannel = oldChannels[channel.Key]; oldChannel.Description = channel.Value.Description; } } foreach (var channel in oldChannels) { if (new string[] { "config", "reload", "monitor", "heartbeat", "default", "dynamic" }.Contains(channel.Key)) { continue; } if (!newChannels.ContainsKey(channel.Key)) { // 刪除 masterDbContext.SymChannel.Remove(channel.Value); } } bool result = false; try { masterDbContext.SaveChanges(); result = true; } catch (Exception e) { LogException(nameof(Channel), e); } return(result); }