Esempio n. 1
0
        public ActionResult Profile(ProfileViewModel model)
        {
            if (model == null)
            {
                //TODO: return error message.
                return(View());
            }
            if (!ModelState.IsValid)
            {
                //TODO: return error message.
                return(View("EditProfile", model));
            }

            var userInfo = _userQueryService.GetUser(new UserId(UserContext.Current.UserId));

            if (userInfo == null)
            {
                //TODO: return error message.
                return(RedirectToAction("Profile", new { id = UserContext.Current.UserId }));
            }

            if (userInfo.FirstName != model.FirstName || userInfo.LastName != model.LastName || userInfo.Phone != model.Phone || userInfo.DateOfBirth != model.DateOfBirth)
            {
                var command = new ChangeUserInformation(new UserId(userInfo.UserId), model.Phone, userInfo.Image, model.FirstName,
                                                        model.LastName, model.DateOfBirth);
                _cmdSender.Send(command);

                UserContext.IsUpdated = false;
            }

            return(RedirectToAction("Profile", new { id = userInfo.UserId }));
        }
        public void CreateSessionByUsername_UserIsNull_ThrowsUserNotFoundException()
        {
            var user = new UserEntity();

            _userQueryService.GetUser(Arg.Any <string>()).Returns(user);

            Assert.Throws <UserNotFoundException>(() => _sut.CreateSessionByUsername("bryan", "pwd123"));
        }
        public void CreateUser_UserDoesNotExist_ReturnsUserEntity()
        {
            UserEntity user = null;

            _userQueryService.GetUser(Arg.Any <string>()).Returns(user);

            _userQueryService.Save(Arg.Any <UserEntity>()).Returns(new UserEntity());

            var result = _sut.CreateUser("bryan", "password");

            Assert.That(result, Is.TypeOf <UserEntity>());
        }
Esempio n. 4
0
        public UserSession CreateSessionByUsername(string username, string password)
        {
            var user = _userQueryService.GetUser(username);

            if (user == null || user.Password != password)
            {
                throw new UserNotFoundException("Incorrect username or password, please try again.");
            }

            var userSession = new UserSession()
            {
                UserId    = user.UserId.ToString(),
                SessionId = Guid.NewGuid(),
                Username  = user.Username
            };

            return(userSession);
        }
Esempio n. 5
0
        private TimeRecordsListViewModel PrepareTimeRecords(TimeRecordsListViewModel model,
                                                            IEnumerable <TimeRecordInfo> timeRecords, Guid?selectedProject, Guid?selectedPerson)
        {
            model.SelectedEndDate   = DateTime.Now.Date;
            model.SelectedStartDate = DateTime.Now.Date;
            model.Projects          = _projectQueryService.GetProjects().Select(x => new SelectListItem {
                Text = x.Name, Value = x.Id.ToString()
            });
            model.Statuses = this.GetStatuses();

            var projectId = selectedProject == null?Guid.Parse(model.Projects.First().Value) : (Guid)selectedProject;

            var isUserProjectManager = _userQueryService.IsUserProjectManager(new ProjectId(projectId), new UserId(UserContext.Current.UserId));

            model.IsProjectManager = isUserProjectManager;
            model.People           = this.GetPeople(isUserProjectManager, projectId);

            var userReporterId = selectedPerson == null?Guid.Parse(model.People.First().Value) : (Guid)selectedPerson;

            var userReporter = _userQueryService.GetUser(new UserId(userReporterId));

            model.User = new UserViewModel
            {
                LastName  = userReporter.LastName,
                FirstName = userReporter.FirstName
            };

            if (isUserProjectManager)
            {
                timeRecords = timeRecords.Where(x => x.Status == ProjectDomain.Model.DomainLayer.TimeRecordStatus.Notified);
            }

            model.Records = timeRecords.Select(x => new TimeRecordViewModel
            {
                StartDate = x.StartDate,
                EndDate   = x.EndDate,
                Effort    = x.Effort,
                Project   = x.Project == null ? null : new ProjectVewModel {
                    Name = x.Project.Name, ProjectId = x.Project.Id
                },
                TimeRecordId = x.TimeRecordId,
                Status       = (TimeRecordStatus)x.Status,
                Task         = x.Task == null ? null : new TaskViewModel {
                    TaskId = x.Task.TaskId, Title = x.Task.Title
                },
                Description = this.TrimString(x.Description, 60),
                UserId      = x.UserId,
            }).OrderBy(x => x.StartDate).ToArray();

            return(model);
        }
