예제 #1
0
        public static void Display(Staffs staff)
        {
            switch (staff.StaffType)
            {
            case StaffType.TEACHINGSTAFF:

                Console.WriteLine("\nSTAFFID:{0}", staff.Id);
                Console.WriteLine("Staff :{0}", staff.StaffType);
                Console.WriteLine("Name :{0}", staff.Name);
                Console.WriteLine("Phone no :{0}", staff.Phone);
                Console.WriteLine("Email id :{0}", staff.Email);
                Console.WriteLine("class name:{0}", ((TeachingStaffs)staff).ClassName);
                Console.WriteLine("Subject:{0}", ((TeachingStaffs)staff).Subject);
                break;

            case StaffType.ADMINISTRATIVESTAFF:
                Console.WriteLine("\nSTAFFID:{0}", staff.Id);
                Console.WriteLine("Staff :{0}", staff.StaffType);
                Console.WriteLine("Name :{0}", staff.Name);
                Console.WriteLine("Phone no :{0}", staff.Phone);
                Console.WriteLine("Email id :{0}", staff.Email);
                Console.WriteLine("Designation:{0}", ((AdministrativeStaff)staff).Designation);
                break;

            case StaffType.SUPPORTSTAFF:
                Console.WriteLine("\nSTAFFID:{0}", staff.Id);
                Console.WriteLine("Staff :{0}", staff.StaffType);
                Console.WriteLine("Name :{0}", staff.Name);
                Console.WriteLine("Phone no :{0}", staff.Phone);
                Console.WriteLine("Email id :{0}", staff.Email);
                Console.WriteLine("Designation:{0}", ((SupportStaffs)staff).Designation);
                break;
            }
        }
        public static Staffs.Staffs GetStaffs(int id, List <Staffs.Staffs> StaffList)
        {
            Staffs.Staffs staff = StaffList.FirstOrDefault(x => x.Id == id);
            if (staff == null)
            {
                return(null);
            }
            else
            {
                switch (staff.StaffType)
                {
                case StaffType.TEACHINGSTAFF:
                    return((TeachingStaffs)staff);

                case StaffType.ADMINISTRATIVESTAFF:
                    return((AdministrativeStaff)staff);

                case StaffType.SUPPORTSTAFF:
                    return((SupportStaffs)staff);

                default:
                    return(null);
                }
            }
        }
        public static Staffs.Staffs InsertStaff(object json, List <Staffs.Staffs> StaffList)
        {
            dynamic dynamicstaff = JsonConvert.DeserializeObject(json.ToString());

            Staffs.Staffs staff  = new Staffs.Staffs();
            int           typeno = (int)dynamicstaff.staffType;

            switch (typeno)
            {
            case 1:
                staff    = JsonConvert.DeserializeObject <TeachingStaffs>(json.ToString());
                staff.Id = StaffDB.GetId();
                return(staff);

            case 2:
                staff    = JsonConvert.DeserializeObject <AdministrativeStaff>(json.ToString());
                staff.Id = StaffDB.GetId();
                return(staff);

            case 3:
                staff    = JsonConvert.DeserializeObject <SupportStaffs>(json.ToString());
                staff.Id = StaffDB.GetId();
                return(staff);

            default:
                return(staff);
            }
        }
 public IActionResult Get(int id)
 {
     Staffs.Staffs staff = StaffApiHelper.GetStaffs(id, StaffList);
     if (staff == null)
     {
         return(NotFound());
     }
     else
     {
         return(Ok(staff));
     }
 }
예제 #5
0
        public static void ViewOne(int a)
        {
            Staffs staff = StaffList.FirstOrDefault(x => x.Id == a);

            if (staff == null)
            {
                Console.WriteLine("NO STAFF WITH THIS ID");
            }
            else
            {
                staff.Display();
            }
        }
예제 #6
0
        public static void ViewOne(int viewid, List <Staffs> StaffList)
        {
            Staffs staff = StaffList.FirstOrDefault(x => x.Id == viewid);

            if (staff == null)
            {
                Console.WriteLine("NO STAFF WITH THIS ID");
            }
            else
            {
                Display(staff);
            }
        }
        public IActionResult Put(int id, [FromBody] object json)
        {
            Staffs.Staffs staff = JsonConvert.DeserializeObject <Staffs.Staffs>(json.ToString());
            if (staff.Id != id)
            {
                return(BadRequest());
            }
            int index = StaffList.FindIndex(s => (s.Id == id));

            //StaffList.Exists
            if (index == -1)
            {
                return(NotFound());
            }
            else
            {
                switch (StaffList[index].StaffType)
                {
                case StaffType.TEACHINGSTAFF:
                    TeachingStaffs staff_t = JsonConvert.DeserializeObject <TeachingStaffs>(json.ToString());
                    ((TeachingStaffs)StaffList[index]).UpdateTeaching(staff_t.Name, staff_t.Phone, staff_t.Email, staff_t.ClassName, staff_t.Subject);
                    break;

                case StaffType.ADMINISTRATIVESTAFF:
                    AdministrativeStaff staff_a = JsonConvert.DeserializeObject <AdministrativeStaff>(json.ToString());
                    ((AdministrativeStaff)StaffList[index]).UpdateAdministrative(staff_a.Name, staff_a.Phone, staff_a.Email, staff_a.Designation);
                    break;

                case StaffType.SUPPORTSTAFF:
                    SupportStaffs staff_s = JsonConvert.DeserializeObject <SupportStaffs>(json.ToString());
                    ((SupportStaffs)StaffList[index]).UpdateSupport(staff_s.Name, staff_s.Phone, staff_s.Email, staff_s.Designation);
                    break;
                }
                staffdb.WriteData(StaffList);
                return(Ok(StaffList[index]));
            }
        }