public List <AllocationEmployeeLeave> TotalCasualLeave(int employeeId)
        {
            string query = @"select e.Id, a.LeaveTypeId, a.NumberOfLeave
from tb_Employee e
inner join tb_AllocationLeave a on e.DesignationId = a.DesignationId
where e.Id = '" + employeeId + "' and a.LeaveTypeId = '" + 2 + "'";

            try
            {
                SqlCommand com = new SqlCommand(query, con);
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                List <AllocationEmployeeLeave> totalLeave = new List <AllocationEmployeeLeave>();
                while (dr.Read())
                {
                    AllocationEmployeeLeave leave = new AllocationEmployeeLeave();
                    leave.Id            = (int)dr["Id"];
                    leave.NumberOfLeave = (int)dr["NumberOfLeave"];
                    totalLeave.Add(leave);
                }
                dr.Close();
                return(totalLeave.ToList());
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to connect Server", exception);
            }
            finally
            {
                con.Close();
            }
        }
 public bool IsLeaveAllocated(AllocationEmployeeLeave leaveTaken)
 {
     try
     {
         string     Query   = "SELECT * FROM tb_AllocationLeave WHERE (DesignationId = @DesignationId and LeaveTypeId = @LeaveTypeId)";
         SqlCommand Command = new SqlCommand(Query, con);
         con.Open();
         Command.Parameters.Clear();
         Command.Parameters.Add("DesignationId", SqlDbType.Int);
         Command.Parameters["DesignationId"].Value = leaveTaken.DesignationId;
         Command.Parameters.Add("LeaveTypeId", SqlDbType.Int);
         Command.Parameters["LeaveTypeId"].Value = leaveTaken.LeaveTypeId;
         SqlDataReader Reader = Command.ExecuteReader();
         Reader.Read();
         bool isExist = Reader.HasRows;
         Reader.Close();
         return(isExist);
     }
     catch (Exception exception)
     {
         throw new Exception("Unable to connect Server", exception);
     }
     finally
     {
         con.Close();
     }
 }
        public int AllocationLeave(AllocationEmployeeLeave leave)
        {
            string query = @"INSERT INTO [dbo].[tb_AllocationLeave]
           ([DesignationId]
           ,[LeaveTypeId]
           ,[NumberOfLeave])
     VALUES
           ('" + leave.DesignationId + "', '" + leave.LeaveTypeId + "', '" + leave.NumberOfLeave + "')";

            try
            {
                SqlCommand command = new SqlCommand(query, con);
                con.Open();
                int rowAffected = command.ExecuteNonQuery();
                return(rowAffected);
            }
            catch (Exception exception)
            {
                throw new Exception("Unable to connect Server", exception);
            }
            finally
            {
                con.Close();
            }
        }
Esempio n. 4
0
        public ActionResult AllocationLeave(AllocationEmployeeLeave allocation)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (adminManager.IsLeaveAllocated(allocation))
                    {
                        ViewBag.ShowMsg = "Leave allocated alrady.";
                    }
                    else
                    {
                        int message = adminManager.AllocationLeave(allocation);
                        if (message > 0)
                        {
                            ViewBag.ShowMsg = "Leave Allocation Saved Successfully!";
                        }
                        else
                        {
                            ViewBag.ShowMsg = "Opps! Data Not Saved! Try Again Please";
                        }
                    }
                }
                catch (Exception exception)
                {
                    ViewBag.ShowMsg = exception.Message;
                }
            }

            ViewBag.leavetype    = adminManager.GetLeaveTypes();
            ViewBag.designations = adminManager.GetDesignationList();

            return(View());
        }
        public int AllocationLeave(AllocationEmployeeLeave allocation)
        {
            int rowAffected = adminGateway.AllocationLeave(allocation);

            return(rowAffected);
        }
 public bool IsLeaveAllocated(AllocationEmployeeLeave leaveTaken)
 {
     return(adminGateway.IsLeaveAllocated(leaveTaken));
 }