ASP DOT NET

Monday, October 16, 2023

How to to select duplicate rows from sql server?

 SELECT * FROM Recruitment WHERE Email IN (SELECT Email FROM Recruitment GROUP BY Email HAVING COUNT(*) > 1);


WITH CTE AS (

    SELECT 

        Email,

        ROW_NUMBER() OVER (PARTITION BY Email ORDER BY (SELECT NULL)) AS RowNumber

    FROM Recruitment

)

SELECT * FROM CTE WHERE RowNumber > 1


--DELETE FROM CTE WHERE RowNumber > 1;

Wednesday, September 27, 2023

Thursday, September 7, 2023

How to Use IN Operator into Linq?

using System;

using System.Collections.Generic;

using System.Linq;

class Program

{

    static void Main()

    {

        // Sample collection of items

        List<int> items = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

        // List of values you want to check against

        List<int> valuesToCheck = new List<int> { 2, 5, 8 };


        // Use LINQ to filter items based on the valuesToCheck list

        var filteredItems = items.Where(item => valuesToCheck.Contains(item));

        // Display the filtered items

        foreach (var item in filteredItems)

        {

            Console.WriteLine(item);

        }

    }

Tuesday, August 22, 2023

What is Dependency Injection? Explanation with real time Examples.

Dependency Injection (DI) is a design pattern and a fundamental concept in software engineering that promotes loose coupling and modularization of components within an application. In the context of ASP.NET Core, Dependency Injection is a built-in feature that helps manage the dependencies of an application's components, making it easier to develop, test, and maintain code. 

In Dependency Injection, the basic idea is to invert the responsibility of creating and managing objects (dependencies) from a component to an external service, often referred to as the "container" or "DI container." The container is responsible for creating and providing instances of the required classes to the components that need them.

ASP.NET Core's Dependency Injection system is built on top of the .NET Core framework and is used to manage the dependencies of various components like controllers, services, middleware, and more. It provides the following benefits:

1.    Modularity and Reusability: Components can be developed independently and reassembled easily by specifying their dependencies through constructor parameters.

2.    Testability: By injecting dependencies into components, it becomes easier to substitute real implementations with mock objects during testing, improving the overall testability of the code.

3.    Maintainability: DI simplifies the process of managing dependencies, making it easier to swap implementations, add new features, or update existing ones.

4.    Flexibility: The same component can be reused in different contexts simply by injecting different implementations of its dependencies.


Here's a basic example of using Dependency Injection in an ASP.NET Core application:


// Define a service interface
public interface IMessageService
{
    string GetMessage();

}

// Implement the service

public class MessageService : IMessageService

{

    public string GetMessage()

    {

        return "Hello from the MessageService!";

    }

}

// Configure DI in Startup.cs

public void ConfigureServices(IServiceCollection services)

{

    services.AddScoped<IMessageService, MessageService>();

    services.AddControllersWithViews();

}

// Inject the service into a controller

public class HomeController : Controller

{

    private readonly IMessageService _messageService;

 

    public HomeController(IMessageService messageService)

    {

        _messageService = messageService;

    }

 

    public IActionResult Index()

    {

        string message = _messageService.GetMessage();

        return View((object)message);

    }

}


In this example, the HomeController depends on the IMessageService interface. During the application's startup, you've registered the MessageService implementation of IMessageService in the DI container using AddScoped. When an instance of HomeController is created, the DI container automatically provides an instance of MessageService, fulfilling the dependency.

ASP.NET Core provides a wide range of DI container lifetimes (AddTransientAddScopedAddSingleton) to control how instances are managed and shared across the application's components.

Remember that the built-in Dependency Injection system in ASP.NET Core makes it easier to manage and utilize dependencies, leading to cleaner, more maintainable, and testable code.


Certainly! Here are a few more examples of how Dependency Injection can be used in ASP.NET Core:


