Esempio n. 1
0
        public async Task <Dialog> GetDialogBetweenUsers(int[] users)
        {
            int dipper = users[0], mabel = users[1];

            VcksUser user1 = db.Users.Find(dipper);
            VcksUser user2 = db.Users.Find(mabel);

            if (user1 != null && user2 != null)
            {
                Dialog dialog = db.Dialogs.Include(x => x.Participants).Include(x => x.Messages).FirstOrDefault(d => d.Participants.Any(p => p.ProfileId == user1.Id) && d.Participants.Any(p => p.ProfileId == user2.Id));
                if (dialog == null)
                {
                    dialog = new Dialog()
                    {
                        Participants = new List <Participant>()
                        {
                            new Participant()
                            {
                                ProfileId = user1.Id
                            }, new Participant()
                            {
                                ProfileId = user2.Id
                            }
                        }
                    };
                    db.Dialogs.Add(dialog);
                    await db.SaveChangesAsync();
                }
                return(dialog);
            }
            return(null);
        }
Esempio n. 2
0
        public async Task <UserDTO> GetUser(int userId)
        {
            VcksUser user = await accountManager.GetUser(userId);

            var userDTO = mapper.Map <VcksUser, UserDTO>(user);

            return(userDTO);
        }
Esempio n. 3
0
        public async Task <VcksUser> GetUser(int userId)
        {
            VcksUser user = db.Users
                            .Include(z => z.Followers)
                            .ThenInclude(x => x.Profile.Avatar)
                            .Include(z => z.Friends)
                            .ThenInclude(x => x.Profile.Avatar)
                            .Include(z => z.Profile.Avatar)
                            .FirstOrDefault(u => u.Id == userId);

            if (user != null)
            {
                return(user);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        public async Task <OperationDetails> Create(RegisterModelDTO rm)
        {
            VcksUser user = await userManager.FindByNameAsync(rm.Email);

            if (user == null)
            {
                var original = new File()
                {
                    FileName    = rm.Avatar.FileName,
                    ContentType = rm.Avatar.ContentType,
                    Content     = rm.Avatar.Content,
                };
                var square = new File()
                {
                    FileName    = rm.Avatar.FileName,
                    ContentType = rm.Avatar.ContentType,
                    Content     = ImageHelpers.GetCroppedImage(rm.Avatar.Content),
                };
                var square_100 = new File()
                {
                    FileName    = rm.Avatar.FileName,
                    ContentType = rm.Avatar.ContentType,
                    Content     = ImageHelpers.GetCroppedImage(rm.Avatar.Content, 100),
                };
                var square_300 = new File()
                {
                    FileName    = rm.Avatar.FileName,
                    ContentType = rm.Avatar.ContentType,
                    Content     = ImageHelpers.GetCroppedImage(rm.Avatar.Content, 100),
                };
                var square_600 = new File()
                {
                    FileName    = rm.Avatar.FileName,
                    ContentType = rm.Avatar.ContentType,
                    Content     = ImageHelpers.GetCroppedImage(rm.Avatar.Content, 100),
                };

                user = new VcksUser()
                {
                    Email = rm.Email, UserName = rm.Email
                };

                user.Files = new List <File>()
                {
                    original, square, square_100, square_300, square_600
                };

                user.Profile = new VcksUserProfile()
                {
                    FirstName = rm.FirstName, LastName = rm.LastName, Email = rm.Email,
                    Avatar    = new Avatar {
                        Default = !rm.HasAvatar, Original = original, Square = square, Square_100 = square_100, Square_300 = square_300, Square_600 = square_600
                    }
                };

                var result = await userManager.CreateAsync(user, rm.Password);

                if (result.Errors.Count() > 0)
                {
                    return(new OperationDetails(false, result.Errors.FirstOrDefault().Description, ""));
                }

                await userManager.AddToRoleAsync(user, rm.Role);

                return(new OperationDetails(true, "Регистрация успешно пройдена", ""));
            }
            else
            {
                return(new OperationDetails(false, "Пользователь с таким логином уже существует", "Email"));
            }
        }