public Company Save(CompanyRaw item) { var newItem = new Company { Name = item.Name, CountryId = item.CountryId }; _context.Company.Add(newItem); _context.SaveChanges(); return(newItem); }
public ActionResult Create(Project model) { try { ptcontext.Projects.Add(model); ptcontext.SaveChanges(); return(RedirectToAction("Edit", new { id = model.ID })); } catch { return(View(model)); } }
public void SaveCountries(List <CountryStage> countryStages) { var countries = countryStages.Select(MapToCountry).ToList(); _context.AddRange(countries); _context.SaveChanges(); }
public static void newReservation(reservation reservation) { using (var db = new PTContext()) { db.reservation.Add(reservation); db.SaveChanges(); } }
public (Project, string) CreateProject(Project model) { var projectExist = _db.Project.Any(x => x.Name == model.Name); if (!projectExist) { model.CreatedDate = DateTime.Now; model.ModifiedDate = DateTime.Now; model.Completed = false; //this will be auto set once all tasks are done. _db.Project.Add(model); _db.SaveChanges(); return(model, null); } return(null, $"Project '{model.Name}' already exists."); }
public (bool, string) CreateTask(TaskPT task) { if (!TaskExists(task.Name)) { var now = DateTime.Now; task.StatusId = (int)StatusId.New; task.CreatedDate = now; task.ModifiedDate = now; _db.Task.Add(task); _db.SaveChanges(); return(true, null); } return(false, $"A task '{task.Name}' already exists."); }
public ActionResult Create(Employee model) { try { if (!ModelState.IsValid) { return(View(model)); } ptcontext.Employees.Add(model); ptcontext.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(model)); } }
public static void editReservation(reservation reservation) { using (var db = new PTContext()) { reservation.customer.customerID = reservation.customerID; db.Entry(reservation).State = EntityState.Modified; db.Entry(reservation.customer).State = EntityState.Modified; db.SaveChanges(); } }
public (bool, string) CreateResource(Resource resource) { var resourceExist = _db.Resource.Any(x => x.Name == resource.Name); if (!resourceExist) { var now = DateTime.Now; resource.CreatedDate = now; resource.ModifiedDate = now; _db.Resource.Add(resource); _db.SaveChanges(); return(true, null); } return(false, $"Resource '{resource.Name}' already exists."); }
private static void UpdateSuper() { var dir = @"C:\Users\Trappist\Downloads\"; var files = Directory.GetFiles(dir, "ActivityStatement.*.html"); using (var dbContext = new PTContext()) { foreach (var file in files) { Console.Write(file); string date = file .Replace(dir, "") .Replace("ActivityStatement.", "") .Replace(".html", ""); Console.Write(date); var fileContents = File.ReadAllText(file); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(fileContents); var table = doc.GetElementbyId("tblOpenPositions_U1688065Body"); var tbodies = table.ChildNodes .Where(a => a.Name == "div").First() .ChildNodes.Where(a => a.Name == "table").First() .ChildNodes.Where(a => a.Name == "tbody"); foreach (var tbody in tbodies) { var row = tbody.ChildNodes.Where(a => a.Name == "tr").First(); if (row?.Attributes["class"]?.Value == "row-summary no-details") { var tds = row.ChildNodes.Where(a => a.Name == "td").ToList(); var ib = new Ib(); if (date.Length < 8) { date = date + "28"; } ib.Dateimported = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture); ib.Symbol = tds[0].InnerText; ib.Quantity = Convert.ToInt32(tds[1].InnerText); ib.Mult = tds[2].InnerText; ib.CostPrice = Convert.ToDecimal(tds[3].InnerText); ib.CostBasis = Convert.ToDecimal(tds[4].InnerText); ib.ClosePrice = Convert.ToDecimal(tds[5].InnerText); ib.Value = Convert.ToDecimal(tds[6].InnerText); ib.UnrealizedPL = Convert.ToDecimal(tds[7].InnerText); ib.Code = tds[8].InnerText; dbContext.Ib.Add(ib); } } File.Move(file, @"C:\Data\Imported\" + file.Replace(dir, "")); } dbContext.SaveChanges(); } }
static void Main(string[] args) { Console.WriteLine($"Options provided {(args?.Length > 0 ? args[0] : "None")}"); if (args?.Length > 0 ? args[0] == "super": false) { UpdateSuper(); return; } var refreshTimespan = new TimeSpan(4, 0, 0); using (var dbContext = new PTContext()) { var program = new Program(); var tickers = dbContext.Ticker.Where(t => !string.IsNullOrWhiteSpace(t.Url)); foreach (var ticker in tickers) { var lastTickerRecorded = dbContext.TickerHistory .Where(a => a.SchemeCode == ticker.SchemeCode) .Max(a => a.Daterecorded); if (lastTickerRecorded.HasValue && (DateTime.Now - lastTickerRecorded.Value) < refreshTimespan) { continue; } var nav = program.GetTickerUpdate(ticker.Url); nav.Wait(); if (nav != null) { var tickerHistory = new TickerHistory() { Daterecorded = DateTime.Now, SchemeCode = ticker.SchemeCode, Value = nav.Result }; dbContext.TickerHistory.Add(tickerHistory); } var task = Task.Delay(1000 * 10); task.Wait(); } dbContext.SaveChanges(); } //PTContext.ConnectionString = "Data Source=TRAPPIST-PC\\SQLEXPRESS;Initial Catalog=PT;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; }
public Account Save(Account account) { _context.Account.Add(account); _context.SaveChanges(); return(account); }
public Service Save(Service item) { _context.Service.Add(item); _context.SaveChanges(); return(item); }