public static Staff CreateStaff(StaffType staffType)
        {
            switch (staffType)
            {
            case StaffType.teachingStaff:
                TeachingStaff teachingStaff = new TeachingStaff();
                AskCommonDetails(teachingStaff);
                teachingStaff.Subject       = InputStaffProperties.AskSubject();
                teachingStaff.AssignedClass = InputStaffProperties.AskClass();
                return(teachingStaff);

            case StaffType.administrativeStaff:
                AdminstrativeStaff adminStaff = new AdminstrativeStaff();
                AskCommonDetails(adminStaff);
                adminStaff.Post = InputStaffProperties.AskPost();
                return(adminStaff);

            case StaffType.supportStaff:
                SupportStaff supportStaff = new SupportStaff();
                AskCommonDetails(supportStaff);
                supportStaff.Post = InputStaffProperties.AskPost();
                return(supportStaff);

            default:
                return(null);
            }
        }
예제 #2
0
        public static Staff ReadAndCreateStaffFromType()
        {
            int   staffsType = ReadStaffType();
            Staff newStaff;

            switch (staffsType)
            {
            case (int)StaffType.teachingStaff:
                Console.WriteLine("\n-> Teaching Staff Selected\n");
                newStaff = new TeachingStaff();
                break;

            case (int)StaffType.administrativeStaff:
                Console.WriteLine("\n-> Administrative Staff Selected\n");
                newStaff = new AdministrativeStaff();
                break;

            case (int)StaffType.supportStaff:
                Console.WriteLine("\n-> Support Staff Selected\n");
                newStaff = new SupportStaff();
                break;

            default:
                Console.WriteLine("\n-> Invalid Staff Selected\n");
                return(null);
            }

            ReadOrUpdateStaffDetails(newStaff);
            return(newStaff);
        }
예제 #3
0
        public void RetrieveAllStaff()
        {
            string output = "";

            List <Staff> finalResult = new List <Staff>();

            // JsonFileOperation jfile = new JsonFileOperation();
            // jfile.RetrieveAllFromFile<SupportStaff>();
            // XmlFileOperation xfile = new XmlFileOperation();
            // xfile.RetrieveAllFromFile<TeachingStaff>();
            try
            {
                DatabaseOperation db = new DatabaseOperation();
                finalResult = db.RetriveAll((int)SType.TeachingStaff);

                foreach (var items in finalResult)
                {
                    TeachingStaff item = (TeachingStaff)items;
                    output = "EmpId : " + item.EmpId + " Name : " + item.Name + " Phone : " + item.Phone +
                             " Email : " + item.Email + " Dob : " + item.Dob + " Designation : " + item.Subject;
                    Console.WriteLine(output + "\n");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("\n List is empty \n");
            }
        }
예제 #4
0
        public void RetrieveSingleStaff()
        {
            string       name = "", output = "";
            List <Staff> finalResult = new List <Staff>();

            object[] result = new object[7];
            Console.WriteLine("Enter Details to Search :");

            Console.WriteLine("Enter Name :");

            name = InputName();
            // JsonFileOperation jfile = new JsonFileOperation();
            // jfile.RetrieveFromFile<TeachingStaff>(name);

            // XmlFileOperation xfile = new XmlFileOperation();`
            // xfile.RetrieveFromFile<TeachingStaff>(name);

            DatabaseOperation db = new DatabaseOperation();

            finalResult = db.SearchStaff(name, (int)SType.TeachingStaff);
            if (finalResult.Count > 0)
            {
                foreach (var items in finalResult)
                {
                    TeachingStaff item = (TeachingStaff)items;
                    output = "EmpId : " + item.EmpId + " Name : " + item.Name + " Phone : " + item.Phone +
                             " Email : " + item.Email + " Dob : " + item.Dob + " Designation : " + item.Subject;
                    Console.WriteLine(output + "\n");
                }
            }
            else
            {
                Console.WriteLine("\n List is empty \n");
            }
        }
예제 #5
0
        public void DeleteStaff()
        {
            string        id;
            TeachingStaff result = new TeachingStaff();

            RetrieveAllStaff();
            Console.WriteLine("\nEnter Details to Delete :");

            Console.WriteLine("Enter EmpId:");
            id = Console.ReadLine();
            // JsonFileOperation jfile = new JsonFileOperation();
            // jfile.DeleteFromFile<TeachingStaff>(id);
            // XmlFileOperation xfile = new XmlFileOperation();
            // xfile.DeleteFromFile<TeachingStaff>(id);
            DatabaseOperation dbr = new DatabaseOperation();

            result = (TeachingStaff)dbr.GetSingleStaff(id, (int)SType.TeachingStaff);
            if (result != null)
            {
                DatabaseOperation db = new DatabaseOperation();
                db.DeleteStaff((int)SType.TeachingStaff, id);
                Console.WriteLine("\nDeletion Successfull");
            }
            else
            {
                Console.WriteLine("\nStaff Not Found!!");
            }
        }
        /// <summary>
        /// Method to add TeachingStaff - SS
        /// </summary>
        /// <param name="name">name of TeachingStaff</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> AddTeachingStaffAsync(AddTeachingStaffManagementAc addTeachingStaff, int instituteId)
        {
            if (!await _iMSDbContext.TeachingStaffs.AnyAsync(x => x.InstituteId == instituteId && x.Code.ToLowerInvariant() == addTeachingStaff.Code.ToLowerInvariant()))
            {
                var TeachingStaff = new TeachingStaff()
                {
                    CreatedOn   = DateTime.UtcNow,
                    InstituteId = instituteId,
                    Name        = addTeachingStaff.Name,
                    Code        = addTeachingStaff.Code,
                    Description = addTeachingStaff.Description,
                    Status      = true
                };
                _iMSDbContext.TeachingStaffs.Add(TeachingStaff);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Teaching staff added successfully"
                });
            }
            else
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Teaching staff with the same name is already exist"
                       }
            };
        }
