public async Task <IActionResult> Edit(long id, [Bind("Id,CreatedDate,TotalDay,RemainDay,CreatedId,LeaveTypeId,EmployeeInfoId")] EmployeeLeaveInfo employeeLeaveInfo)
        {
            if (id != employeeLeaveInfo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //_context.Update(employeeLeaveInfo);
                    //await _context.SaveChangesAsync();
                    await employeeLeaveInfoRepository.Update(employeeLeaveInfo);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeLeaveInfoExists(employeeLeaveInfo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeInfoId"] = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "Id", employeeLeaveInfo.EmployeeInfoId);
            ViewData["LeaveTypeId"]    = new SelectList(leaveTypeRepository.GetLeaveTypeList(), "Id", "Id", employeeLeaveInfo.LeaveTypeId);
            return(View(employeeLeaveInfo));
        }
        public List <EmployeeLeaveInfo> ShowAllLeaveStatus()
        {
            const string query = @"SELECT e.Id,e.Reason, CONVERT(NVARCHAR,e.StartDate, 100) AS[StartDate],CONVERT(NVARCHAR,e.EndDate, 100) AS[EndDate],e.TotalDay, e.Status,CONVERT(NVARCHAR,e.EntryDate, 100) AS[EntryDate], a.EmployeeName,a.Email,p.LeaveTypeName
            FROM EmployeeLeaveRequest e
            INNER JOIN Employee a ON e.EmployeeId = a.Id
            INNER JOIN LeaveType p ON e.LeaveTypeId = p.Id";

            try
            {
                var command = new SqlCommand(query, Connection);
                Connection.Open();
                SqlDataReader reader            = command.ExecuteReader();
                var           employeeLeaveInfo = new List <EmployeeLeaveInfo>();
                int           serial            = 1;
                while (reader.Read())
                {
                    var employeeLeave = new EmployeeLeaveInfo
                    {
                        Id            = serial,
                        EmployeeName  = reader["EmployeeName"].ToString(),
                        Email         = reader["Email"].ToString(),
                        LeaveTypeName = reader["LeaveTypeName"].ToString(),
                        Reason        = reader["Reason"].ToString(),
                        StartDate     = reader["StartDate"].ToString(),
                        EndDate       = reader["EndDate"].ToString(),
                        TotalDay      = (int)reader["TotalDay"],
                        EntryDate     = reader["EntryDate"].ToString(),
                        Status        = reader["Status"].ToString()
                    };

                    employeeLeaveInfo.Add(employeeLeave);
                    serial++;
                }
                reader.Close();
                return(employeeLeaveInfo);
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to connect Server", exception);
            }
            finally
            {
                Connection.Close();
            }
        }
        public List <EmployeeLeaveInfo> ShowAllLeaveStatus()
        {
            string query = @"SELECT e.Id, CONVERT(NVARCHAR,e.StartDate, 100) AS[StartDate],CONVERT(NVARCHAR,e.EndDate, 100) AS[EndDate],e.TotalDay, e.Status,CONVERT(NVARCHAR,e.EntryDate, 100) AS[EntryDate], a.EmployeeName,a.Email,p.LeaveTypeName
FROM tb_EmployeeLeave e
INNER JOIN tb_Employee a ON e.EmployeeId = a.Id
INNER JOIN tb_LeaveType p ON e.LeaveTypeId = p.Id";

            try
            {
                SqlCommand command = new SqlCommand(query, con);
                con.Open();
                SqlDataReader            reader            = command.ExecuteReader();
                List <EmployeeLeaveInfo> employeeLeaveInfo = new List <EmployeeLeaveInfo>();
                int serial = 1;
                while (reader.Read())
                {
                    EmployeeLeaveInfo employeeLeave = new EmployeeLeaveInfo();

                    employeeLeave.Id            = serial;
                    employeeLeave.EmployeeName  = reader["EmployeeName"].ToString();
                    employeeLeave.Email         = reader["Email"].ToString();
                    employeeLeave.LeaveTypeName = reader["LeaveTypeName"].ToString();
                    employeeLeave.TotalDay      = (int)reader["TotalDay"];
                    employeeLeave.StartDate     = reader["StartDate"].ToString();
                    employeeLeave.EndDate       = reader["EndDate"].ToString();
                    employeeLeave.EntryDate     = reader["EntryDate"].ToString();
                    employeeLeave.Status        = reader["Status"].ToString();

                    employeeLeaveInfo.Add(employeeLeave);
                    serial++;
                }
                reader.Close();
                return(employeeLeaveInfo);
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to connect Server", exception);
            }
            finally
            {
                con.Close();
            }
        }
        public async Task <IActionResult> Create([Bind("Id,CreatedDate,TotalDay,RemainDay,CreatedId,LeaveTypeId,EmployeeInfoId")] EmployeeLeaveInfoViewModel employeeLeaveInfo)
        {
            if (ModelState.IsValid)
            {
                EmployeeLeaveInfo dd = new EmployeeLeaveInfo()
                {
                    CreatedDate    = employeeLeaveInfo.CreatedDate,
                    TotalDay       = employeeLeaveInfo.TotalDay,
                    RemainDay      = employeeLeaveInfo.RemainDay,
                    CreatedId      = employeeLeaveInfo.CreatedId,
                    EmployeeInfoId = employeeLeaveInfo.EmployeeInfoId,
                    LeaveTypeId    = employeeLeaveInfo.LeaveTypeId
                };
                //_context.Add(employeeLeaveInfo);
                //await _context.SaveChangesAsync();
                await employeeLeaveInfoRepository.Save(dd);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeInfoId"] = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "Id", employeeLeaveInfo.EmployeeInfoId);
            ViewData["LeaveTypeId"]    = new SelectList(leaveTypeRepository.GetLeaveTypeList(), "Id", "Id", employeeLeaveInfo.LeaveTypeId);
            return(View(employeeLeaveInfo));
        }
 public async Task Update(EmployeeLeaveInfo ot)
 {
     context.Update(ot);
     await context.SaveChangesAsync();
 }
 public async Task Save(EmployeeLeaveInfo ot)
 {
     context.Add(ot);
     await context.SaveChangesAsync();
 }
 public async Task Delete(EmployeeLeaveInfo ot)
 {
     context.Remove(ot);
     await context.SaveChangesAsync();
 }