示例#1
0
        public async Task AddPersonPositionAsync(PersonPosition personPosition,
                                                 CancellationToken ct = default)
        {
            await _repository.PersonPositions.AddAsync(personPosition, ct);

            await _repository.SaveChangesAsync(ct);
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            PersonPosition personPosition = db.PersonPositions.Find(id);

            db.PersonPositions.Remove(personPosition);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "PersonPositionId,PositionId,FirstName,LastName,Phone")] PersonPosition personPosition)
 {
     if (ModelState.IsValid)
     {
         db.Entry(personPosition).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PositionId = new SelectList(db.Positions, "PositionId", "Title", personPosition.PositionId);
     return(View(personPosition));
 }
示例#4
0
 public User(string username, string firstName, string lastName, string email, PersonPosition position, double salary, ShiftType shiftType, bool[] workingDays, Department department, int id)
 {
     this.ID        = id;
     Username       = username;
     FirstName      = firstName;
     LastName       = lastName;
     Email          = email;
     Position       = position;
     Salary         = salary;
     ShiftTypeU     = shiftType;
     WorkingDays    = workingDays;
     UserDepartment = department;
 }
示例#5
0
 private static PersonPositionViewModel PpDto(PersonPosition pp)
 {
     return(new PersonPositionViewModel
     {
         PersonPositionId = pp.PositionId,
         FirstName = pp.FirstName,
         LastName = pp.LastName,
         Phone = pp.Phone,
         PositionId = pp.PositionId,
         Person = pp.Person,
         Position = pp.Position
     });
 }
示例#6
0
        public static bool GetAllUsers()
        {
            string query = "Select * from people as p join working_days as wd on p.username = wd.username";

            try
            {
                using (MySqlConnection conn = new MySqlConnection(ConnectionString))
                {
                    List <User> results = new List <User>();
                    conn.Open();
                    MySqlCommand    cmd        = new MySqlCommand(query, conn);
                    MySqlDataReader dataReader = cmd.ExecuteReader();
                    while (dataReader.Read())
                    {
                        int            id          = Int32.Parse(dataReader[0].ToString());
                        string         username    = dataReader[1].ToString();
                        string         firstName   = dataReader[2].ToString();
                        string         lastName    = dataReader[3].ToString();
                        string         email       = dataReader[4].ToString();
                        string         phoneNumber = dataReader[5].ToString();
                        PersonPosition position    =
                            (PersonPosition)Enum.Parse(typeof(PersonPosition), dataReader[6].ToString(), true);
                        double     salary     = Double.Parse(dataReader[7].ToString());
                        Department department = new Department(dataReader[8].ToString());
                        ShiftType  shiftType  =
                            (ShiftType)Enum.Parse(typeof(ShiftType), dataReader[11].ToString(), true);
                        bool[] days = new bool[7];
                        for (int i = 0; i < 7; i++)
                        {
                            days[i] = bool.Parse(dataReader[i + 12].ToString());
                        }

                        User user = new User(username, firstName, lastName, email, position, salary, shiftType,
                                             days, department, id, phoneNumber);
                        results.Add(user);
                        //MessageBox.Show(user.ToString());
                    }

                    conn.Close();
                    Users.users.Clear();
                    Users.users.AddRange(results);
                }
            }
            catch (Exception)
            {
                throw new NoConnectionException();
            }

            return(true);
        }
示例#7
0
        // GET: EmployeePosition/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PersonPosition personPosition = db.PersonPositions.Find(id);

            if (personPosition == null)
            {
                return(HttpNotFound());
            }
            return(View(personPosition));
        }
示例#8
0
        public static bool ListIsNull(List <Person> listToCheck, PersonPosition position)
        {
            var foo = !listToCheck.Where(a => a.Position == position).Any();

            if (foo)
            {
                Console.WriteLine(
                    "=======================\n" +
                    $"There are no {position}s in the current list!\n" +
                    "Please add more!"
                    );
                Console.ReadLine();
            }
            return(foo);
        }
示例#9
0
        // GET: EmployeePosition/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PersonPosition personPosition = db.PersonPositions.Find(id);

            if (personPosition == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PositionId = new SelectList(db.Positions, "PositionId", "Title", personPosition.PositionId);
            return(View(personPosition));
        }
示例#10
0
        public async Task AddPeoplePositionsAsync(Room room, List <PersonDTO> people,
                                                  DateTime timestamp, CancellationToken ct = default)
        {
            foreach (var person in people)
            {
                var personPosition = new PersonPosition()
                {
                    Room            = room,
                    PositionX       = person.PositionX,
                    PositionY       = person.PositionY,
                    FaceMask        = person.FaceMask,
                    NearestDistance = person.NearestDistance,
                    Timestamp       = timestamp,
                };

                await AddPersonPositionAsync(personPosition, ct);
            }
        }
