public ActionResult HeaderLogin()
 {
     if (User.Identity.IsAuthenticated)
     {
         UserDTO u = Helper.GetUser(User.Identity.Name);
         ViewBag.UserName = u.FirstName;
     }
     return(PartialView("_HeaderLogin"));
 }
Exemple #2
0
 public ActionResult Dialogs(int id)
 {
     if (messService.IsUserInDialog(id, Helper.GetUser(User.Identity.Name).Id).Data)
     {
         ViewBag.data = id;
         return(View("DialogsContainer", 1));
     }
     else
     {
         return(RedirectToAction("Dialogs"));
     }
 }
Exemple #3
0
        //===================Messages===================//
        public void SendMessage(int dialogId, string Text)
        {
            bool                  isToday  = true;
            UserDTO               fromUser = Helper.GetUser(Context.User.Identity.Name);
            DialogDTO             dDTO     = messService.GetDialog(dialogId, fromUser.Id).Data;
            DialogMessageDTO      prevdm   = dDTO.LastMessInDialog;
            IEnumerable <UserDTO> uid      = messService.GetUsersInDialog(dDTO.Id).Data;
            DialogMessageDTO      dm       = messService.SendMessage(new DialogMessageDTO()
            {
                DialogId = dialogId, FromUserId = fromUser.Id, Text = Text, Date = DateTime.Now, Status = false
            }).Data;

            if (prevdm != null)
            {
                if (prevdm.Date.Year == DateTime.Now.Year && prevdm.Date.Month == DateTime.Now.Month && prevdm.Date.Day == prevdm.Date.Day)
                {
                    isToday = false;
                }
            }
            foreach (UserDTO uDTO in uid)
            {
                ConnectedUser cu = users.FirstOrDefault(us => us.userId == uDTO.Id);
                if (cu != null)
                {
                    if (uDTO.Id == fromUser.Id)
                    {
                        if (uid.Count() == 2)
                        {
                            Clients.Client(cu.ConnectionId).showMessageForCaller(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = fromUser.FirstName + " " + fromUser.LastName,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                        else
                        {
                            Clients.Client(cu.ConnectionId).showMessageForCaller(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = dDTO.Name,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                    }
                    else
                    {
                        if (uid.Count() == 2)
                        {
                            Clients.Client(cu.ConnectionId).showMessage(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = fromUser.FirstName + " " + fromUser.LastName,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                        else
                        {
                            Clients.Client(cu.ConnectionId).showMessage(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = dDTO.Name,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                    }
                }
            }
        }
 public void SendFriendRequest(int friendId)
 {
     friendService.SendFriendRequest(Helper.GetUser(User.Identity.Name).Id, friendId);
 }