  1. Injecting Configuration:
You can inject configuration settings into your services or controllers, making it easy to access application settings without tightly coupling them to the configuration source.

public class MyService : IMyService

{

    private readonly IConfiguration _configuration;

     public MyService(IConfiguration configuration)

    {

        _configuration = configuration;

    }

     public string GetSetting(string key)

    {

        return _configuration[key];

    }

}

  1. Injecting Database Context:
In ASP.NET Core applications, you often work with databases using Entity Framework Core. You can inject your database context into controllers or services, making it easy to interact with the database without worrying about managing connections and lifetimes.

public class ProductService : IProductService

{

    private readonly ApplicationDbContext _context;

 

    public ProductService(ApplicationDbContext context)

    {

        _context = context;

    }

     public List<Product> GetProducts()

    {

        return _context.Products.ToList();

    }

}


  1. Injecting Logger:
Logging is essential for monitoring and debugging applications. You can inject a logger into your components, allowing you to log messages and exceptions easily.

public class MyService : IMyService

{

    private readonly ILogger<MyService> _logger;

 

    public MyService(ILogger<MyService> logger)

    {

        _logger = logger;

    }

 

    public void DoSomething()

    {

        _logger.LogInformation("Doing something...");

    }

}


  1. Injecting Custom Services:
You can define your own services and inject them into controllers or other services. This promotes separation of concerns and modularity.

public interface IEmailService

{

    void SendEmail(string recipient, string subject, string body);

}

 

public class EmailService : IEmailService

{

    public void SendEmail(string recipient, string subject, string body)

    {

        // Implementation to send an email

    }

}

 

public class MyController : Controller

{

    private readonly IEmailService _emailService;

 

    public MyController(IEmailService emailService)

    {

        _emailService = emailService;

    }

 

    public IActionResult SendEmail()

    {

        _emailService.SendEmail("recipient@example.com", "Hello", "This is a test email.");

        return View();

    }

}


  1. Injecting Repositories:
If you're following the repository pattern, you can inject repository interfaces into your services or controllers, making it easy to manage data access.

public class ProductService : IProductService

{

    private readonly IProductRepository _productRepository;

 

    public ProductService(IProductRepository productRepository)

    {

        _productRepository = productRepository;

    }

 

    public List<Product> GetProducts()

    {

        return _productRepository.GetAllProducts();

    }

}


These examples showcase how Dependency Injection can be applied to various scenarios within an ASP.NET Core application. By using DI, you achieve better separation of concerns, easier testing, and improved code maintainability.

Monday, July 31, 2023

All Visual Studio Product Keys