Esempio n. 6
0
        /// <summary>
        /// Registers the given user as a current viewer of the report with the given ID and
        /// broadcasts a message to all other viewers and monitors of the report.
        /// </summary>
        public void RegisterReportAccess(Guid reportId)
        {
            Guid userId = GetUserId();

            if (userId != Guid.Empty && reportId != Guid.Empty)
            {
                // Add the current connection to the given report's connection group and cache.
                _reportUsers.AddOrUpdate(reportId, (id) => new List <Guid>()
                {
                    userId
                }, (id, list) =>
                {
                    if (!list.Contains(userId))
                    {
                        list.Add(userId);
                    }
                    return(list);
                });
                Groups.Add(Context.ConnectionId, reportId.ToString());

                // Broadcast a message containing limited information about the user.
                User user     = _userQuerySvc.GetUser(userId);
                var  userInfo = user != null
                    ? new { user.Id, user.FullName }
                    : new { Id = userId, FullName = "" };

                // Only broadcast the message to other users.
                // TODO: Make sure this is ok in the scenario where the user is both viewing a report queue and editing a report.
                var excludeConnections = _userConnections.ContainsKey(userId) ? _userConnections[userId].ToArray() : new string[] { };
                Clients.Group(reportId.ToString(), excludeConnections).reportUserJoined(reportId, userInfo);

                // Manually broadcast to report monitors.
                foreach (var monitor in _reportMonitors.Where(m => m.Value.Contains(reportId)))
                {
                    Clients.Client(monitor.Key).reportUserJoined(reportId, userInfo);
                }
            }
        }
Esempio n. 7
0
        public UserEntity CreateUser(string username, string password)
        {
            var createdUser = new UserEntity()
            {
                Username = username,
                Password = password
            };

            var user = _userQueryService.GetUser(username);

            if (user == null)
            {
                return(_userQueryService.Save(createdUser));
            }

            throw new UserAlreadyExistsException($"The username '{username}' is not available, please try again.");
        }
Esempio n. 8
0
        public List <QueryCategoryReference> GetEnabledQueries(Guid userId)
        {
            //Find the Agency ID and name for the user
            var user = _userQueryService.GetUser(userId);

            if (user == null)
            {
                throw new Exception("User could not be found for User ID " + userId);
            }

            var agency = _agencyQueryService.GetAgency(user.PrimaryAgencyId);

            if (agency == null)
            {
                throw new Exception("Agency could not be found for Agency ID " + user.PrimaryAgencyId);
            }

            return(_queriesQueryService.GetEnabledQueries(_tenantName, agency.Id, agency.Name));
        }
        public ActionResult Edit(int id)
        {
            string sqlQuery = "SELECT * FROM [dbo].[ShowUserInfo]() WHERE Id = {0}";

            Object[] parameters = { id };

            var users = queryService.GetUser(id.ToString());

            //SelectList roles = roleQueryService.GetAllRoles();
            //ViewBag.Roles = roles;


            ShowUserInfo temp = new ShowUserInfo
            {
                Id       = Convert.ToInt32(users.Id),
                Name     = users.Name,
                Email    = users.Email,
                Pass     = users.Password,
                RoleName = users.Role.Name
            };

            return(View(temp));
        }
Esempio n. 10
0
        public User Get(Guid userId)
        {
            var user = _userQueryService.GetUser(userId);

            return(user);
        }
Esempio n. 11
0
 public List <UserModel> GetUsers()
 {
     return(_userQueryService.GetUser());
 }