예제 #1
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            var id = this.User.Identity.GetUserId();

            if (id != null)
            {
                var currentUser = this.UserManager.FindById(int.Parse(id));
                if (currentUser == null)
                {
                    this.AuthenticationManager.SignOut();
                    return;
                }

                this.ViewBag.User = new UserViewModel
                {
                    Id                = currentUser.Id,
                    UserName          = currentUser.UserName,
                    DisplayName       = currentUser.DisplayName,
                    EMail             = currentUser.DisplayName,
                    ProfilePictureUrl =
                        GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(currentUser.Email),
                                                      GravatarHelper.Size.S32)
                };
            }
        }
예제 #2
0
        public ActionResult Index()
        {
            var           existingUser  = ChatCookieHelperStub.GetDbUserFromCookie(this.Request);
            ChatViewModel chatViewModel = null;

            if (existingUser != null)
            {
                if (!ChatHub.IsUserRegisteredInDbUsersStub(existingUser))
                {
                    // cookie is invalid
                    ChatCookieHelperStub.RemoveCookie(this.Response);
                    return(this.RedirectToAction("Index"));
                }

                // in this case the authentication cookie is valid and we must render the chat
                chatViewModel = new ChatViewModel()
                {
                    IsUserAuthenticated = true,
                    UserId   = existingUser.Id,
                    UserName = existingUser.FullName,
                    UserProfilePictureUrl =
                        GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(existingUser.Email), GravatarHelper.Size.s32)
                };
            }

            return(this.View(chatViewModel));
        }
예제 #3
0
        public ActionResult Index()
        {
            var viewModel = new IndexViewModel
            {
                Rooms = this.Db.ChatRooms.Select(m => new RoomViewModel
                {
                    Id             = m.Id,
                    RoomName       = m.Name,
                    Description    = m.Description,
                    RoomUsersCount = m.ChatRoomUsers.Count
                }).ToList(),
                Users = this.Db.Users.Select(m => new UserViewModel
                {
                    Id          = m.Id,
                    DisplayName = m.DisplayName,
                    EMail       = m.Email
                }).ToList()
            };

            // refine data
            viewModel.Users.ForEach(
                u =>
            {
                u.ProfilePictureUrl = GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(u.EMail),
                                                                    GravatarHelper.Size.S16);
            });

            return(this.View(viewModel));
        }
예제 #4
0
        /// <summary>
        /// Joins the chat
        /// </summary>
        public ActionResult JoinChat(string userName, string email)
        {
            // try to find an existing user with the same e-mail
            var user = ChatHub.FindUserByEmail(email);

            if (user == null)
            {
                user = new ChatUser()
                {
                    Name              = userName,
                    Email             = email,
                    ProfilePictureUrl = GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(email), GravatarHelper.Size.s32),
                    Id     = new Random().Next(100000),
                    Status = ChatUser.StatusType.Online,
                    RoomId = ChatController.ROOM_ID_STUB
                };

                // for signalr
                {
                    ChatHub.RegisterNewUser(user);
                }

                // for long-polling
                {
                    ChatServer.SetupRoomIfNonexisting(ChatController.ROOM_ID_STUB);
                    ChatServer.Rooms[ChatController.ROOM_ID_STUB].RegisterNewUser(user);
                }
            }

            // Normally it wouldn't be necessary to create this cookie because the
            // FormsAuthentication cookie does this
            ChatHelper.CreateNewUserCookie(this.Response, user);

            return(this.RedirectToAction("Index"));
        }
        public static List <DoctorViewModel> GetDoctorViewModelsFromPractice(CerebelloEntitiesAccessFilterWrapper db, Practice practice, DateTime localNow)
        {
            var usersThatAreDoctors = db.Users
                                      .Where(u => u.PracticeId == practice.Id)
                                      .Where(u => u.Doctor != null);

            var dataCollection = usersThatAreDoctors
                                 .Select(u => new
            {
                ViewModel = new DoctorViewModel()
                {
                    Id               = u.Id,
                    Name             = u.Person.FullName,
                    UrlIdentifier    = u.Doctor.UrlIdentifier,
                    CRM              = u.Doctor.CRM,
                    MedicalSpecialty = u.Doctor.MedicalSpecialtyName,
                },
                u.Doctor.MedicalEntityCode,
                u.Doctor.MedicalEntityJurisdiction,
                u.Doctor,
                u.Person.EmailGravatarHash,
            })
                                 .ToList();

            // Getting more doctor's informations:
            // Todo: this is going to become a problem in the future, because this info has no cache.
            // - next free time slot of each doctor;
            // - gravatar image.
            foreach (var eachItem in dataCollection)
            {
                if (!string.IsNullOrEmpty(eachItem.EmailGravatarHash))
                {
                    eachItem.ViewModel.ImageUrl = GravatarHelper.GetGravatarUrl(eachItem.EmailGravatarHash, GravatarHelper.Size.s16);
                }

                eachItem.ViewModel.MedicalEntity = string.Format(
                    string.IsNullOrEmpty(eachItem.MedicalEntityJurisdiction) ? "{0}" : "{0}-{1}",
                    eachItem.MedicalEntityCode,
                    eachItem.MedicalEntityJurisdiction);

                // It is only possible to determine the next available time if the schedule of the doctor is already configured.
                if (eachItem.Doctor.CFG_Schedule != null)
                {
                    var nextSlotInLocalTime = ScheduleController.FindNextFreeTimeInPracticeLocalTime(db, eachItem.Doctor, localNow);
                    eachItem.ViewModel.NextAvailableTime = nextSlotInLocalTime.Item1;
                }
            }

            var doctors = dataCollection.Select(item => item.ViewModel).ToList();

            return(doctors);
        }