示例#11
0
 public User(string firstName, string lastName, string email, PersonPosition position, double salary, ShiftType shiftType, bool[] workingDays, Department department)
 {
     try
     {
         Username = GenerateUsername();
     }
     catch (FormatException)
     {
         throw new UsernameErrorException();
     }
     catch (IOException)
     {
         throw new IOException();
     }
     FirstName      = firstName;
     LastName       = lastName;
     Email          = email;
     Position       = position;
     Salary         = salary;
     ShiftTypeU     = shiftType;
     WorkingDays    = workingDays;
     UserDepartment = department;
 }
示例#12
0
        public async System.Threading.Tasks.Task <IActionResult> CreateProfile(CreateProfileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.SelectPost.Posts  = this._positionService.GetAllPosition();
                model.SelectPost.PostId = model.SelectPost.Posts.FirstOrDefault().Id;
                return(View(model));
            }

            var person = new Person
            {
                LastName   = model.LastName,
                FirstName  = model.FirstName,
                MiddleName = model.MiddleName,
                Gender     = (DAL.Gender)model.Gender,
                INN        = model.INN,
                SNILS      = model.SNILS,
                Post       = new Position
                {
                    Id = model.SelectPost.PostId
                }
            };

            var education = new Education();

            var files = HttpContext.Request.Form.Files;

            if (files.Count > 0)
            {
                var allowedExtensions = new[] { ".png", ".jpg" };
                foreach (var file in files)
                {
                    if (file.Name == "profileImage")
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await file.CopyToAsync(memoryStream);

                            string fileExtension = Path.GetExtension(file.FileName);
                            if (!allowedExtensions.Contains(fileExtension))
                            {
                                return(View(model));
                            }
                            person.Image = memoryStream.ToArray();
                        }
                    }
                    else if (file.Name == "educationImage")
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await file.CopyToAsync(memoryStream);

                            string fileExtension = Path.GetExtension(file.FileName);
                            if (!allowedExtensions.Contains(fileExtension))
                            {
                                return(View(model));
                            }
                            education.File = memoryStream.ToArray();
                        }
                    }
                }
            }
            var resultPerson = this._personService.CreatePerson(person);

            var personPosition = new PersonPosition
            {
                PersonId   = resultPerson.Id,
                PositionId = model.SelectPost.PostId
            };

            this._personPositionService.AddPersonPosition(personPosition);

            if (education.File != null)
            {
                education.EndDate  = model.Education.EndDate;
                education.PersonId = resultPerson.Id;
                this._educationService.CreateEducation(education);
            }

            var passport = new Passport
            {
                PersonId   = resultPerson.Id,
                Series     = model.PassportSeries,
                Number     = model.PassportNumber,
                GivenBy    = model.PassportGivenBy,
                Address    = model.PassportAddress,
                DateOfGive = model.PassportDateOfGive
            };

            this._passportService.CreatePassport(passport);

            var insurance = new InsurancePolicy
            {
                PersonId = resultPerson.Id,
                Number   = model.InsuranceNumber,
                Company  = model.InsuranceCompany
            };

            this._insuranceService.CreatePolicy(insurance);

            return(RedirectToAction("Persons", "Person"));
        }
示例#13
0
 /// <summary>
 /// Updates a persons position
 /// </summary>
 /// <param name="personPosition"></param>
 public void UpdatePersonPosition(PersonPosition personPosition)
 {
     this._unitOfWork.PersonsPositions.Update(personPosition);
 }
示例#14
0
 /// <summary>
 /// Adds a new position to a person
 /// </summary>
 /// <param name="personPosition"></param>
 public void AddPersonPosition(PersonPosition personPosition)
 {
     this._unitOfWork.PersonsPositions.Create(personPosition);
 }
