एमवीसी का उपयोग करके प्राथमिक कुंजी फ़ील्ड में बटन (अगले पिछले पहले आखिरी) नेविगेशन बटन में कार्यक्षमता कैसे जोड़ें


==========समस्या==========

रिपॉजिटरी का उपयोग करके कार्रवाई बनाने के लिए नेक्स्ट प्रीवियस लास्ट फर्स्ट में फ़ंक्शन नहीं जोड़ा जा सकता

कर्मचारी आईडी फ़ील्ड पर आधारित पैटर्न

==========उदाहरण==========

कर्मचारी आईडी: 5 अंतिम रिकॉर्ड के रूप में

यदि क्रिएट एक्शन व्यू लोड हो जाता है तो उसे कर्मचारी आईडी के लिए अधिकतम+1 दिखाना होगा यानी यह 6 दिखाएगा
अगर नेक्स्ट बटन पर क्लिक करें तो 6 हो जाएंगे

यदि पिछला बटन 4 पर क्लिक करें और नाम, उम्र आदि से संबंधित अन्य डेटा प्राप्त करें…

यदि लास्ट बटन पर क्लिक करें तो 5 हो जाएं और नाम, उम्र आदि से संबंधित अन्य डेटा प्राप्त करें…

यदि फर्स्टबटन पर क्लिक करें तो 1 बन जाता है और नाम, उम्र आदि से संबंधित अन्य डेटा प्राप्त होता है…

======प्रयुक्त प्रौद्योगिकी============

मैं रिपॉजिटरी पैटर्न जेनेरिक का उपयोग करके विजुअल स्टूडियो 2017 एएसपीनेट कोर 2.1 एसक्यूएल सर्वर 2012 में काम करता हूं

मैंने क्या प्रयास किया है:

===========Employee Controller Have Create Action=====

public class EmployeesController : Controller
    {
        private readonly IEmployees _context;

        public EmployeesController(IEmployees context)
        {
            _context = context;
        }

        
        // GET: Employees/Create
        public IActionResult Create()
        {
How to call functions below
         //   var maxId =   maxid+1;
getNext()
getprevious()
getlast()
getfirst()
            return View();
        }
===============Generic Repository Pattern(required function I dont know======
 
 public class EFRepository<T> : IRepository<T> where T : class
    {
        protected TabDbContext _context { get; set; }
        public EFRepository(TabDbContext context)
        {
            _context = context;
        }
getNext(){
what implementation write
}
getprevious()
{
what implementation write
}
getlast()
{
what implementation write
}
getfirst()
{
what implementation write
}
public IQueryable<T> GetAll()
        {
            return _context.Set<T>();
        }

        public virtual async Task<ICollection<T>> GetAllAsyn()
        {

            return await _context.Set<T>().ToListAsync();
        }

        public virtual T Get(int id)
        {
            return _context.Set<T>().Find(id);
        }

        public virtual async Task<T> GetAsync(int id)
        {
            return await _context.Set<T>().FindAsync(id);
        }

       
        public virtual T Find(Expression<Func<T, bool>> match)
        {
            return _context.Set<T>().SingleOrDefault(match);
        }

        public virtual async Task<T> FindAsync(Expression<Func<T, bool>> match)
        {
            return await _context.Set<T>().SingleOrDefaultAsync(match);
        }

        public ICollection<T> FindAll(Expression<Func<T, bool>> match)
        {
            return _context.Set<T>().Where(match).ToList();
        }

        public async Task<ICollection<T>> FindAllAsync(Expression<Func<T, bool>> match)
        {
            return await _context.Set<T>().Where(match).ToListAsync();
        }

}
=====Buttons Navigation on Create View Of Employee Controller====
<div class="title_of_div">
    <button id="BtnFirst" style="display:inline">First</button>
    <button id="BtnNext" style="display:inline">Next</button>
    <button id="BtnPrevious" style="display: inline">Previous</button>
    <button id="BtnLast" style="display: inline">Last</button>
</div>
view create controlls
===========Create Action Get==========
 <form asp-action="Create">

            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="EmployeeId" class="control-label"></label>
                <input asp-for="EmployeeId" class="form-control" />
                <span asp-validation-for="EmployeeId" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="BranchCode" class="control-label"></label>
                <input asp-for="BranchCode" class="form-control" />
                <span asp-validation-for="BranchCode" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="EmployeeName" class="control-label"></label>
                <input asp-for="EmployeeName" class="form-control" />
                <span asp-validation-for="EmployeeName" class="text-danger"></span>
            </div>
            
        </form>
    </div>
</div>
============Model related data=============
public class Employee
    {
        [Key]
        public int EmployeeId { get; set; }
        public int BranchCode { get; set; }
        public string EmployeeName { get; set; }
   
    }

समाधान 1

1) “बनाएँ” के लिए किसी आईडी की आवश्यकता नहीं है; आईडी किसी भी पहचान के लिए ईएफ द्वारा निर्दिष्ट की गई है / [Key] फ़ील्ड/विशेषता.

2) अगला: ..कहाँ( e => e.Id > 5 ).Orderby( e => e.Id ).FirstOrDefault()

3) पिछला: ..कहाँ( e => e.Id < 5 ).Orderby( e => e.Id ).LastOrDefault()

4) पहला: ..ऑर्डरबी(ई => ई.आईडी ).फर्स्टऑर्डडिफॉल्ट()

5) अंतिम: ..Orderby( e => e.Id ).LastOrDefault()

コメント

タイトルとURLをコピーしました