private PreviewProfileModel formatProfileData(int userId, ProfileStatisticsModel profileStatisticsModel)
        {
            var db = new MyDBModels.DB();
            var countUnreadMessages = 0;
            var countGroups         = 0;
            var dateUtils           = new DateUtils();

            var userModel    = db.user.Where(u => u.UserId == userId).First();
            var profileModel = db.profile.Where(p => p.ProfileId == userModel.ProfileId).First();

            var communicationIdArray    = userModel.CommunicationIdArray;
            var communicationDataAccess = new CommunicationDataAccess();

            communicationIdArray.ToList().ForEach(delegate(int communicationId)
            {
                var communicationModelDb = db.communication.Where(c => c.CommunicationId == communicationId).First();
                if (IsUnreadCommunication(communicationModelDb.MessageIdArray, profileModel.ProfileId))
                {
                    countUnreadMessages++;
                }
            });

            PreviewProfileModel previewProfileModel = new PreviewProfileModel();

            previewProfileModel.FullName              = String.Format("{0} {1}", profileModel.Name, profileModel.LastName);
            previewProfileModel.PhotoUrl              = profileModel.PhotoUrl;
            previewProfileModel.TimeLastActive        = profileModel.TimeLastActive;//dateUtils.calculateStateLastActivity(profileModel.TimeLastActive);
            previewProfileModel.CountRequestedFriends = userModel.FriendPossibleIdArray.Count();;
            previewProfileModel.CountUnreadMessages   = countUnreadMessages;
            previewProfileModel.CountRequestedGroups  = countGroups;
            previewProfileModel.ProfileStatistics     = profileStatisticsModel;

            return(previewProfileModel);
        }
        public PreviewProfileModel SingUpUser(SignUpModel model)
        {
            GenerateResponce responce = new GenerateResponce(Request);

            //if (model != null)
            {
                PreviewProfileModel modelProfile = logic.signUpUser(model);
                if (modelProfile != null)
                {
                    responce.generateResponce(HttpStatusCode.OK);
                }
                else
                {
                    responce.generateThrowWithMessage(HttpStatusCode.Unauthorized, "User with this login exist");
                }

                return(modelProfile);
            }
            //return responce.generateError(HttpStatusCode.InternalServerError, "Empty data");
        }
        public PreviewProfileModel LogInUser()
        {
            GenerateResponce    responce = new GenerateResponce(Request);
            PreviewProfileModel model    = new PreviewProfileModel();

            if (Request.Headers.Contains("Authorization"))
            {
                string basic = Request.Headers.GetValues("Authorization").First();
                model = logic.logInUser(basic);

                if (model == null)
                {
                    responce.generateThrowWithMessage(HttpStatusCode.Unauthorized, "No SignUp user");
                }
                return(model);
            }

            responce.generateThrowWithMessage(HttpStatusCode.BadRequest, "No Authorization field");
            return(model);
        }