public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var userProfile = await _context.UserProfile.FirstOrDefaultAsync(m => m.IdUser == id); if (userProfile == null) { return(NotFound()); } PortfolioContext db = new PortfolioContext(); var img = db.ImgUser.Where(m => m.IdUser == id); var educationUser = await _context.Education.FirstOrDefaultAsync(m => m.IdUser == id); var userServices = await _context.UserServices.FirstOrDefaultAsync(m => m.IdUser == id); var userWorkplace = await _context.UserWorkplace.FirstOrDefaultAsync(m => m.IdUser == id); var userBiography = await _context.UserBiography.FirstOrDefaultAsync(m => m.IdUser == id); FullUser model = new FullUser(); model.OneUser = userProfile; model.Image = img; model.EducationUser = educationUser; model.ServicesUser = userServices; model.WorkplaceUser = userWorkplace; model.BiographyUser = userBiography; return(View(model)); }
public IHttpActionResult Delete(int id) { if (id < 0) { return(BadRequest("Invalid id")); } using (var context = new PortfolioContext()) { try { var transaction = context.Transactions .Where(t => t.TransactionId == id) .FirstOrDefault(); if (transaction != null) { context.Entry(transaction).State = EntityState.Deleted; context.SaveChanges(); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } } }
public PortfolioController(IHubContext <StockStatsHub> hubContext, PortfolioContext portfolioContext, ILogger <PortfolioController> logger) { _hubContext = hubContext; _portfolioContext = portfolioContext; _logger = logger; }
public IHttpActionResult Put(Transaction transaction) { if (!ModelState.IsValid) { return(BadRequest("Invalid model")); } using (var context = new PortfolioContext()) { try { var result = context.Transactions.SingleOrDefault(t => t.TransactionId == transaction.TransactionId); if (result != null) { result.CashValue = transaction.CashValue; result.Commission = transaction.Commission; result.Date = transaction.Date; result.Name = transaction.Name; result.Price = transaction.Price; result.Shares = transaction.Shares; result.Symbol = transaction.Symbol; result.Type = transaction.Type; context.SaveChanges(); return(Ok()); } else { return(this.Insert(transaction)); } } catch (Exception ex) { return(InternalServerError(ex)); } } }
public IEnumerable <Transaction> Get() { using (var context = new PortfolioContext()) { return(context.Transactions.ToList()); } }
public ProjectTechnology GetByTechnologyId(int techId) { using (var context = new PortfolioContext()) { return(context.ProjectTechnologies.FirstOrDefault(_ => _.ProjectTechnologyId == techId)); } }
public SpeedrunController(SpeedrunContext context, PortfolioContext userContext, UserManager <ApplicationUser> userManager, ILogger <SpeedrunController> logger) { _srContext = context; _userContext = userContext; _userManager = userManager; _logger = logger; }
public async Task PostLabel([FromBody] PortfolioConfigAddLabelRequest labelRequest) { using (var context = new PortfolioContext()) { var portfolio = await context.Portfolios .Include(p => p.Configuration.Labels) .Include(p => p.Configuration.LabelGroups) .SingleAsync(p => p.ViewKey == labelRequest.ViewKey); var label = portfolio.Configuration.Labels.SingleOrDefault(l => l.FieldName == labelRequest.FieldName); var group = labelRequest.FieldGroup == null ? null : portfolio.Configuration.LabelGroups.Single(l => l.Name == labelRequest.FieldGroup); if (label == null) { label = new PortfolioLabelConfig(); portfolio.Configuration.Labels.Add(label); } // Update the label's fields label = PortfolioMapper.ConfigMapper.Map(labelRequest, label); label.Group = group; // Save await context.SaveChangesAsync(); } }
// GET: UserPortfolio/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var userPortfolio = await _context.UserPortfolio .FirstOrDefaultAsync(m => m.IdPortfolio == id); var userProfile = await _context.UserProfile .FirstOrDefaultAsync(m => m.IdUser == id); if (userPortfolio == null) { return(NotFound()); } PortfolioContext db = new PortfolioContext(); var img = db.ImgPortfolio.Where(m => m.IdPortfolio == id); FullPortfolio model = new FullPortfolio(); model.OnePortfolio = userPortfolio; model.OneProfile = userProfile; model.Image = img; return(View(model)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PortfolioContext context) { // https://abelsquidhead.com/index.php/2017/07/31/deploying-dbs-in-your-cicd-pipeline-with-ef-core-code-first/ // When the environment is hit for the first time after deployment, // Run all the migrations that haven’t been run yet in the correct order, and your new DB schemas will automatically be deployed. context.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); // Add Authenication middleware app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
public static List <ApplicationUser> GetValidUsersForRoles(this PortfolioContext context, params string[] validRoleNames) { var validRoleIds = context.Roles.Where(r => validRoleNames.Contains(r.Name)).Select(r => r.Id).ToList(); var validUserIds = context.UserRoles.Where(ur => validRoleIds.Contains(ur.RoleId)).Select(ur => ur.UserId).ToList(); return(context.Users.Where(u => validUserIds.Contains(u.Id)).ToList()); }
private static T buildLog <T>(PortfolioContext context, Func <DateTime, string, T> logFactory, DateTime timestamp, T log) where T : class { var changes = context.ChangeTracker.Entries().Where(c => c.State == EntityState.Modified); if (changes.Count() > 0) { string text; try { var logText = new List <string>(); foreach (var change in changes) { string container = null; if (change.Entity is PortfolioLabelConfig) { var label = change.Entity as PortfolioLabelConfig; container = (label.Label ?? label.FieldName).Replace(" ", "_"); } var originalValues = change.OriginalValues; var currentValues = change.CurrentValues; builLog(logText, originalValues, currentValues, container); } text = string.Join("; ", logText); } catch (Exception e) { text = e.ToString(); } log = logFactory(timestamp, text); } return(log); }
// Le constructeur instancie le contexte et le stocke dans une variable : // var newLogger = new ILogger<IndexModel>(); // var newContext = new PortfolioContext(); // var newPage = new IndexModel(newLogger, newContext); public IndexModel(ILogger <IndexModel> logger, PortfolioContext context) { this.logger = logger; this.context = context; this.logger.LogInformation("Classe IndexModel instanciée"); }
//****************************************************************************** public async Task <IActionResult> Edit(int?id) { int idCookie = 0; string statusPassword = ""; if (Request.Cookies.ContainsKey("IdUser") && Request.Cookies.ContainsKey("UserPassword")) { idCookie = int.Parse(Request.Cookies["IdUser"]); statusPassword = Request.Cookies["UserPassword"]; } if (statusPassword == "true" && idCookie > 0) { var blogUser = await _context.BlogUser.FindAsync(id); if (blogUser == null) { return(NotFound()); } PortfolioContext db = new PortfolioContext(); var img = db.ImgBlog.Where(m => m.IdBlog == id); FullBlog model = new FullBlog(); ViewBag.Type = model.GetType(); model.OneBlog = blogUser; model.Image = img; return(View(model)); } else { return(Redirect("/UserAuthorization/Index")); } }
public Email GetByImageId(int imageId) { using (var context = new PortfolioContext()) { return(context.Emails.FirstOrDefault(_ => _.EmailId == imageId)); } }
public BowlingController(BowlingContext context, PortfolioContext userContext, UserManager <ApplicationUser> userManager, ILogger <BowlingController> logger) { _bowlingContext = context; _userContext = userContext; _userManager = userManager; _logger = logger; }
public ProjectImage GetByImageId(int imageId) { using (var context = new PortfolioContext()) { return(context.ProjectImages.FirstOrDefault(_ => _.ProjectImageId == imageId)); } }
public List <ProjectImage> GetAllByProjectId(int projectId) { using (var context = new PortfolioContext()) { return(context.ProjectImages.Where(_ => _.ProjectId == projectId).ToList()); } }
public List <Email> GetAllEmails() { using (var context = new PortfolioContext()) { return(context.Emails.ToList()); } }
public List <int> GetAllIdsFor(int projectId) { using (var context = new PortfolioContext()) { return(context.ProjectImages.Where(_ => _.ProjectId == projectId) .Select(_ => _.ProjectImageId).ToList()); } }
public void DeleteBlogById(int commentId) { var context = new PortfolioContext(); var entryBlog = context.Blog.FirstOrDefault(x => x.BlogId == commentId); context.Blog.Remove(entryBlog); context.SaveChanges(); }
public void DeleteCommentById(int commentId) { var context = new PortfolioContext(); var entryComment = context.Comment.FirstOrDefault(x => x.CommentId == commentId); context.Comment.Remove(entryComment); context.SaveChanges(); }
private static void EF6Test() { var db = new PortfolioContext(); var first = db.Portfolios.Include("Accounts").First(); var accounts = first.Accounts; //var next = from p in db.Portfolios.Include("Accounts") select p; }
private Project MapProject <T>(PortfolioContext dest, IEnumerable <T> sourceProjectDetail, Project destProject, T latestSourceUpdate) where T : IPostgresProject { var oddSourceUpdate = latestSourceUpdate as oddproject; try { if (oddSourceUpdate != null) { if (SyncMaps.directorateKeyMap.ContainsKey(oddSourceUpdate.direct)) { oddSourceUpdate.direct = SyncMaps.directorateKeyMap[oddSourceUpdate.direct]; } else { oddSourceUpdate.direct = oddSourceUpdate.direct?.ToLower(); } } mapper.Map(latestSourceUpdate, destProject, opt => opt.Items[nameof(PortfolioContext)] = dest); destProject.Description = sourceProjectDetail.Where(u => !string.IsNullOrEmpty(u.short_desc)).OrderBy(u => u.timestamp).LastOrDefault()?.short_desc; // Take the last description return(destProject); } catch (AutoMapperMappingException ame) { if (latestSourceUpdate is oddproject && new string[] { "Size", "Directorate" }.Contains(ame.MemberMap.DestinationName)) { var oddProject = latestSourceUpdate as oddproject; switch (ame.MemberMap.DestinationName) { case "Directorate": log.Add($"MAPPING ERROR: Destination member = {ame.MemberMap.DestinationName}, source data = {oddProject.direct}"); break; case "Size": log.Add($"MAPPING ERROR: Source project size = {oddProject.project_size}"); break; } } else { switch (ame.MemberMap.DestinationName) { case nameof(Project.BudgetType): log.Add($"MAPPING ERROR: Destination member = {ame.MemberMap.DestinationName}, source budgettype = {latestSourceUpdate.budgettype}"); break; case nameof(Project.Category): log.Add($"MAPPING ERROR: Destination member = {ame.MemberMap.DestinationName}, source category = {latestSourceUpdate.category}"); break; default: log.Add($"MAPPING ERROR: Destination member = {ame.MemberMap.DestinationName}"); break; } } } return(null); }
public Project Edit(Project project) { using (var context = new PortfolioContext()) { context.Entry(project).State = EntityState.Modified; context.SaveChanges(); return(project); } }
public YugiohController(PortfolioContext userContext, UserManager <ApplicationUser> userManager, ILogger <YugiohController> logger, IMemoryCache cardCache, YugiohApiClient yugiohClient, YugiohContext yugiohContext) { _userContext = userContext; _userManager = userManager; _logger = logger; _cardCache = cardCache; _yugiohClient = yugiohClient; _yugiohContext = yugiohContext; }
public Email Delete(Email image) { using (var context = new PortfolioContext()) { context.Entry(image).State = EntityState.Deleted; context.SaveChanges(); return(image); } }
public List <Project> GetAllBlockchainProjects() { using (var context = new PortfolioContext()) { return(context.Projects .Include("ProjectTechnologies") .Include("ProjectImages").Where(_ => _.BlockchainProject == true).ToList()); } }
public List <Project> GetAllUnFeaturedProjects() { using (var context = new PortfolioContext()) { return(context.Projects .Include("ProjectTechnologies") .Include("ProjectImages").Where(_ => _.FeaturedProject == false).ToList()); } }
public List <Project> GetAllProjects() { using (var context = new PortfolioContext()) { return(context.Projects .Include("ProjectTechnologies") .Include("ProjectImages").ToList()); } }
protected void Seed(PortfolioContext context) { // Cascade null context.Database.ExecuteSqlCommand(@"IF(OBJECT_ID('Project_Media','F') IS NOT NULL) BEGIN ALTER TABLE Project DROP CONSTRAINT Project_Media END"); context.Database.ExecuteSqlCommand(@"ALTER TABLE Project ADD CONSTRAINT Project_Media FOREIGN KEY (MediaID) REFERENCES Media (ID) ON UPDATE CASCADE ON DELETE SET NULL"); context.Database.ExecuteSqlCommand(@"IF(OBJECT_ID('User_Media','F') IS NOT NULL) BEGIN ALTER TABLE AccountUser DROP CONSTRAINT User_Media END"); context.Database.ExecuteSqlCommand(@"ALTER TABLE AccountUser ADD CONSTRAINT User_Media FOREIGN KEY (MediaID) REFERENCES Media (ID) ON UPDATE CASCADE ON DELETE SET NULL"); // Create myself as a user var user = new AccountUser { FirstName = "Hannah", LastName = "Hamlin", Email = "*****@*****.**", Password = SecurePasswordHasher.Hash("password"), MediaID = null, CreatedAt = TimeStamp.Now(), UpdatedAt = TimeStamp.Now() }; context.AccountUsers.Add(user); context.SaveChanges(); }