Ejemplo n.º 1
0
        public async Task <IActionResult> Put([FromBody] StaffUpdateDTO staffUpdateDTO)
        {
            StaffUpdateModel StaffUpdate = new DTOMapper <StaffUpdateDTO, StaffUpdateModel>().Serialize(staffUpdateDTO);
            int UpdateId = await _staffService.UpdateUser(StaffUpdate);

            return(Ok());
        }
Ejemplo n.º 2
0
 public void EditStaff(User user, int id, StaffUpdateDTO staffDTO)
 {
     if (user.Id == id || user.Admin)
     {
         var          json   = File.ReadAllText(filePath);
         List <Staff> staffs = JsonConvert.DeserializeObject <List <Staff> >(json);
         var          res    = staffs.FirstOrDefault(x => x.Id == id);
         if (res != null)
         {
             res.UserName      = staffDTO.UserName ?? res.UserName;
             res.DateOfJoining = staffDTO.DateOfJoining ?? res.DateOfJoining;
             res.Password      = staffDTO.Password ?? res.Password;
             res.PhoneNumber   = staffDTO.PhoneNumber ?? res.PhoneNumber;
             res.Subject       = staffDTO.Subject ?? res.Subject;
             if (res.Admin)
             {
                 res.Admin = staffDTO.Admin;
             }
         }
         string jsonResult = JsonConvert.SerializeObject(staffs);
         File.WriteAllText(filePath, jsonResult);
     }
     else
     {
         Console.WriteLine("No access for edit");
     }
 }
        public void StaffAction()
        {
            StaffInt client   = new StaffController();
            int      latestId = IdCalculate.ComputeId();

            do
            {
                Console.Clear();
                Console.WriteLine("\t\t Staff Dashboard");
                Console.WriteLine("1. Add New Staff");
                Console.WriteLine("2. Edit Details");
                Console.WriteLine("3. Delete Data");
                Console.WriteLine("4. Exit Application");

                Console.Write("Enter your choice now: ");
                int selectedOption = Convert.ToInt32(Console.ReadLine());

                switch (selectedOption)
                {
                case 1:
                {
                    Console.WriteLine("Enter details of staff");
                    var staff = new Staff();
                    staff.Id = latestId;

                    Console.Write("UserName: "******"Password: "******"Subject: ");
                    staff.Subject = Console.ReadLine();

                    Console.Write("Experience: ");
                    staff.Experience = Convert.ToInt32(Console.ReadLine());

                    Console.Write("Phone: ");
                    staff.PhoneNumber = Console.ReadLine();

                    Console.Write("Date of Joining: ");
                    staff.DateOfJoining = Console.ReadLine();

                    staff.Admin = false;

                    client.AddStaff(staff);
                    break;
                }

                case 2:
                {
                    var staffDTO = new StaffUpdateDTO();
                    do
                    {
                        Console.Write("Enter one property to edit: (UserName , Password , Subject , Experience, Phone, DateOfJoining): ");
                        var property = Console.ReadLine();
                        Console.Write("Enter new value: ");
                        var value    = Console.ReadLine();
                        var staffObj = new StaffUpdateDTO();
                        var propInfo = staffObj.GetType().GetProperty(property);
                        if (propInfo == null)
                        {
                            Console.WriteLine("Wrong PropertyName");
                            break;
                        }
                        propInfo.SetValue(staffObj, value);
                        client.EditStaff(latestId, staffObj);
                    } while (Continue("edit"));
                    break;
                }

                case 5:
                {
                    Console.WriteLine("Are you Sure you want to delete your account? (Y/N)");
                    string ree = Console.ReadLine();
                    if (ree.Equals("Y") || ree.Equals("y"))
                    {
                        client.DeleteStaff(latestId);
                    }
                    break;
                }

                case 6:
                {
                    Environment.Exit(0);
                    break;
                }

                default:
                {
                    Console.WriteLine("Invalid choice, Retuning to Dashboard");
                    break;
                }
                }
            } while (Continue());
        }
        public void AdminActions(User user)
        {
            Admin           client     = new AdminControl();
            StaffController controller = new StaffController();
            int             latestId   = IdCalculate.ComputeId();

            do
            {
                Console.Clear();
                Console.WriteLine("\t\t Admin Dashboard");
                Console.WriteLine("1. View all Staffs");
                Console.WriteLine("2. View Staff Details");
                Console.WriteLine("3. Add Staff Details");
                Console.WriteLine("4. Edit Staff Details");
                Console.WriteLine("5. Delete Staff");
                Console.WriteLine("6. Exit Application");

                Console.Write("Enter your choice now: ");
                int selectedOption = Convert.ToInt32(Console.ReadLine());

                switch (selectedOption)
                {
                case 1:
                {
                    Console.WriteLine("Fetching all Data\n");
                    client.GetAllStaff(user.Admin);
                    break;
                }

                case 2:
                {
                    Console.Write("Enter Id of staff to view : ");
                    string id = Console.ReadLine();
                    client.GetStaff(user.Admin, Convert.ToInt32(id));
                    break;
                }

                case 3:
                {
                    if (user.Admin)
                    {
                        Console.WriteLine("Enter details of staff");
                        var staff = new Staff();
                        staff.Id = latestId;

                        Console.Write("UserName: "******"Password: "******"Subject: ");
                        staff.Subject = Console.ReadLine();

                        Console.Write("Experience: ");
                        staff.Experience = Convert.ToInt32(Console.ReadLine());

                        Console.Write("Phone: ");
                        staff.PhoneNumber = Console.ReadLine();

                        Console.Write("Date of Joining: ");
                        staff.DateOfJoining = Console.ReadLine();

                        staff.Admin = false;

                        client.AddStaff(user.Admin, staff);
                    }
                    else
                    {
                        Console.WriteLine("No Access");
                    }
                    break;
                }

                case 4:
                {
                    int id       = user.Id;
                    var staffDTO = new StaffUpdateDTO();
                    //limiting to one edit at a time
                    if (user.Admin)
                    {
                        Console.WriteLine("Enter Id of staff to edit");
                        id = Convert.ToInt32(Console.ReadLine());
                    }
                    Console.WriteLine("Enter property name and new value");
                    do
                    {
                        Console.Write("Enter one property to edit: (UserName , Password , Subject , Experience, Phone, DateOfJoining): ");
                        var property = Console.ReadLine();
                        Console.Write("Enter new value: ");
                        var value    = Console.ReadLine();
                        var staffObj = new StaffUpdateDTO();
                        var propInfo = staffObj.GetType().GetProperty(property);
                        if (propInfo == null)
                        {
                            Console.WriteLine("Wrong PropertyName");
                            break;
                        }
                        propInfo.SetValue(staffObj, value);

                        client.EditStaff(user, id, staffObj);
                    } while (Continue("edit"));
                    break;
                }

                case 5:
                {
                    Console.WriteLine("Enter details of staff to delete");
                    Console.Write("Enter Id of staff: ");
                    int id = Convert.ToInt32(Console.ReadLine());
                    client.DeleteStaff(user, id);
                    break;
                }

                case 6:
                {
                    Environment.Exit(0);
                    break;
                }

                default:
                {
                    Console.WriteLine("Invalid choice, Retuning to Dashboard");
                    break;
                }
                }
            } while (Continue());
        }