 SQL Server 2017

---------------- 

Enterprise Core - 6GPYM-VHN83-PHDM2-Q9T2R-KBV83 

Developer - 22222-00000-00000-00000-00000 

Enterprise - TDKQD-PKV44-PJT4N-TCJG2-3YJ6B 

Standard - PHDV4-3VJWD-N7JVP-FGPKY-XBV89 

Web - WV79P-7K6YG-T7QFN-M3WHF-37BXC 


https://www.teamos-hkrg.com/index.php?threads/microsoft-sql-server-english-2017-rtm-teamos.42103/


Visual Studio 2017

------------------- 

Enterprise:  NJVYC-BMHX2-G77MM-4XJMR-6Q8QF  |  N2VYX-9VR2K-T733M-MWD9X-KQCDF

Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH |  4F3PR-NFKDB-8HFP7-9WXGY-K77T7


Test Professional: VG622-NKFP4-GTWPH-XB2JJ-JFHVF 

Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF

Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH


Visual Studio 2019 

--------------------------

Professional: NYWVH-HT4XC-R2WYW-9Y3CM-X4V3Y |  NJVYC-BMHX2-G77MM-4XJMR-6Q8QF

Enterprise  : BF8Y8-GN2QH-T84XB-QVY3B-RC4DF |  KBJFW-NXHK6-W4WJM-CRMQB-G3CDH



Sublime Text 3 Serial key build is 3176

----------------------------------------


> * Added these lines into  /etc/hosts 


127.0.0.1       www.sublimetext.com

127.0.0.1       license.sublimehq.com


> * Used the license key


----- BEGIN LICENSE -----

sgbteam

Single User License

EA7E-1153259

8891CBB9 F1513E4F 1A3405C1 A865D53F

115F202E 7B91AB2D 0D2A40ED 352B269B

76E84F0B CD69BFC7 59F2DFEF E267328F

215652A3 E88F9D8F 4C38E3BA 5B2DAAE4

969624E7 DC9CD4D5 717FB40C 1B9738CF

20B3C4F1 E917B5B3 87C38D9C ACCE7DD8

5F7EF854 86B9743C FADC04AA FB0DA5C0

F913BE58 42FEA319 F954EFDD AE881E0B

------ END LICENSE ------


Microsoft office professional Plus 2016 

----------------------------------------

NBCRJ-YJ94Q-T73WV-9PR4F-9W3VC

KNJPJ-YBFTR-42K6M-Y6FMX-BKM3P      

QQ34F-N3THK-CWTFJ-HD66X-8QK7C

8FDTG-TNM2Y-C9DF9-QQ9XX-V22X2

Y89NG-BWMGT-KJPT3-B326G-683VC



Visual Studio 2022

--------------------------------------------

Enterprise: VHF9H-NXBBB-638P6-6JHCY-88JWH

Professional: TD244-P4NB7-YQ6XK-Y8MMM-YWV2J




Visual Studio 2019

--------------------------------------------

Enterprise BF8Y8-GN2QH-T84XB-QVY3B-RC4DF | KBJFW-NXHK6-W4WJM-CRMQB-G3CD 

https://visualstudio.microsoft.com/fr/thank-you-downloading-visual-studio/?sku=Enterprise&rel=16

Professional NYWVH-HT4XC-R2WYW-9Y3CM-X4V3Y | NJVYC-BMHX2-G77MM-4XJMR-6Q8QF 

https://visualstudio.microsoft.com/fr/thank-you-downloading-visual-studio/?sku=Professional&rel=16


Visual Studio 2017

----------------------------------------------

Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF | N2VYX-9VR2K-T733M-MWD9X-KQCDF

Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH | 4F3PR-NFKDB-8HFP7-9WXGY-K77T7

Test Professional: VG622-NKFP4-GTWPH-XB2JJ-JFHVF

Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF

Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH



Visual Studio 2010 Express

----------------------------------------------

Visual Basic: 2KQT8-HV27P-GTTV9-2WBVV-M7X96

C#: PQT8W-68YB2-MPY6C-9JV9X-42WJV

C++: 6VPJ7-H3CXH-HBTPT-X4T74-3YVY7

Web Developer: CY8XP-83P66-WCF9D-G3P42-K2VG3


Thursday, July 20, 2023

How to Generate Alphanumeric Id using c# Linq


            var res = hrmsEntities.LeadGenerations.Select(x => x.LeadId.Substring(7)).ToList();

            int maxvalue = res.Select(int.Parse).DefaultIfEmpty(0).Max();

            int gen = Convert.ToInt32(maxvalue) + 1;

            var LeadId = "WRM/" + "LD" + "/" + gen;

            lvm.leadGeneration.LeadId = LeadId;

         

Monday, June 19, 2023

How to Remove Duplicate Words from String

   //Code for remove duplicate from string

                string temp = "";

                finalgrp.Split(',').Distinct().ToList().ForEach(k => temp += k + ",");

                finalgrp = temp.Trim(',');

How to to select duplicate rows from sql server?

 SELECT * FROM Recruitment WHERE Email IN (SELECT Email FROM Recruitment GROUP BY Email HAVING COUNT(*) > 1); WITH CTE AS (     SELECT   ...