예제 #7
0
        private Staff _GetStaffFromData(SqlDataReader dataReader)
        {
            Staff staff = null;

            //Creating Specific Staff and reading specific Fields
            switch ((int)dataReader["StaffTypeID"])
            {
            case (int)StaffType.teachingStaff:
                staff = new TeachingStaff();
                ((TeachingStaff)staff).SubjectName = dataReader["SubjectName"].ToString().Trim();
                break;

            case (int)StaffType.administrativeStaff:
                staff = new AdministrativeStaff();
                ((AdministrativeStaff)staff).Position = dataReader["Position"].ToString().Trim();
                break;

            case (int)StaffType.supportStaff:
                staff = new SupportStaff();
                ((SupportStaff)staff).Role = dataReader["Role"].ToString().Trim();
                break;
            }

            //Common Fields
            if (staff != null)
            {
                staff.Id   = (int)dataReader["StaffID"];
                staff.Name = dataReader["Name"].ToString().Trim();
            }

            return(staff);
        }
예제 #8
0
        public List <TeachingStaff> getTeachingstaff(List <TeachingStaff> teaching)
        {
            TeachingStaff t = new TeachingStaff();

            List <TeachingStaff> p = t.GetAllTeachingStaffDetails(teaching);

            return(p);
        }
예제 #9
0
        // function to insert data into user defined table type
        public void AddStaffToType(List <Staff> StaffList)
        {
            DataTable DT = new DataTable();

            DT.Columns.Add(new DataColumn("Name", typeof(string)));
            DT.Columns.Add(new DataColumn("Code", typeof(string)));
            DT.Columns.Add(new DataColumn("Type", typeof(string)));
            DT.Columns.Add(new DataColumn("PhoneNumber", typeof(string)));
            DT.Columns.Add(new DataColumn("DateOfJoin", typeof(DateTime)));
            DT.Columns.Add(new DataColumn("Subject", typeof(string)));
            DT.Columns.Add(new DataColumn("Role", typeof(string)));
            DT.Columns.Add(new DataColumn("Department", typeof(string)));

            foreach (var staff in StaffList)
            {
                DataRow DR = DT.NewRow();

                DR["Name"] = staff.Name;

                DR["Code"] = staff.EmpCode;

                DR["Type"] = staff.StaffType.ToString();

                DR["PhoneNumber"] = staff.ContactNumber;

                DR["DateOfJoin"] = staff.DateOfJoin;

                if (StaffTypes.Teaching == staff.StaffType)
                {
                    TeachingStaff teachingStaff = (TeachingStaff)staff;
                    DR["Subject"] = teachingStaff.Subject;
                }
                else if (StaffTypes.Administrative == staff.StaffType)
                {
                    AdministrativeStaff adminStaff = (AdministrativeStaff)staff;
                    DR["Role"] = adminStaff.Role;
                }
                else if (StaffTypes.Support == staff.StaffType)
                {
                    SupportStaff supportStaff = (SupportStaff)staff;
                    DR["Department"] = supportStaff.Department;
                }

                DT.Rows.Add(DR);
            }
            InsertStaffs(DT); //calling datatable method here
        }
예제 #10
0
        // function to update staff info
        public void UpdateStaff <T>(T obj) where T : Staff
        {
            using (SqlConnection con = new SqlConnection(ConnString))
            {
                using (SqlCommand cmd = new SqlCommand("SPUpdateStaff", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", obj.Id);
                    cmd.Parameters.AddWithValue("@Name", obj.Name);
                    cmd.Parameters.AddWithValue("@Code", obj.EmpCode);
                    cmd.Parameters.AddWithValue("@Type", obj.StaffType.ToString());
                    cmd.Parameters.AddWithValue("@PhoneNumber", obj.ContactNumber);
                    cmd.Parameters.AddWithValue("@DateOfJoin", obj.DateOfJoin);

                    if (obj is TeachingStaff)
                    {
                        TeachingStaff staff = (TeachingStaff)Convert.ChangeType(obj, obj.GetType());
                        cmd.Parameters.AddWithValue("@Subject", staff.Subject);
                        cmd.Parameters.AddWithValue("@Role", "");
                        cmd.Parameters.AddWithValue("@Department", "");
                    }
                    else if (obj is AdministrativeStaff)
                    {
                        AdministrativeStaff staff = (AdministrativeStaff)Convert.ChangeType(obj, obj.GetType());
                        cmd.Parameters.AddWithValue("@Role", staff.Role);
                        cmd.Parameters.AddWithValue("@Department", "");
                        cmd.Parameters.AddWithValue("@Subject", "");
                    }
                    else
                    {
                        SupportStaff staff = (SupportStaff)Convert.ChangeType(obj, obj.GetType());
                        cmd.Parameters.AddWithValue("@Department", staff.Department);
                        cmd.Parameters.AddWithValue("@Subject", "");
                        cmd.Parameters.AddWithValue("@Role", "");
                    }
                    con.Open();
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException sqlExc)
                    {
                    }
                }
            }
        }
예제 #11
0
        public IActionResult Post([FromBody] Object staff)
        {
            bool isExist = false;

            var jsonString = staff.ToString();
            //var temp = (int)JObject.Parse(jsonString)["StaffType"];
            //StaffTypes type = (StaffTypes)temp;
            string     temp = (string)JObject.Parse(jsonString)["StaffType"];
            StaffTypes type = (StaffTypes)Enum.Parse(typeof(StaffTypes), temp, true);

            List <Staff> StaffList = new List <Staff>();

            if (type == StaffTypes.Teaching)
            {
                TeachingStaff obj = JsonConvert.DeserializeObject <TeachingStaff>(jsonString);
                StaffList.Add(obj);
            }
            if (type == StaffTypes.Administrative)
            {
                AdministrativeStaff obj = JsonConvert.DeserializeObject <AdministrativeStaff>(jsonString);
                StaffList.Add(obj);
            }
            if (type == StaffTypes.Support)
            {
                SupportStaff obj = JsonConvert.DeserializeObject <SupportStaff>(jsonString);
                StaffList.Add(obj);
            }
            DataBaseManager dataBaseManager = new DataBaseManager();

            try {
                isExist = dataBaseManager.CheckCodeExistence(StaffList[0].EmpCode);
                if (isExist)
                {
                    return(StatusCode(400));
                }
                else
                {
                    dataBaseManager.AddStaffToType(StaffList);
                    return(StatusCode(201));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }
        }
예제 #12
0
        public List <Staff> Populate(SqlDataReader sqlDataReader, int StaffType)
        {
            List <Staff> staffList = new List <Staff>();

            while (sqlDataReader.Read())
            {
                if ((int)sqlDataReader.GetValue(9) == 0)
                {
                    AdministrativeStaff administrative = new AdministrativeStaff();
                    administrative.EmpId       = sqlDataReader.GetValue(0).ToString();
                    administrative.Name        = sqlDataReader.GetValue(1).ToString();
                    administrative.Phone       = sqlDataReader.GetValue(2).ToString();
                    administrative.Email       = sqlDataReader.GetValue(3).ToString();
                    administrative.Dob         = (DateTime)sqlDataReader.GetValue(4);
                    administrative.StaffType   = (SType)sqlDataReader.GetValue(8);
                    administrative.Designation = sqlDataReader.GetValue(5).ToString();
                    staffList.Add(administrative);
                }
                else if ((int)sqlDataReader.GetValue(9) == 1)
                {
                    TeachingStaff teaching = new TeachingStaff();
                    teaching.EmpId     = sqlDataReader.GetValue(0).ToString();
                    teaching.Name      = sqlDataReader.GetValue(1).ToString();
                    teaching.Phone     = sqlDataReader.GetValue(2).ToString();
                    teaching.Email     = sqlDataReader.GetValue(3).ToString();
                    teaching.Dob       = (DateTime)sqlDataReader.GetValue(4);
                    teaching.StaffType = (SType)sqlDataReader.GetValue(8);
                    teaching.Subject   = sqlDataReader.GetValue(6).ToString();
                    staffList.Add(teaching);
                }
                else if ((int)sqlDataReader.GetValue(9) == 2)
                {
                    SupportStaff support = new SupportStaff();
                    support.EmpId      = sqlDataReader.GetValue(0).ToString();
                    support.Name       = sqlDataReader.GetValue(1).ToString();
                    support.Phone      = sqlDataReader.GetValue(2).ToString();
                    support.Email      = sqlDataReader.GetValue(3).ToString();
                    support.Dob        = (DateTime)sqlDataReader.GetValue(4);
                    support.StaffType  = (SType)sqlDataReader.GetValue(8);
                    support.Department = sqlDataReader.GetValue(7).ToString();
                    staffList.Add(support);
                }
            }
            return(staffList);
        }
예제 #13
0
        public void EditStaff()
        {
            string id;

            RetrieveAllStaff();
            Console.WriteLine("Enter details of staff to be edited:");
            Console.WriteLine("Enter EmpId :");
            id = Console.ReadLine();

            TeachingStaff teaching = new TeachingStaff();

            try
            {
                DatabaseOperation db = new DatabaseOperation();
                teaching = (TeachingStaff)db.GetSingleStaff(id, (int)SType.TeachingStaff);

                // JsonFileOperation jfile = new JsonFileOperation();
                // teaching = (TeachingStaff)jfile.GetObj<TeachingStaff>(id, teaching);
                // XmlFileOperation xfile = new XmlFileOperation();
                // teaching = (TeachingStaff)xfile.GetObj<TeachingStaff>(id, teaching);


                if (teaching.Name == null)
                {
                    Console.WriteLine("\nStaff Not Found!!");
                }
                else
                {
                    TeachingStaff teachingEdit = new TeachingStaff();
                    teachingEdit.StaffType = SType.TeachingStaff;
                    teachingEdit.EmpId     = teaching.EmpId;
                    teachingEdit.Name      = teaching.Name;
                    teachingEdit.Phone     = teaching.Phone;
                    teachingEdit.Dob       = teaching.Dob;
                    teachingEdit.Email     = teaching.Email;
                    teachingEdit.Subject   = teaching.Subject;
                    EditHelp(id, teaching, teachingEdit);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\nStaff Not Found!!");
            }
        }
예제 #14
0
        // function to populate objects from the result
        public static List <Staff> PopulateStaff(SqlDataReader reader)
        {
            int          id;
            string       name, code, number, subject, role, department;
            StaffTypes   emptType;
            DateTime     dateOfJoin;
            DataTable    dt        = new DataTable();
            List <Staff> StaffList = new List <Staff>();

            while (reader.HasRows)
            {
                while (reader.Read())
                {
                    var temp = (StaffTypes)Enum.Parse(typeof(StaffTypes), reader["type"].ToString());
                    name       = reader["Name"].ToString();
                    code       = reader["Code"].ToString();
                    id         = (int)reader["Id"];
                    emptType   = temp;
                    number     = reader["PhoneNumber"].ToString();
                    dateOfJoin = (DateTime)reader["DateOfJoin"];

                    if (StaffTypes.Teaching == temp)
                    {
                        subject = reader["Subject"].ToString();
                        TeachingStaff obj = new TeachingStaff(name, code, emptType, subject, number, dateOfJoin, id);
                        StaffList.Add(obj);
                    }
                    else if (StaffTypes.Administrative == temp)
                    {
                        role = reader["Role"].ToString();
                        AdministrativeStaff obj = new AdministrativeStaff(name, code, emptType, role, number, dateOfJoin, id);
                        StaffList.Add(obj);
                    }
                    else if (StaffTypes.Support == temp)
                    {
                        department = reader["Department"].ToString();
                        SupportStaff obj = new SupportStaff(name, code, emptType, department, number, dateOfJoin, id);
                        StaffList.Add(obj);
                    }
                }
                reader.NextResult();
            }
            return(StaffList);
        }
예제 #15
0
        public static List <Staff> PopulateList(List <Staff> StaffList)
        {
            int          id;
            string       name, code, number, subject, role, department;
            StaffTypes   emptType;
            DateTime     dateOfJoin;
            List <Staff> staffs = new List <Staff>();

            foreach (var staff in StaffList)
            {
                id         = staff.Id;
                name       = staff.Name;
                code       = staff.EmpCode;
                number     = staff.ContactNumber;
                emptType   = staff.StaffType;
                dateOfJoin = staff.DateOfJoin;

                if (StaffTypes.Teaching == emptType)
                {
                    TeachingStaff teachingStaff = (TeachingStaff)staff;
                    subject = teachingStaff.Subject;
                    TeachingStaff obj = new TeachingStaff(name, code, emptType, subject, number, dateOfJoin, id);
                    staffs.Add(obj);
                }
                else if (StaffTypes.Administrative == emptType)
                {
                    AdministrativeStaff administrativeStaff = (AdministrativeStaff)staff;
                    role = administrativeStaff.Role;
                    AdministrativeStaff obj = new AdministrativeStaff(name, code, emptType, role, number, dateOfJoin, id);
                    staffs.Add(obj);
                }
                else if (StaffTypes.Support == emptType)
                {
                    SupportStaff supportStaff = (SupportStaff)staff;
                    department = supportStaff.Department;
                    SupportStaff obj = new SupportStaff(name, code, emptType, department, number, dateOfJoin, id);
                    staffs.Add(obj);
                }
            }
            return(StaffList);
        }
예제 #16
0
        public void ViewStaffInfo(Staff staff)
        {
            switch (staffTypeChoice)
            {
            case 1:
                TeachingStaff teachingStaff = (TeachingStaff)staff;
                Console.WriteLine("\n\nID: {0},  Name: {1},  Code: {2}, Type: {3},  Subject: {4},   Contact Number: {5},   Joining Date: {6}", teachingStaff.Id, teachingStaff.Name, teachingStaff.EmpCode, teachingStaff.StaffType, teachingStaff.Subject, teachingStaff.ContactNumber, teachingStaff.DateOfJoin);
                break;

            case 2:
                AdministrativeStaff administrativeStaff = (AdministrativeStaff)staff;
                Console.WriteLine("\n\nID: {0},   Name: {1},  Code:{2}, Type: {3},  Role: {4},   Contact Number: {5},   Joining Date: {6}", administrativeStaff.Id, administrativeStaff.Name, administrativeStaff.EmpCode, administrativeStaff.StaffType, administrativeStaff.Role, administrativeStaff.ContactNumber, administrativeStaff.DateOfJoin);
                break;

            case 3:
                SupportStaff supportStaff = (SupportStaff)staff;
                Console.WriteLine("\n\nID: {0},   Name: {1},  Code:{2},  Type: {3},  Department: {4},   Contact Number: {5},   Joining Date: {6}", supportStaff.Id, supportStaff.Name, supportStaff.EmpCode, supportStaff.StaffType, supportStaff.Department, supportStaff.ContactNumber, supportStaff.DateOfJoin);
                break;

            default: return;
            }
        }
예제 #17
0
        public IActionResult Put(int id, [FromBody] Object staff)
        {
            var jsonString = staff.ToString();
            //var temp = (int)JObject.Parse(jsonString)["StaffType"];
            //StaffTypes type = (StaffTypes)temp;
            string          temp            = (string)JObject.Parse(jsonString)["StaffType"];
            StaffTypes      type            = (StaffTypes)Enum.Parse(typeof(StaffTypes), temp, true);
            DataBaseManager dataBaseManager = new DataBaseManager();

            try
            {
                if (type == StaffTypes.Teaching)
                {
                    TeachingStaff obj = JsonConvert.DeserializeObject <TeachingStaff>(jsonString);
                    dataBaseManager.UpdateStaff(obj);
                    return(StatusCode(200));
                }
                if (type == StaffTypes.Administrative)
                {
                    AdministrativeStaff obj = JsonConvert.DeserializeObject <AdministrativeStaff>(jsonString);
                    dataBaseManager.UpdateStaff(obj);
                    return(StatusCode(200));
                }
                if (type == StaffTypes.Support)
                {
                    SupportStaff obj = JsonConvert.DeserializeObject <SupportStaff>(jsonString);
                    dataBaseManager.UpdateStaff(obj);
                    return(StatusCode(200));
                }

                return(NotFound());
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }
        }
예제 #18
0
        public static void ViewDetails(Staff staff)
        {
            switch (staff.StaffType)
            {
            case StaffType.teachingStaff:
                TeachingStaff teachingStaff = (TeachingStaff)staff;
                ViewCommonDetails(teachingStaff);
                Console.WriteLine("\nSubject : {0}", teachingStaff.Subject);
                Console.WriteLine("Class Assigned: {0}", teachingStaff.AssignedClass);
                break;

            case StaffType.administrativeStaff:
                AdminstrativeStaff adminStaff = (AdminstrativeStaff)staff;
                ViewCommonDetails(adminStaff);
                Console.WriteLine("\nPost : {0}", adminStaff.Post);
                break;

            case StaffType.supportStaff:
                SupportStaff supportStaff = (SupportStaff)staff;
                ViewCommonDetails(supportStaff);
                Console.WriteLine("\nPost : {0}", supportStaff.Post);
                break;
            }
        }
예제 #19
0
        public void EditHelp(string id, TeachingStaff teaching, TeachingStaff teachingEdit)
        {
            int    option;
            bool   valid = false;
            string name = "", phone = "", email = "", subject = "", date = "";

            string[] Options;
            int      Select, Count = 0;

            Console.WriteLine("Edit Details of Staff :" + teaching.Name);
            do
            {
                Console.WriteLine("Select Values (1/2/3/4/5/6) :\n1.Edit Name\n2.Edit Phone\n3.Edit Dob\n4.Edit Email\n5.Edit Subject\n6.Exit");
                option = Convert.ToInt32(Console.ReadLine());
                switch (option)
                {
                case 1:
                    Console.WriteLine("Enter Name :");
                    name = Console.ReadLine();
                    teachingEdit.Name = name;
                    valid             = Validation(teachingEdit);
                    if (valid)
                    {
                        Console.WriteLine("Name :" + teachingEdit.Name);
                    }

                    break;

                case 2:
                    Console.WriteLine("Enter Phone No:");
                    phone = Console.ReadLine();
                    teachingEdit.Phone = phone;
                    valid = Validation(teachingEdit);
                    if (valid)
                    {
                        Console.WriteLine("Phone :" + teachingEdit.Phone);
                    }

                    break;

                case 3:
                    Console.WriteLine("Enter date of birth");

                    date = InputDob();
                    if (!String.IsNullOrEmpty(date))
                    {
                        teachingEdit.Dob = Convert.ToDateTime(date);
                    }
                    valid = Validation(teachingEdit);
                    if (valid)
                    {
                        Console.WriteLine("Date of birth :" + teaching.Dob);
                    }

                    break;

                case 4:
                    Console.WriteLine("Enter Email");
                    email = Console.ReadLine();
                    teachingEdit.Email = email;
                    valid = Validation(teachingEdit);
                    if (valid)
                    {
                        Console.WriteLine(" Email :" + teachingEdit.Email);
                    }

                    break;

                case 5:
                    Options = ConfigList("Subject");
                    Console.WriteLine("Enter Subject");
                    do
                    {
                        Console.WriteLine("\nSelect any one option(0 to exit)");

                        foreach (var val in Options)
                        {
                            Console.WriteLine(++Count + " :" + val);
                        }
                        Count = 0;

                        int.TryParse(Console.ReadLine(), out Select);
                        if (Select == 0)
                        {
                            break;
                        }
                        subject = Options[Select - 1];
                        break;
                    }while (Select != 0);
                    teachingEdit.Subject = subject;
                    valid = Validation(teachingEdit);
                    if (valid)
                    {
                        Console.WriteLine("Subject :" + teachingEdit.Subject);
                    }

                    break;

                case 6:
                    valid = Validation(teachingEdit);
                    if (!valid)
                    {
                        Console.WriteLine("Values Not Edited");
                        return;
                    }
                    else if (teaching == teachingEdit)
                    {
                        return;
                    }
                    else
                    {
                        // JsonFileOperation jfile = new JsonFileOperation();
                        // jfile.UpdateFile<TeachingStaff>(id, teachingEdit);
                        // XmlFileOperation xfile = new XmlFileOperation();
                        // xfile.UpdateFile<TeachingStaff>(id, teachingEdit);
                        DatabaseOperation db = new DatabaseOperation();
                        db.UpdateStaff(teachingEdit.EmpId, teachingEdit.Name, teachingEdit.Phone, teachingEdit.Email, teachingEdit.Dob, (int)teachingEdit.StaffType, teachingEdit.Subject);
                        Console.WriteLine("Edit Successfull");
                        return;
                    }

                default:
                    Console.WriteLine("Invalid Input!!");
                    break;
                }
            }while (option != 6);
        }
예제 #20
0
        public void AddStaff()
        {
            string bulkOrNot = "n";

            do
            {
                string        subject = "";
                int           Count = 0, Select, id = 0;
                bool          valid = false;
                object[]      opt   = new object[5];
                string[]      Options;
                TeachingStaff teaching = new TeachingStaff();
                do
                {
                    opt     = EnterValues();
                    Options = ConfigList("Subject");
                    Console.WriteLine("Enter Subject :");
                    do
                    {
                        Console.WriteLine("\nSelect any one option(0 to exit)");

                        foreach (var val in Options)
                        {
                            Console.WriteLine(++Count + " :" + val);
                        }
                        Count = 0;

                        int.TryParse(Console.ReadLine(), out Select);
                        if (Select == 0)
                        {
                            break;
                        }
                        subject = Options[Select - 1];
                        break;
                    }while (Select != 0);
                    teaching.StaffType = SType.TeachingStaff;
                    teaching.EmpId     = opt[4].ToString();
                    teaching.Name      = opt[0].ToString();
                    teaching.Phone     = opt[1].ToString();
                    if (!String.IsNullOrEmpty(opt[2].ToString()))
                    {
                        teaching.Dob = Convert.ToDateTime(opt[2]);
                    }
                    teaching.Email   = opt[3].ToString();
                    teaching.Subject = subject;
                    valid            = Validation(teaching);
                    if (!valid)
                    {
                        Console.WriteLine("\nDo you want to correct entered values ??(yes-1/No-0)");
                        id = InputOption();
                        if (id == 1)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                }while (!valid);

                if (valid)
                {
                    teachingList.Add(teaching);
                    // JsonFileOperation jfile = new JsonFileOperation();
                    // jfile.AddToFile<TeachingStaff>(teaching);
                    // XmlFileOperation xfile = new XmlFileOperation();
                    // xfile.AddToFile<TeachingStaff>(teaching);

                    DatabaseOperation db = new DatabaseOperation();
                    db.AddBulkData(teaching.EmpId, teaching.Name, teaching.Phone, teaching.Email, teaching.Dob, (int)teaching.StaffType, teaching.Subject);

                    // Console.WriteLine("\nValues added are :\n");
                    //Console.WriteLine("\nName: " + teaching.Name + " " + "DOB: " + teaching.Dob + " " + "Phone :" + teaching.Phone + " " + "Email :" + teaching.Email + " Subject: " + teaching.Subject);
                }
                Console.WriteLine("Add data again : (y/n)\n");
                bulkOrNot = Console.ReadLine();
                if (bulkOrNot.Equals("n"))
                {
                    DatabaseOperation database = new DatabaseOperation();
                    database.ExecuteBulkProc();
                    break;
                }
            }while (bulkOrNot.Equals("y"));
        }
예제 #21
0
        // function for update staff details
        public void UpdateStaff()
        {
            DataBaseManager dataBaseManager = new DataBaseManager();

            DateTime dateInput;
            bool     succeed;
            string   input;
            string   subject = System.Configuration.ConfigurationManager.AppSettings["subjects"];

            string[] subjects = subject.Split(',');
            int      index = 1, choice;

            Console.WriteLine($"\n\n----------------------- Update Staff -----------------------\n");
            //Console.WriteLine("\nEnter Emp code of the staff that you want to update");
            //string code = Console.ReadLine();
            //code = code.ToUpper();
            id = getStaffId();

            List <Staff> filteredList = new List <Staff>();

            filteredList = dataBaseManager.FetchStaffInfo(id);
            if (filteredList.Exists(x => x.Id == id))
            {
                foreach (var staff in filteredList)
                {
                    if (staff.Id == id)
                    {
                        //ViewStaffInfo(staff);
                        do
                        {
                            succeed = false;
                            try
                            {
                                Console.WriteLine($"Enter Name ({staff.Name})");
                                input = Console.ReadLine();
                                if (string.IsNullOrEmpty(input))
                                {
                                    name = staff.Name;
                                }
                                else
                                {
                                    name = input;
                                    Validator.ValidateName(name);
                                }
                                succeed    = true;
                                staff.Name = name;
                                Console.WriteLine("Name updated succesfully");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        } while (succeed == false);

                        do
                        {
                            succeed = false;
                            try
                            {
                                Console.WriteLine($"\nEnter Contact Number ({staff.ContactNumber})");
                                input = Console.ReadLine();
                                if (string.IsNullOrEmpty(input))
                                {
                                    number = staff.ContactNumber;
                                }
                                else
                                {
                                    number = input;
                                    Validator.ValidatePhoneNumber(number);
                                }
                                succeed             = true;
                                staff.ContactNumber = number;
                                Console.WriteLine("Contact Number updated succesfully");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        } while (succeed == false);


                        do
                        {
                            succeed = false;
                            try
                            {
                                Console.WriteLine($"\nEnter Date of Join ({staff.DateOfJoin}) (dd-mm-yyyy) ");
                                if (!(DateTime.TryParse(Console.ReadLine(), out dateInput)))
                                {
                                    doj = staff.DateOfJoin;
                                }
                                else
                                {
                                    doj = dateInput;
                                    Validator.ValidateDate(doj);
                                }

                                succeed          = true;
                                staff.DateOfJoin = doj;
                                Console.WriteLine("Date of Join updated succesfully");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        } while (succeed == false);

                        string staffType = staff.StaffType.ToString();
                        switch (staffType)
                        {
                        case "Teaching":
                            TeachingStaff teachingStaff = (TeachingStaff)staff;
                            do
                            {
                                succeed = false;
                                index   = 1;
                                try
                                {
                                    Console.WriteLine($"\nSelect language from choice ({teachingStaff.Subject})");
                                    foreach (string item in subjects)
                                    {
                                        Console.WriteLine($"{index}. {item}");
                                        index++;
                                    }
                                    if (!Int32.TryParse(Console.ReadLine(), out choice))
                                    {
                                        succeed = false;
                                        Console.WriteLine("Enter a valid choice");
                                    }
                                    else
                                    {
                                        if (choice <= subjects.Length && choice > 0)
                                        {
                                            subj    = subjects[choice - 1];
                                            succeed = true;
                                            teachingStaff.Subject = subj;
                                        }
                                        else
                                        {
                                            Console.WriteLine("Enter a valid choice");
                                            succeed = false;
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            } while (succeed == false);
                            dataBaseManager.UpdateStaff <TeachingStaff>(teachingStaff);
                            break;

                        case "Administrative":
                            AdministrativeStaff administrativeStaff = (AdministrativeStaff)staff;
                            do
                            {
                                succeed = false;
                                try
                                {
                                    Console.WriteLine($"\nEnter Role ({administrativeStaff.Role}) ");
                                    input = Console.ReadLine();
                                    if (string.IsNullOrEmpty(input))
                                    {
                                        role = administrativeStaff.Role;
                                    }
                                    else
                                    {
                                        role = input;
                                        Validator.ValidateRole(role);
                                    }
                                    succeed = true;
                                    administrativeStaff.Role = role;
                                    Console.WriteLine("Role updated succesfully");
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            } while (succeed == false);
                            dataBaseManager.UpdateStaff <AdministrativeStaff>(administrativeStaff);
                            break;

                        case "Support":
                            SupportStaff supportStaff = (SupportStaff)staff;
                            do
                            {
                                succeed = false;
                                try
                                {
                                    Console.WriteLine($"\nEnter Department ({supportStaff.Department}) ");
                                    input = Console.ReadLine();
                                    if (string.IsNullOrEmpty(input))
                                    {
                                        department = supportStaff.Department;
                                    }
                                    else
                                    {
                                        department = input;
                                        Validator.ValidateDepartment(department);
                                    }
                                    succeed = true;
                                    supportStaff.Department = department;
                                    Console.WriteLine("Role updated succesfully");
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                }
                            } while (succeed == false);
                            dataBaseManager.UpdateStaff <SupportStaff>(supportStaff);
                            break;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("\nStaff Not Found");
                return;
            }
        }
예제 #22
0
        // function for add staff
        public void AddStaff()
        {
            List <Staff> StaffList = new List <Staff>();
            string       subject   = System.Configuration.ConfigurationManager.AppSettings["subjects"];

            string[] subjects = subject.Split(',');
            bool     succeed, flag = false, isCodeExist = false;
            int      index = 1, choice;
            string   addMoreChoice;

            DataBaseManager dbManager = new DataBaseManager();

            do
            {
                staffTypeChoice = GetStaffType();
                var empType = (StaffTypes)staffTypeChoice;
                if (staffTypeChoice == counter)
                {
                    return;
                }

                Console.WriteLine($"\n\n----------------------- {empType} Staff -----------------------\n");
                do
                {
                    succeed = false;
                    try
                    {
                        Console.WriteLine("\nEnter Name: ");
                        name = Console.ReadLine();
                        Validator.ValidateName(name);
                        succeed = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                } while (succeed == false);

                do
                {
                    succeed = false;
                    Console.WriteLine("\nEnter Employee code :");
                    code        = Console.ReadLine();
                    code        = code.ToUpper();
                    isCodeExist = dbManager.CheckCodeExistence(code);
                    if (isCodeExist || StaffList.Exists(x => x.EmpCode == code))
                    {
                        Console.WriteLine("\nEmp code already exists");
                        succeed = false;
                    }
                    else
                    {
                        succeed = true;
                    }
                } while (succeed == false);


                do
                {
                    succeed = false;
                    try
                    {
                        Console.WriteLine("\nEnter Contact Number");
                        number = Console.ReadLine();
                        Validator.ValidatePhoneNumber(number);
                        succeed = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                } while (succeed == false);

                do
                {
                    succeed = false;
                    try
                    {
                        Console.WriteLine("\nEnter Date of Join (dd-mm-yyyy)");
                        doj = DateTime.Parse(Console.ReadLine());
                        Validator.ValidateDate(doj);
                        succeed = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                } while (succeed == false);


                switch (staffTypeChoice)
                {
                case 1:
                    do
                    {
                        succeed = false;
                        index   = 1;
                        try
                        {
                            Console.WriteLine("\nSelect your choice");
                            foreach (string item in subjects)
                            {
                                Console.WriteLine($"{index}. {item}");
                                index++;
                            }
                            if (!Int32.TryParse(Console.ReadLine(), out choice))
                            {
                                succeed = false;
                                Console.WriteLine("Enter a valid choice");
                            }
                            else
                            {
                                if (choice <= subjects.Length && choice > 0)
                                {
                                    subj    = subjects[choice - 1];
                                    succeed = true;
                                }
                                else
                                {
                                    Console.WriteLine("Enter a valid choice");
                                    succeed = false;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    } while (succeed == false);

                    TeachingStaff teachingStaff = new TeachingStaff(name, code, empType, subj, number, doj);
                    StaffList.Add(teachingStaff);
                    //dbManager.AddStaff<TeachingStaff>(teachingStaff);
                    break;

                case 2:
                    do
                    {
                        succeed = false;
                        try
                        {
                            Console.WriteLine("\nEnter Role");
                            role    = Console.ReadLine();
                            succeed = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    } while (succeed == false);
                    AdministrativeStaff administrativeStaff = new AdministrativeStaff(name, code, empType, role, number, doj);
                    StaffList.Add(administrativeStaff);
                    //dbManager.AddStaff<AdministrativeStaff>(administrativeStaff);
                    break;

                case 3:
                    do
                    {
                        succeed = false;
                        try
                        {
                            Console.WriteLine("\nEnter Department");
                            department = Console.ReadLine();
                            succeed    = true;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    } while (succeed == false);
                    SupportStaff supportStaff = new SupportStaff(name, code, empType, department, number, doj);
                    StaffList.Add(supportStaff);
                    //dbManager.AddStaff<SupportStaff>(supportStaff);
                    break;

                case 4:
                    // back to main menu
                    break;
                }
                Console.WriteLine("Do you want to add more ? (Y/N)");
                addMoreChoice = Console.ReadLine();
            } while (addMoreChoice == "y" || addMoreChoice == "Y");
            dbManager.AddStaffToType(StaffList);
        }
예제 #23
0
        public void InsertStaff(List <TeachingStaff> t, List <NonTeachingStaff> nt)
        {
            string category = GetCategory();

            if (category.Equals("Teaching"))
            {
                TeachingStaff staff = new TeachingStaff();

                List <Subjects> subb = GetSubjects();

                string n = getName();


                Address ad = getAddress();

                string tpe = GetStaffType();

                int sal = GetSalary();


                TeachingStaff t1 = new TeachingStaff()
                {
                    address = ad,
                    TeachingOrNonTeaching = category,
                    name   = n,
                    salary = sal,
                    sub    = subb,
                    type   = tpe
                };

                t.Add(t1);
            }



            else
            {
                NonTeachingStaff staff = new NonTeachingStaff();


                string n = getName();


                Address ad = getAddress();

                string tpe = GetStaffType();

                int sal = GetSalary();

                string d = GetDepartment();

                NonTeachingStaff ntt = new NonTeachingStaff()
                {
                    address = ad,
                    TeachingOrNonTeaching = category,
                    name   = n,
                    salary = sal,
                    dept   = d,
                    type   = tpe
                };

                nt.Add(ntt);
            }
        }