示例#15
0
        public async Task <ActionResult> OAuth2(string code, string state, string error, string error_description)
        {
            //2 Step:After logging in, linkedin will redirect back to our site, to the url that whe mentioned in reurn_uri, with Authorize Code or error
            Person          profile         = null;
            LinkedInProfile linkedInProfile = new LinkedInProfile();

            if (!string.IsNullOrEmpty(error) | !string.IsNullOrEmpty(error_description))
            {
                this.ViewBag.Error            = error;
                this.ViewBag.ErrorDescription = error_description;
                return(View());
            }
            else
            {
                //3rd step: If no errors, Get the AccessToken from the AuthorizeCode that linkedin sent back to us
                try
                {
                    // get the APIs client to get the accesstoken
                    LinkedInApi api       = new LinkedInApi(config);
                    var         userToken = await api.OAuth2.GetAccessTokenAsync(code, redirect_uri);

                    //4th step: Use this access token to get the loggedin Member details
                    if (userToken != null && !string.IsNullOrEmpty(userToken.AccessToken))
                    {
                        //1-way to get member profile details: Conventional way  // Not giving all the values for the specified scopes
                        //var Profileclient = new RestClient("https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,title,position,profilePicture,displayImage,profilePicture(displayImage~:playableStreams))") { };
                        //var ProfileAuthRequest = new RestRequest("", Method.GET) { };
                        //ProfileAuthRequest.AddHeader("Authorization", "Bearer " + userToken.AccessToken);
                        //var Profileresponse = Profileclient.Execute(ProfileAuthRequest);

                        //2-way to get member profile details: Through  Sparkle.LinkedInNET plugin
                        var      user        = new UserAuthorization(userToken.AccessToken);
                        string[] acceptlangs = { "en-US" };// need to pass the accepting languages
                        profile = api.Profiles.GetMyProfile(user, acceptlangs, FieldSelector.For <Person>().WithEmailAddress().WithId().WithPictureUrl().WithPositionsTitle().WithSummary().WithFirstName().WithLastName().WithMaidenName().WithPhoneNumbers().WithPublicProfileUrl());


                        //5th step: After getting the profile details, map to our own model
                        if (profile != null)
                        {
                            //Map return values to our own model
                            linkedInProfile.Firstname        = profile.Firstname;
                            linkedInProfile.Lastname         = profile.Lastname;
                            linkedInProfile.MaidenName       = profile.MaidenName;
                            linkedInProfile.EmailAddress     = profile.EmailAddress;
                            linkedInProfile.PictureUrl       = profile.PictureUrl;
                            linkedInProfile.PublicProfileUrl = profile.PublicProfileUrl;
                            linkedInProfile.Summary          = profile.Summary;
                            if (profile.Positions != null)
                            {
                                PersonPosition personpos = profile.Positions.Position.FirstOrDefault() != null?profile.Positions.Position.SingleOrDefault() : new PersonPosition();

                                linkedInProfile.PositionTitle = personpos.Title ?? string.Empty;
                            }
                            if (profile.PhoneNumbers != null)
                            {
                                PhoneNumber phonenum = profile.PhoneNumbers.PhoneNumber.Count > 0 ? profile.PhoneNumbers.PhoneNumber.SingleOrDefault() : new PhoneNumber();
                                linkedInProfile.PhoneNumber = phonenum.Number ?? string.Empty;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    // throw new HttpRequestException("Request to linkedin Service failed.");
                }
            }

            return(View(linkedInProfile));
        }
示例#16
0
        private void confirmBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(firstNameTb.Text) && !string.IsNullOrWhiteSpace(lastNameTb.Text) &&
                    !string.IsNullOrWhiteSpace(emailTb.Text) && !string.IsNullOrWhiteSpace(salaryTb.Text))
                {
                    if (shiftCb.SelectedIndex > 0 && departmentCb.SelectedIndex > 0 && roleCb.SelectedIndex > 0)
                    {
                        const string emailPattern =
                            "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
                        Regex regex = new Regex(emailPattern);
                        if (regex.IsMatch(emailTb.Text))
                        {
                            string         fn         = firstNameTb.Text;
                            string         ln         = lastNameTb.Text;
                            string         email      = emailTb.Text;
                            string         salaryStr  = Regex.Replace(salaryTb.Text, "€", "");
                            double         salary     = double.Parse(salaryStr.Trim());
                            Department     department = Departments.DepartmentByName(departmentCb.SelectedItem.ToString());
                            PersonPosition position   = (PersonPosition)Enum.Parse(typeof(PersonPosition), roleCb.Text, true);
                            if ((position == PersonPosition.Manager && Users.admin) || (position != PersonPosition.Manager))
                            {
                                ShiftType type  = (ShiftType)Enum.Parse(typeof(ShiftType), shiftCb.Text, true);
                                bool[]    _days = new bool[7];
                                _days[0] = mondayCbx.Checked;
                                _days[1] = tuesdayCbx.Checked;
                                _days[2] = wednesdayCbx.Checked;
                                _days[3] = thursdayCbx.Checked;
                                _days[4] = fridayCbx.Checked;
                                _days[5] = saturdayCbx.Checked;
                                _days[6] = sundayCbx.Checked;

                                if (_edit)
                                {
                                    _userToBeEdited.FirstName      = fn;
                                    _userToBeEdited.LastName       = ln;
                                    _userToBeEdited.Email          = email;
                                    _userToBeEdited.Position       = position;
                                    _userToBeEdited.Salary         = salary;
                                    _userToBeEdited.ShiftTypeU     = type;
                                    _userToBeEdited.WorkingDays    = _days;
                                    _userToBeEdited.UserDepartment = department;
                                    Users.UpdateUser(_userToBeEdited);
                                }
                                else
                                {
                                    if (position == PersonPosition.Manager)
                                    {
                                        Users.AddUser(new User(fn, ln, email, position, salary, type, _days, department), true);
                                    }
                                    else
                                    {
                                        Users.AddUser(new User(fn, ln, email, position, salary, type, _days, department));
                                    }
                                }
                                DatabaseFunctions.GetAllUsers();
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Managers can be added just by admin profile!", "Error", MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please, select a valid Email!", "Error", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Choose valid shift!");
                    }
                }
                else
                {
                    MessageBox.Show("Fill in the empty fields!");
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Salary must be numeric!");
            }
            catch (NoConnectionException)
            {
                MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (NotExistingException)
            {
                MessageBox.Show("User is non-existent, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (UsernameErrorException)
            {
                MessageBox.Show("Error occured, when tried to generate username, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (IOException)
            {
                MessageBox.Show("Error loading resources, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }