private void Window_Closed(object sender, EventArgs e)
        {
            var editWindow = (EditWindow)sender;

            employees = editWindow.employees;
            SetTextBlocks();
        }
Beispiel #2
0
        private async void Hire_Click(object sender, RoutedEventArgs e)
        {
            if (LoginInput.Text == "" || NameInput.Text == "" || SurnameInput.Text == "" || BirthdayInput.Text == "" || PositionInput.Text == "" || SecurityInput.Text == "")
            {
                MessageBox.Show("Fill all fields");
                return;
            }
            EmployeesToView beginner = new EmployeesToView();

            beginner.Login    = LoginInput.Text;
            beginner.Name     = NameInput.Text;
            beginner.Surname  = SurnameInput.Text;
            beginner.Birthday = DateTime.Parse(BirthdayInput.Text);
            beginner.Position = PositionInput.Text;
            beginner.Security = int.Parse(SecurityInput.Text);
            try
            {
                var response = await httpClient.PostAsync("Login", new StringContent(JsonConvert.SerializeObject(beginner), Encoding.UTF8, "application/json"));

                if (!GetError(response.StatusCode, true))
                {
                    return;
                }
                else
                {
                    MessageBox.Show($"Login - {beginner.Login}\nPassword - qwerty", "For beginner");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void Promotion_Closed(object sender, EventArgs e)
        {
            var promotionWindow = (PromotionWindow)sender;

            employees = promotionWindow.employees;
            SetTextBlocks();
        }
Beispiel #4
0
 public PromotionWindow(EmployeesToView toView, HttpClient http)
 {
     httpClient = http;
     employees  = toView;
     InitializeComponent();
     Position.Text = employees.Position;
     Security.Text = employees.Security.ToString();
 }
 public EditWindow(HttpClient client, EmployeesToView toView)
 {
     httpClient = client;
     employees  = toView;
     InitializeComponent();
     NameInput.Text     = toView.Name;
     SurnameInput.Text  = toView.Surname;
     BirthdayInput.Text = $"{toView.Birthday.Value.Date}";
     PositionInput.Text = toView.Position;
     SecurityInput.Text = toView.Security.ToString();
 }
        public void EditEmployee(string forEdit, [FromBody] EmployeesToView toView)
        {
            var currentEmployee = officeDB.Employees.FirstOrDefault(t => t.Login == RequestContext.Principal.Identity.Name);
            var employees       = officeDB.Employees.FirstOrDefault(t => t.Login == forEdit);

            if (currentEmployee == employees || employees.Security >= currentEmployee.Security || toView.Security > currentEmployee.Security)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }
            else
            {
                employees.Name     = toView.Name;
                employees.Surname  = toView.Surname;
                employees.Birthday = toView.Birthday;
                employees.Position = toView.Position;
                employees.Security = toView.Security;
            }
        }
Beispiel #7
0
        private async void GetProfile()
        {
            var response = await httpClient.GetAsync("Profile");

            if (!GetError(response.StatusCode, true))
            {
                return;
            }
            myProfile = await Response <EmployeesToView> .GetResponse(response);

            Login.Text      = myProfile.Login;
            UserName.Text   = $"{myProfile.Name} {myProfile.Surname}";
            Birthday.Text   = myProfile.Birthday.ToString();
            HiringTime.Text = myProfile.Hiring_Time.ToString();
            Position.Text   = myProfile.Position;
            Security.Text   = myProfile.Security.ToString();
            //Profile.Content = myProfile;
            GetLogin($"{myProfile.Name} {myProfile.Surname}");
            response.Dispose();
        }
        public void Hiring([FromBody] EmployeesToView beginner)
        {
            var currentEmployee = officeDB.Employees.FirstOrDefault(t => t.Login == RequestContext.Principal.Identity.Name);

            if (currentEmployee.Security < beginner.Security)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }
            officeDB.Employees.Add(new Employees
            {
                Login       = beginner.Login,
                Password    = "******",
                Name        = beginner.Name,
                Surname     = beginner.Surname,
                Birthday    = beginner.Birthday,
                Hiring_Time = DateTime.UtcNow.Date,
                Security    = beginner.Security,
                Position    = beginner.Position
            });
            officeDB.SaveChangesAsync();
        }
 public ViewWindow(EmployeesToView toView, HttpClient http)
     : this(toView)
 {
     httpClient = http;
 }
Beispiel #10
0
 public ViewWindow(EmployeesToView toView)
 {
     InitializeComponent();
     employees = toView;
     SetTextBlocks();
 }