public static void BulkInsertLeonid(int number, ref List <Statistics> statsList, string connectionString) { DataTable insertDataTable = new DataTable(); insertDataTable.Columns.Add("UUID", typeof(SqlGuid)); for (int i = 0; i < number; i++) { SqlGuid myGuid = SqlGuidUtil.NewSequentialId(); DataRow row = insertDataTable.NewRow(); row["UUID"] = myGuid; insertDataTable.Rows.Add(row); } Stopwatch stopwatch = new Stopwatch(); Statistics stats = new Statistics(); using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); stopwatch.Start(); using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con)) { bulkCopy.BulkCopyTimeout = 3600; bulkCopy.DestinationTableName = "[dbo].[SQLGuidUtilTestTable]"; // Write from the source to the destination. bulkCopy.WriteToServer(insertDataTable); } stopwatch.Stop(); SqlCommand getRowCount = new SqlCommand("GetRowcountFromTable", con); getRowCount.CommandType = CommandType.StoredProcedure; getRowCount.Parameters.Add(new SqlParameter("@schema_name", "dbo")); getRowCount.Parameters.Add(new SqlParameter("@table_name", "SQLGuidUtilTestTable")); SqlParameter pvRowCount = new SqlParameter(); pvRowCount.ParameterName = "@row_count"; pvRowCount.DbType = DbType.Int32; pvRowCount.Direction = ParameterDirection.Output; getRowCount.Parameters.Add(pvRowCount); getRowCount.ExecuteNonQuery(); //int rowCount = int.Parse(getRowCount.Parameters["@row_count"].Value.ToString()); int rowCount = Convert.ToInt32(getRowCount.Parameters["@row_count"].Value); stats.NumberOfRowsInTable = rowCount; stats.Operation = System.Reflection.MethodBase.GetCurrentMethod().Name; stats.DurationInMilliseconds = stopwatch.ElapsedMilliseconds; statsList.Add(stats); } }
public static void InsertLeonid(int number, ref List <Statistics> statsList, string connectionString) { Stopwatch stopwatch = new Stopwatch(); Statistics stats = new Statistics(); using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); stopwatch.Start(); for (int i = 0; i < number; i++) { Guid myGuid = SqlGuidUtil.NewSequentialId(); string cmd = string.Format("INSERT INTO SQLGuidUtilTestTable ([UUID]) VALUES ('{0}')", myGuid.ToString()); SqlCommand command = new SqlCommand(cmd, con); command.ExecuteNonQuery(); cmd = string.Format("INSERT INTO SQLGuidUtilTestTableFKTable (FK) VALUES ('{0}')", myGuid.ToString()); command = new SqlCommand(cmd, con); command.ExecuteNonQuery(); } stopwatch.Stop(); SqlCommand getRowCount = new SqlCommand("GetRowcountFromTable", con); getRowCount.CommandType = CommandType.StoredProcedure; getRowCount.Parameters.Add(new SqlParameter("@schema_name", "dbo")); getRowCount.Parameters.Add(new SqlParameter("@table_name", "SQLGuidUtilTestTable")); SqlParameter pvRowCount = new SqlParameter(); pvRowCount.ParameterName = "@row_count"; pvRowCount.DbType = DbType.Int32; pvRowCount.Direction = ParameterDirection.Output; getRowCount.Parameters.Add(pvRowCount); getRowCount.ExecuteNonQuery(); //int rowCount = int.Parse(getRowCount.Parameters["@row_count"].Value.ToString()); int rowCount = Convert.ToInt32(getRowCount.Parameters["@row_count"].Value); stats.NumberOfRowsInTable = rowCount; stats.Operation = System.Reflection.MethodBase.GetCurrentMethod().Name; stats.DurationInMilliseconds = stopwatch.ElapsedMilliseconds; statsList.Add(stats); } }
public async Task <ActionResult> Create(CategoryViewModel categoryViewModel) { if (ModelState.IsValid) { var category = new Category { Id = SqlGuidUtil.NewSequentialId(), CategoryName = categoryViewModel.CategoryName, IsActive = categoryViewModel.IsActive }; // Then create: _db.Categories.Add(category); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public async Task <ActionResult> Create(SkillViewModel skillViewModel) { if (ModelState.IsValid) { var skill = new Skill { SkillId = SqlGuidUtil.NewSequentialId(), SkillName = skillViewModel.SkillName, IsActive = skillViewModel.IsActive }; // Then create: _db.Skills.Add(skill); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public async Task <ActionResult> Create(PostJobViewModel obj, HttpPostedFileBase file) { string categorypass = null; string skillpass = null; if (!ModelState.IsValid) { return(View(obj)); } var pn = new Job { JobDetails = obj.JobDetails, ExpireDate = obj.ExpireDate, Id = SqlGuidUtil.NewSequentialId(), IsNotification = obj.IsNotification, Lan = obj.Lan, Lat = obj.Lat, PostedDate = obj.PostedDate, Radius = obj.Radius, JobTitle = obj.JobTitle, CompanyAddress = obj.CompanyAddress, CompanyJobId = obj.CompanyJobId, CompanyName = obj.CompanyName, MonthExperience = obj.MonthExperience, Website = obj.Website, YearExpereince = obj.YearExpereince, IsApplicableforWholeCity = obj.IsApplicableforWholeCity }; if (obj.SelectedCategory != null) { // Category foreach (string equipme in obj.SelectedCategory) { categorypass = categorypass + "'" + equipme + "',"; var postcategory = new JobCategory(); postcategory.Id = SqlGuidUtil.NewSequentialId(); postcategory.CategoryId = Guid.Parse(equipme); pn.JobCategories.Add(postcategory); } } if (obj.SelectedSkill != null) { // Category foreach (string skill in obj.SelectedSkill) { skillpass = skillpass + "'" + skill + "',"; var postskill = new JobSkill(); postskill.JobSkillId = SqlGuidUtil.NewSequentialId(); postskill.SkillId = Guid.Parse(skill); pn.JobSkills.Add(postskill); } } if (file != null && file.ContentLength > 0) { var ni = new JobImage { Id = SqlGuidUtil.NewSequentialId() }; // Initialize variables string sSavePath; // Set constant values sSavePath = "Images/"; if (!Directory.Exists(Server.MapPath("~/" + sSavePath))) { // if not created then it will create it. Directory.CreateDirectory(Server.MapPath("~/" + sSavePath)); } // Make sure a duplicate file doesn’t exist. If it does, keep on appending an // incremental numeric until it is unique var sFilename = Path.GetFileName(file.FileName); var fileExtension = Path.GetExtension(file.FileName); var fileAppend = 0; if (!string.IsNullOrWhiteSpace(sFilename)) { while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename))) { fileAppend++; sFilename = Path.GetFileNameWithoutExtension(file.FileName) + fileAppend.ToString() + fileExtension; } // Save document file.SaveAs(Server.MapPath("~/" + sSavePath + sFilename)); ni.ImagePath = "/" + sSavePath + sFilename; pn.JobImages.Add(ni); } } // Then create: _db.Jobs.Add(pn); await _db.SaveChangesAsync(); // If is Notification, then only send push notification if (!pn.IsNotification) { return(RedirectToAction("Index")); } IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); decimal radiust = Convert.ToDecimal(pn.Radius) * 1000; TimeSpan span = pn.ExpireDate - pn.PostedDate; //JobDataMap jdm = new JobDataMap(); if (categorypass != null) { categorypass = categorypass.Remove(categorypass.Length - 1); //jdm.Add("category", categorypass); } //jdm.Add("idd", pn.Id); //jdm.Add("lat", pn.Lat); //jdm.Add("lng", pn.Lan); //jdm.Add("title", pn.Title); //jdm.Add("description", pn.Description); //jdm.Add("expirationdate", pn.ExpireDate.ToString(CultureInfo.InvariantCulture)); //jdm.Add("radius", radiust.ToString("#.##")); //jdm.Add("millisecond", span.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); IJobDetail job = JobBuilder.Create <PushNewsScheduleJob>() .UsingJobData("category", categorypass) .UsingJobData("skills", skillpass) .UsingJobData("idd", pn.Id.ToString()) .UsingJobData("lat", pn.Lat) .UsingJobData("lng", pn.Lan) .UsingJobData("title", pn.JobTitle) .UsingJobData("description", pn.JobDetails) .UsingJobData("years", pn.YearExpereince) .UsingJobData("months", pn.MonthExperience) .UsingJobData("expirationdate", pn.ExpireDate.ToString()) .UsingJobData("radius", radiust.ToString("#.##")) .UsingJobData("millisecond", span.TotalMilliseconds.ToString()) .Build(); ITrigger trigger = TriggerBuilder.Create() .StartNow() .Build(); scheduler.ScheduleJob(job, trigger); //List<UserRegId> urlist = await _db.UserRegIds.Where(ur => ur.UserId = ).ToListAsync(); //foreach(UserRegId u in urlist) //{ // PushNewsModel pnm = new PushNewsModel(); // pnm.id = pn.Id.ToString(); // pnm.lat = pn.Lat; // pnm.lng = pn.Lan; // pnm.title = pn.Title; // pnm.description = pn.Description; // pnm.expirationdate = pn.ExpireDate.ToString(); // decimal radiust = pn.Radius * 1000; // pnm.radius = radiust.ToString("#.##"); // TimeSpan span = pn.ExpireDate - pn.PostedDate; // pnm.millisecond = span.TotalMilliseconds.ToString(); // SendNotification(u.RegId,pnm); //} return(RedirectToAction("Index")); }