public async Task <IActionResult> AddEmployeeToGroup(EmployeeToGroupInvitationInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var userToAdd = await this.userManager.FindByEmailAsync(input.Email);

            if (userToAdd == null)
            {
                this.ModelState.AddModelError("NoSuchUser", "User with this email does not exists.");
                return(this.View(input));
            }

            var isEmployeeInTheGroupAlready = await this.employeeGroupService.IsEmployeeInGroup(userToAdd.Id, input.GroupId);

            if (isEmployeeInTheGroupAlready)
            {
                this.ModelState.AddModelError("EmployeeIsInGroupAlready", $"The employee with email:{input.Email} is already in the group!");
                return(this.View());
            }

            await this.employeeGroupService.AddEmployeeToGroupAsync(userToAdd.Id, input.GroupId, input.Salary, input.Position);

            return(this.RedirectToAction("Index", "People", new { ActiveTabGroupId = input.GroupId }));
        }
        public IActionResult AddEmployeeToGroup(string groupId)
        {
            var inputModel = new EmployeeToGroupInvitationInputModel()
            {
                GroupId = groupId,
            };

            return(this.View(inputModel));
        }
Beispiel #3
0
        public async Task <IActionResult> InviteUserToGroup(EmployeeToGroupInvitationInputModel details)
        {
            var groupNames = await this.groupService.GetGroupAsync <GroupBusinessNamesViewModel>(details.GroupId);

            var html = new StringBuilder();

            var guid = Guid.NewGuid().ToString();

            var verificationId = await this.inviteEmployeeVerificationsService.CreateShiftVerificationAsync(details.GroupId, details.Email, details.Position, details.Salary);

            html.AppendLine($"<h1> {groupNames.BusinessName} wants to invite you to {GlobalConstants.SystemName}</h1>");
            html.AppendLine($"<p> You are invited to become part of the group {groupNames.Name} at position {details.Position}</p>");
            html.AppendLine($"<p> Your salary will be {details.Salary}</p>");
            html.AppendLine($"<h3> If you accept you will become a member of {GlobalConstants.SystemName}, please click the button below! </h3>");
            html.AppendLine("<a> https://localhost:44319/InviteUser/AcceptInvitation/" + verificationId + "</a>");

            await this.emailSender.SendEmailAsync(GlobalConstants.EmailAddress, groupNames.BusinessName, details.Email, EmailSubject, html.ToString());

            return(this.RedirectToAction("Index", "People", new { ActiveTabGroupId = details.GroupId }));
        }