/// <summary>
        /// Get active employee data
        /// </summary>
        /// <param name="EmpNo"></param>
        /// <returns></returns>
        public ActionResult CTS230_getActiveEmployee(string EmpNo)
        {
            SupportStaff SuppStaff = new SupportStaff();

            SuppStaff = getStaff(EmpNo, false);
            return(Json(SuppStaff.EmpFullName));
        }
Пример #2
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);
        }
Пример #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<SupportStaff>();
            try
            {
                DatabaseOperation db = new DatabaseOperation();
                finalResult = db.RetriveAll((int)SType.SupportStaff);

                foreach (var items in finalResult)
                {
                    SupportStaff item = (SupportStaff)items;
                    output = "EmpId : " + item.EmpId + " Name : " + item.Name + " Phone : " + item.Phone +
                             " Email : " + item.Email + " Dob : " + item.Dob + " Designation : " + item.Department;
                    Console.WriteLine(output + "\n");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("\n List is empty \n");
            }
        }
Пример #4
0
        public void DeleteStaff()
        {
            string       id;
            SupportStaff result = new SupportStaff();

            //int id = 0; //iterator = 0;
            RetrieveAllStaff();
            Console.WriteLine("\nEnter Details to Delete :");

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

            result = (SupportStaff)dbr.GetSingleStaff(id, (int)SType.SupportStaff);
            if (result != null)
            {
                DatabaseOperation db = new DatabaseOperation();
                db.DeleteStaff((int)SType.SupportStaff, id);
                Console.WriteLine("\nDeleted Successfull");
            }
            else
            {
                Console.WriteLine("\nStaff Not Found !!");
            }
        }
Пример #5
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<SupportStaff>(name);
            // XmlFileOperation xfile = new XmlFileOperation();
            // xfile.RetrieveFromFile<SupportStaff>(name);

            DatabaseOperation db = new DatabaseOperation();

            finalResult = db.SearchStaff(name, (int)SType.SupportStaff);
            if (finalResult.Count > 0)
            {
                foreach (var items in finalResult)
                {
                    SupportStaff item = (SupportStaff)items;
                    output = "EmpId : " + item.EmpId + " Name : " + item.Name + " Phone : " + item.Phone +
                             " Email : " + item.Email + " Dob : " + item.Dob + " Designation : " + item.Department;
                    Console.WriteLine(output + "\n");
                }
            }
            else
            {
                Console.WriteLine("\n List is empty \n");
            }
        }
        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);
            }
        }
Пример #7
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);
        }
        private SupportStaff getStaff(string EmpNo, bool IsNeedMainBelonging)
        {
            IEmployeeMasterHandler EmpHand   = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;
            List <tbm_Employee>    lstEmp    = new List <tbm_Employee>();
            List <doBelongingData> belonging = new List <doBelongingData>();
            SupportStaff           SupStff   = new SupportStaff();

            SupStff.EmpFullName = "";
            lstEmp = EmpHand.GetActiveEmployee(EmpNo);
            if (lstEmp.Count > 0)
            {
                if (IsNeedMainBelonging)
                {
                    belonging = EmpHand.GetMainBelongingByEmpNo(EmpNo);
                    if (belonging.Count > 0)
                    {
                        SupStff.BelongingOfficeDepart = belonging[0].BelongingOfficeDepart;
                    }
                }
                SupStff.EmpFullName = lstEmp[0].EmpFullName;

                return(SupStff);
            }

            return(SupStff);
        }
Пример #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            SupportStaff supportstaff = db.SupportStaff.Find(id);

            db.SupportStaff.Remove(supportstaff);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #10
0
 public ActionResult Edit(SupportStaff supportstaff)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supportstaff).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supportstaff));
 }
Пример #11
0
        //
        // GET: /TeacherAndSubject/Delete/5

        public ActionResult Delete(int id = 0)
        {
            SupportStaff supportstaff = db.SupportStaff.Find(id);

            if (supportstaff == null)
            {
                return(HttpNotFound());
            }
            return(View(supportstaff));
        }
Пример #12
0
        public ActionResult Create(SupportStaff supportstaff)
        {
            if (ModelState.IsValid)
            {
                db.SupportStaff.Add(supportstaff);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supportstaff));
        }
Пример #13
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
        }
Пример #14
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));
            }
        }