예제 #6
0
 private ChatUserInfo GetUserInfo(User user, ChatUserInfo.StatusType status)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     return(new ChatUserInfo
     {
         Id = user.Id,
         Name = user.DisplayName,
         Status = status,
         ProfilePictureUrl =
             GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(user.Email),
                                           GravatarHelper.Size.S32)
     });
 }
예제 #7
0
        internal static void FillUserViewModel(User user, Practice practice, UserViewModel viewModel)
        {
            viewModel.Id       = user.Id;
            viewModel.UserName = user.UserName;

            viewModel.FullName      = user.Person.FullName;
            viewModel.ImageUrl      = GravatarHelper.GetGravatarUrl(user.Person.EmailGravatarHash, GravatarHelper.Size.s16);
            viewModel.Gender        = user.Person.Gender;
            viewModel.DateOfBirth   = ConvertToLocalDateTime(practice, user.Person.DateOfBirth);
            viewModel.MaritalStatus = user.Person.MaritalStatus;
            viewModel.BirthPlace    = user.Person.BirthPlace;
            viewModel.Cpf           = user.Person.CPF;
            viewModel.Profissao     = user.Person.Profession;
            viewModel.Email         = user.Person.Email;

            viewModel.IsAdministrador = user.AdministratorId != null;
            viewModel.IsDoctor        = user.DoctorId != null;
            viewModel.IsSecretary     = user.SecretaryId != null;
            viewModel.IsOwner         = user.IsOwner;
        }
예제 #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var existingUser = ChatCookieHelperStub.GetDbUserFromCookie(new HttpRequestWrapper(this.Request));

            if (existingUser != null)
            {
                if (!ChatHub.IsUserRegisteredInDbUsersStub(existingUser))
                {
                    // cookie is invalid
                    ChatCookieHelperStub.RemoveCookie(new HttpResponseWrapper(this.Response));
                    // redirects the user to the same page
                    this.Response.Redirect("/Home/Index.aspx");
                }

                // in this case the authentication cookie is valid and we must render the chat
                IsUserAuthenticated = true;
                UserId   = existingUser.Id;
                UserName = existingUser.FullName;
                UserProfilePictureUrl = GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(existingUser.Email), GravatarHelper.Size.s32);
            }
        }
예제 #9
0
        private ChatUser GetUserById(int id)
        {
            var myRoomId = this.GetMyRoomId();

            // this is STUB. Normally you would go to the database get the real user
            var dbUser = chatUsers.First(u => u.Id == id);

            ChatUser.StatusType userStatus;
            lock (connections)
            {
                userStatus = connections.ContainsKey(myRoomId)
                                 ? (connections[myRoomId].ContainsKey(dbUser.Id)
                                        ? ChatUser.StatusType.Online
                                        : ChatUser.StatusType.Offline)
                                 : ChatUser.StatusType.Offline;
            }
            return(new ChatUser()
            {
                Id = dbUser.Id,
                Name = dbUser.Name,
                Status = userStatus,
                ProfilePictureUrl = GravatarHelper.GetGravatarUrl(GravatarHelper.GetGravatarHash(dbUser.Email), GravatarHelper.Size.s32)
            });
        }