public async Task <bool> CreateActionItem(ActionItemForCreateDto actionItemForCreateDto)
        {
            var actionItem = _mapper.Map <ActionItem>(actionItemForCreateDto);

            actionItem.CreatedAt = DateTime.Now;

            var savedActionItem = await _unitOfWork.ActionItem.CreateActionItem(actionItem);

            if (savedActionItem != null)
            {
                foreach (var itemAssignee in actionItemForCreateDto.Assignees)
                {
                    itemAssignee.CreatedAt = DateTime.Now;
                    itemAssignee.ItemId    = savedActionItem.Id;
                    var assigneeResult = await _unitOfWork.ItemAssignee.InsertAssignees(itemAssignee);

                    await _azureBusService.SendEmailAsync(itemAssignee.AssigneeId, "actionAssign");

                    if (!assigneeResult)
                    {
                        return(assigneeResult);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateUser(UsersForAdminDto userForEdit)
        {
            var user = await _unitOfWork.User.GetUser(userForEdit.Id);

            if (user != null)
            {
                _mapper.Map(userForEdit, user);
                var firstRole = 0;
                try
                {
                    var previousRole = await _userManager.GetRolesAsync(user);

                    if (userForEdit.Role != null && previousRole[firstRole] != userForEdit.Role)
                    {
                        var addNewRole = await _userManager.AddToRoleAsync(user, userForEdit.Role);

                        if (!addNewRole.Succeeded)
                        {
                            return(BadRequest("Adding new Role  unsuccessful"));
                        }
                        var deletePreviousRole = await _userManager.RemoveFromRoleAsync(user, previousRole[firstRole]);

                        if (!deletePreviousRole.Succeeded)
                        {
                            return(BadRequest("Removing previous Role unsuccessful"));
                        }
                        await _azureBusService.SendEmailAsync(user.Id, "roleChange");
                    }
                    if (userForEdit.Locked)
                    {
                        user.LockoutEnd = DateTime.Now.AddYears(100);
                    }

                    if (!userForEdit.Locked && user.LockoutEnd > DateTime.Now && user.LockoutEnd != null)
                    {
                        user.LockoutEnd = DateTime.Now;
                    }
                    await _unitOfWork.Save();

                    return(Ok());
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"error message: {exception}");
                    return(BadRequest("Save unsuccesful"));
                }
            }
            return(BadRequest("Save unsuccesful"));
        }
        public async Task <IActionResult> AddInitiativeMember(InitiativeMemberDto initiativeMemberForCreateDto)
        {
            var initiativeMember = await _initiativeMemberService.GetInitiativeMember(initiativeMemberForCreateDto);

            if (initiativeMember != null)
            {
                return(BadRequest("Already a member"));
            }

            if (initiativeMember == null)
            {
                var result = await _initiativeMemberService.AddInitiativeMember(initiativeMemberForCreateDto);

                if (result)
                {
                    await _azureBusService.SendEmailAsync(initiativeMemberForCreateDto.MemberId, "initiativeAssign");

                    return(Ok());
                }
            }

            return(BadRequest("Adding member is failed"));
        }