Пример #15
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)
                    {
                    }
                }
            }
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
0
        public void EditStaff()
        {
            string id;

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

            SupportStaff support = new SupportStaff();

            try
            {
                DatabaseOperation db = new DatabaseOperation();
                support = (SupportStaff)db.GetSingleStaff(id, (int)SType.SupportStaff);

                // JsonFileOperation jfile = new JsonFileOperation();
                // support = (SupportStaff)jfile.GetObj<SupportStaff>(id, support);
                // XmlFileOperation xfile = new XmlFileOperation();
                // support = (SupportStaff)xfile.GetObj<SupportStaff>(id, support);
                if (support.Name == null)
                {
                    Console.WriteLine("\nStaff Not Found !!");
                }
                else
                {
                    SupportStaff supportEdit = new SupportStaff();
                    supportEdit.StaffType  = SType.SupportStaff;
                    supportEdit.EmpId      = support.EmpId;
                    supportEdit.Name       = support.Name;
                    supportEdit.Phone      = support.Phone;
                    supportEdit.Dob        = support.Dob;
                    supportEdit.Email      = support.Email;
                    supportEdit.Department = support.Department;
                    EditHelp(id, support, supportEdit);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\nStaff Not Found !!");
            }
        }
        //public ActionResult CTS230_RemoveNotCompleteAttachFile()
        //{
        //    //ObjectResultData res = new ObjectResultData();
        //    //try
        //    //{
        //    //    ICommonHandler handCom = ServiceContainer.GetService<ICommonHandler>() as ICommonHandler;
        //    //    handCom.RemoveAttachFile(AttachmentModule.Project, null, Session.SessionID, false);
        //    //    res.ResultData = true;
        //    //    return Json(res);
        //    //}
        //    //catch (Exception ex)
        //    //{
        //    //    res.AddErrorMessage(ex);
        //    //    return Json(res);
        //    //}
        //    return View();
        //}

        //public ActionResult CTS230_AttachFile(HttpPostedFileBase uploadedFile, string DocName, string action, string delID)
        //{
        //    string TempRelatedID = Session.SessionID;
        //    MessageModel MsgModel;
        //    ObjectResultData res = new ObjectResultData();
        //    ICommonHandler handler = ServiceContainer.GetService<ICommonHandler>() as ICommonHandler;
        //    List<dtAttachFileNameID> lstAttachedName = handler.GetAttachFileName(TempRelatedID, null, false);

        //    if (action == "delete" && delID != "")
        //    {
        //        ICommonHandler comhand = ServiceContainer.GetService<ICommonHandler>() as ICommonHandler;
        //        comhand.RemoveAttachFile(AttachmentModule.Project, Convert.ToInt32(delID), TempRelatedID, false);
        //        List<dtAttachFileNameID> list = comhand.GetAttachFileName(TempRelatedID, null, false);
        //        ViewBag.AttachFileList = list;
        //        return View("CTS230_Upload");
        //    }

        //    if (lstAttachedName.Count >= AttachDocumentCondition.C_ATTACH_DOCUMENT_MAXIMUM_NUMBER && action == "upload")
        //    {
        //        MsgModel = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0076);
        //        ViewBag.AttachFileList = lstAttachedName;
        //        ViewBag.Message = MsgModel.Message;
        //        ViewBag.MsgCode = "MSG0076";
        //        return View("CTS230_Upload");
        //    }
        //    else
        //    {
        //        bool IsFileNameExist = false;
        //        foreach (dtAttachFileNameID i in lstAttachedName)
        //        {
        //            if (i.FileName.ToUpper() == DocName.ToUpper())
        //            {
        //                lstAttachedName = handler.GetAttachFileName(TempRelatedID, null, false);
        //                IsFileNameExist = true;
        //                break;
        //            }
        //        }
        //        if (IsFileNameExist)
        //        {
        //            MsgModel = MessageUtil.GetMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0115);
        //            lstAttachedName = handler.GetAttachFileName(TempRelatedID, null, false);
        //            ViewBag.AttachFileList = lstAttachedName;
        //            ViewBag.Message = MsgModel.Message;
        //            ViewBag.MsgCode = "MSG0115";
        //            return View("CTS230_Upload");
        //        }
        //    }
        //    if (uploadedFile != null)
        //    {
        //        int fileSize = uploadedFile.ContentLength;
        //        if (uploadedFile.ContentLength > 0)
        //        {
        //            byte[] data;
        //            using (BinaryReader reader = new BinaryReader(uploadedFile.InputStream))
        //            {
        //                data = reader.ReadBytes(uploadedFile.ContentLength);
        //            }
        //            string fileType = Path.GetExtension(uploadedFile.FileName);
        //            List<tbt_AttachFile> attach = handler.InsertAttachFile(TempRelatedID,
        //                                            DocName,
        //                                              fileType,
        //                                              fileSize,
        //                                              data,
        //                                              false,
        //                                              DateTime.Now,
        //                                              CommonUtil.dsTransData.dtUserData.EmpFullName,
        //                                              DateTime.Now,
        //                                              CommonUtil.dsTransData.dtUserData.EmpFullName);
        //        }
        //    }
        //    lstAttachedName = handler.GetAttachFileName(TempRelatedID, null, false);
        //    ViewBag.AttachFileList = lstAttachedName;
        //    return View("CTS230_Upload");
        //}

        #region CheckBeforeAdd

        /// <summary>
        /// Validate before add support staff
        /// </summary>
        /// <param name="Cond"></param>
        /// <returns></returns>
        public ActionResult CTS230_ChackBeforeAddSupportStaff(CTS230_SupportStaff Cond)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            if (ModelState.IsValid == false)
            {
                ValidatorUtil.BuildErrorMessage(res, this, null);
                if (res.IsError)
                {
                    return(Json(res));
                }
            }
            SupportStaff staff = getStaff(Cond.StaffCode, true);

            if (staff != null && CommonUtil.IsNullOrEmpty(staff.EmpFullName.Trim()))
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0095, new string[] { Cond.StaffCode }, new string[] { "SupportStaffCode" });
                return(Json(res));
            }
            bool IsStaff = false;

            if (!CommonUtil.IsNullOrEmpty(Cond.lstStaffCode))
            {
                for (int i = 0; i < Cond.lstStaffCode.Length; i++)
                {
                    if ((Cond.lstStaffCode[i].ToUpper() == Cond.StaffCode.ToUpper()))
                    {
                        IsStaff = true;
                        break;
                    }
                }
            }
            if (IsStaff)
            {
                res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3188, new string[] { Cond.StaffCode }, new string[] { "SupportStaffCode" });
                return(Json(res));
            }
            return(Json(true));
        }
Пример #20
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);
        }
Пример #21
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;
            }
        }
Пример #22
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));
            }
        }
Пример #23
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;
            }
        }
Пример #24
0
        public void AddStaff()
        {
            string bulkOrNot = "n";

            do
            {
                string       department = "";
                int          Count = 0, Select, id = 0;
                bool         valid = false;
                object[]     opt   = new object[5];
                string[]     Options;
                SupportStaff support = new SupportStaff();
                do
                {
                    opt     = EnterValues();
                    Options = ConfigList("Department");
                    Console.WriteLine("Enter Department :");
                    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;
                        }
                        department = Options[Select - 1];
                        break;
                    }while (Select != 0);
                    support.StaffType = SType.SupportStaff;
                    support.EmpId     = opt[4].ToString();
                    support.Name      = opt[0].ToString();
                    support.Phone     = opt[1].ToString();
                    if (!String.IsNullOrEmpty(opt[2].ToString()))
                    {
                        support.Dob = Convert.ToDateTime(opt[2]);
                    }
                    support.Email      = opt[3].ToString();
                    support.Department = department;
                    valid = Validation(support);
                    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)
                {
                    supportList.Add(support);
                    JsonFileOperation jfile = new JsonFileOperation();
                    jfile.AddToFile <SupportStaff>(support);
                    XmlFileOperation xfile = new XmlFileOperation();
                    xfile.AddToFile <SupportStaff>(support);

                    DatabaseOperation db = new DatabaseOperation();
                    db.AddBulkData(support.EmpId, support.Name, support.Phone, support.Email, support.Dob, (int)support.StaffType, support.Department);
                    //Console.WriteLine("\nValues added are :\n");

                    // Console.WriteLine("\nName: " + support.Name + " " + "DOB: " + support.Dob + " " + "Phone :" + support.Phone + " " + "Email :" + support.Email + " Department: " + support.Department);
                }
                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"));
        }
Пример #25
0
        public void EditHelp(string id, SupportStaff support, SupportStaff supportEdit)
        {
            int    option;
            bool   valid = false;
            string name = "", phone = "", email = "", department = "", date = "";

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

            Console.WriteLine("Edit Details of Staff :" + support.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 Department\n6.Exit");
                option = Convert.ToInt32(Console.ReadLine());
                switch (option)
                {
                case 1:
                    Console.WriteLine("Enter Name :");
                    name             = Console.ReadLine();
                    supportEdit.Name = name;
                    valid            = Validation(supportEdit);
                    if (valid)
                    {
                        Console.WriteLine("Name :" + supportEdit.Name);
                    }

                    break;

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

                    break;

                case 3:
                    Console.WriteLine("Enter date of birth");
                    date = InputDob();
                    if (!String.IsNullOrEmpty(date))
                    {
                        supportEdit.Dob = Convert.ToDateTime(date);
                    }

                    valid = Validation(supportEdit);
                    if (valid)
                    {
                        Console.WriteLine("Date of birth :" + supportEdit.Dob);
                    }

                    break;

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

                    break;

                case 5:
                    Console.WriteLine("Enter Department");
                    Options = ConfigList("Department");
                    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;
                        }
                        department = Options[Select - 1];
                        break;
                    }while (Select != 0);
                    supportEdit.Department = department;
                    valid = Validation(supportEdit);
                    if (valid)
                    {
                        Console.WriteLine("Department:" + supportEdit.Department);
                    }

                    break;

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

                default:
                    Console.WriteLine("Invalid Input!!");
                    break;
                }
            }while (option != 6);
        }
Пример #26
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);
        }
Пример #27
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;
            }
        }