public void PostMessage(string recieverUsername, string Message)
        {
            var userRepo = new Repositories.UserRepository();

            Repositories.MessageRepository.AddNewMessage(userRepo.GetUserByUserName(User.Identity.Name),
                                                         userRepo.GetUserByUserName(recieverUsername).Id, Message);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (IRiakEndPoint endpoint = RiakCluster.FromConfig("riakConfig"))
            {
                IRiakClient client = endpoint.CreateClient();
                UserRepository userRepo = new UserRepository(client);
                MsgRepository msgRepo = new MsgRepository(client);
                TimelineRepository timelineRepo = new TimelineRepository(client);
                TimelineManager timelineMgr = new TimelineManager(timelineRepo, msgRepo);

                // Create and save users
                var marleen = new User("marleenmgr", "Marleen Manager", "*****@*****.**");
                var joe = new User("joeuser", "Joe User", "*****@*****.**");
                userRepo.Save(marleen);
                userRepo.Save(joe);

                // Create new Msg, post to timelines
                Msg msg = new Msg(marleen.UserName, joe.UserName, "Welcome to the company!");
                timelineMgr.PostMsg(msg);

                // Get Joe's inbox for today, get first message
                Timeline joesInboxToday = timelineMgr.GetTimeline(joe.UserName, Timeline.TimelineType.Inbox, DateTime.UtcNow);
                Msg joesFirstMsg = msgRepo.Get(joesInboxToday.MsgKeys.First());

                Console.WriteLine("From: " + joesFirstMsg.Sender);
                Console.WriteLine("Msg : " + joesFirstMsg.Text);
            }
        }
        public string ReturnFullNameFromId(int id)
        {
            var userRepo = new Repositories.UserRepository();
            var fullName = userRepo.ReturnFullNameById(id);

            return(fullName);
        }
Exemplo n.º 4
0
        public void UserRepository_AddDeviceRegistration()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.AddDeviceRegistration("UserComplete", new byte[0], 1, new byte[0], new byte[0]);

            _mockContext.Verify(v => v.SaveChanges(), Times.Once);
        }
Exemplo n.º 5
0
 public int Save(User user)
 {
     UserRepository ur = new UserRepository();
     if (user.ID > 0)
         return ur.Update(user);
     else
         return ur.Insert(user);
 }
Exemplo n.º 6
0
        public User GetUserByUsername(string username)
        {
            List<QueryParameter> queryParameters = new List<QueryParameter>();
            queryParameters.Add(new QueryParameter("username", username));

            List<User> users = new UserRepository().GetByParameter("getByUsername", queryParameters);
            return users != null ? users[0] : null;
        }
Exemplo n.º 7
0
        public void UserRepository_AddAuthenticationRequest()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.AddAuthenticationRequest("UserComplete", "appId", "challenge", "keyHandle");

            _mockContext.Verify(v => v.SaveChanges(), Times.Once);
        }
        public Models.MessageListModel GetMessages(string ActiveUser)
        {
            var userRepo = new Repositories.UserRepository();

            var modelList   = new Models.MessageListModel();
            var allMessages = Repositories.MessageRepository.GetAllPostsForUser(userRepo.GetUserByUserName(ActiveUser));

            var messages = new List <MessageModel>();

            foreach (var m in allMessages)
            {
                var model = new Models.MessageModel();
                model.MessageId      = m.Id;
                model.Message        = m.Message1;
                model.SenderID       = m.SenderId;
                model.RecieverID     = m.ReceiverId;
                model.SenderFullName = userRepo.ReturnFullNameById(model.SenderID);
                messages.Add(model);
            }
            modelList.Message = messages;
            return(modelList);
        }
Exemplo n.º 9
0
        public void UserRepository_AddDeviceRegistrationNoUser()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.AddDeviceRegistration("NoUser", new byte[0], 1, new byte[0], new byte[0]);

            _mockContext.Verify(v => v.SaveChanges(), Times.Never);
        }
Exemplo n.º 10
0
        public void UserRepository_UpdateDeviceCounterNoUserFound()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.UpdateDeviceCounter("NoUser", new byte[0], 1);

            // Nothing saved because user not found
            _mockContext.Verify(v => v.SaveChanges(), Times.Never);
        }
Exemplo n.º 11
0
        public void UserRepository_UpdateDeviceCounter()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.UpdateDeviceCounter("UserComplete", _deviceRegistration.PublicKey, 1);

            _mockContext.Verify(v => v.SaveChanges(), Times.Once);
        }
Exemplo n.º 12
0
        public void UserRepository_SaveUserAuthenticationRequestNoUser()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.SaveUserAuthenticationRequest("NoUser", "appId", "challenge", "keyHandle");

            _mockContext.Verify(v => v.SaveChanges(), Times.Never);
        }
Exemplo n.º 13
0
        public void UserRepository_RemoveUsersAuthenticationRequestNoUser()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.RemoveUsersAuthenticationRequests("NoUser");

            _mockContext.Verify(v => v.SaveChanges(), Times.Never);
        }
Exemplo n.º 14
0
 public User GetUser(int id)
 {
     UserRepository ur = new UserRepository();
     return ur.GetByID(id);
 }
Exemplo n.º 15
0
        public void UserRepository_FindUser()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            var user = userRepository.FindUser("TestUserJustName");

            Assert.IsNotNull(user);
        }
Exemplo n.º 16
0
        public void UserRepository_ConstructsProperly()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            Assert.IsNotNull(userRepository);
        }
Exemplo n.º 17
0
        public void UserRepository_AddUser()
        {
            _mockContext.Setup(s => s.Users.Add(It.IsAny<User>()));
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.AddUser("NewUser", "NewPassword");

            _mockContext.Verify(v => v.Users.Add(It.Is<User>((t => t.Name == "NewUser" && t.Password == "NewPassword"))), Times.Once);
            _mockContext.Verify(v => v.SaveChanges(), Times.Once);
        }
Exemplo n.º 18
0
 public bool ValidateUser(string username, string password)
 {
     List<QueryParameter> queryParameters = new List<QueryParameter>();
     queryParameters.Add(new QueryParameter("username", username));
     queryParameters.Add(new QueryParameter("password", password));
     List<User> users = new UserRepository().GetByParameter("validateUser", queryParameters);
     return users != null ? true : false;
 }
Exemplo n.º 19
0
        public void UserRepository_FindUserNullReturnsNull()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            var user = userRepository.FindUser(null);

            Assert.IsNull(user);
        }
Exemplo n.º 20
0
        public SaveResponse Create(IUnitOfWork uow, SaveRequest <MyRow> request)
        {
            //request.Entity.Status = 1;
            var userid = new MyRepository().Create(uow, request).EntityId.ToString();

            BalanceAccountRow balance   = new BalanceAccountRow();
            EmploeesStatusRow statusRow = new EmploeesStatusRow();

            balance.User_ID     = int.Parse(userid);
            balance.BaseSalary  = request.Entity.Balance;
            balance.GrossSalary = request.Entity.Balance;
            balance.NetIncome   = request.Entity.Balance;
            balance.DateEnd     = DateTime.Now;

            foreach (var item in request.Entity.AlowancesList)
            {
                item.UserId        = int.Parse(userid);
                item.AllowanceDate = DateTime.Now;

                balance.GrossSalary += item.Allowance; //3200
                balance.NetIncome   += item.Allowance; //3200
            }

            foreach (var item in request.Entity.InsuranceList)
            {
                item.UserId        = int.Parse(userid);
                item.InsuranceDate = DateTime.Now;

                /*balance.NetIncome = balance.GrossSalary;*/ //3200 -50
                balance.NetIncome -= item.InsurancesQ;
            }

            #region UserVacanciesLimit


            var VacancationsLimitR = request.Entity.UserVacanciesLimit;
            if (VacancationsLimitR.Count != 0)
            {
                int VacancationsLimitR_Distinct_count = VacancationsLimitR.Select(x => x.VacancyId).Distinct().Count();
                int VacancationsLimitR_Count          = VacancationsLimitR.Select(x => x.VacancyId).Count();

                if (VacancationsLimitR_Distinct_count == VacancationsLimitR_Count)
                {
                    foreach (var item in VacancationsLimitR)
                    {
                        item.UserId = int.Parse(userid);
                    }
                }
                else
                {
                    throw new Exception("Sorry You cannot Enter more than one Vaction Limit");
                }
            }

            #endregion



            statusRow.UserId             = int.Parse(userid);
            statusRow.EmploymentStatusID = 1; //Active in employmentStatus
            statusRow.EmpSDate           = DateTime.Now;
            uow.Connection.Insert <EmploeesStatusRow>(statusRow);

            uow.Connection.Insert <BalanceAccountRow>(balance);

            return(new SaveResponse());
        }
Exemplo n.º 21
0
        public void UserRepository_RemoveUsersAuthenticationRequest()
        {
            UserRepository userRepository = new UserRepository(_mockContext.Object);

            userRepository.RemoveUsersAuthenticationRequests("UserComplete");

            _mockContext.Verify(v => v.SaveChanges(), Times.Once);
        }
        static void Main(string[] args)
        {
            //-- Poor-man DI - build our dependencies by hand for this demo
            IDbScopeFactory dbScopeFactory = new EntityFrameworkScopeFactory();
            IAmbientDbLocator ambientDbLocator = new EntityFrameworkAmbientLocator();
            IUserRepository userRepository = new UserRepository(ambientDbLocator);

            var userCreationService = new UserCreationService(dbScopeFactory, userRepository);
            var userQueryService = new UserQueryService(dbScopeFactory, userRepository);
            var userEmailService = new UserEmailService(dbScopeFactory);
            var userCreditScoreService = new UserCreditScoreService(dbScopeFactory);

            try
            {
                Console.WriteLine("This demo application will create a database named DbContextScopeDemo in the default SQL Server instance on localhost. Edit the connection string in UserManagementDbContext if you'd like to create it somewhere else.");
                Console.WriteLine("Press enter to start...");
                Console.ReadLine();

                //-- Demo of typical usage for read and writes
                Console.WriteLine("Creating a user called Mary...");
                var marysSpec = new UserCreationSpec("Mary", "*****@*****.**");
                userCreationService.CreateUser(marysSpec);
                Console.WriteLine("Done.\n");

                Console.WriteLine("Trying to retrieve our newly created user from the data store...");
                var mary = userQueryService.GetUser(marysSpec.Id);
                Console.WriteLine("OK. Persisted user: {0}", mary);

                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                //-- Demo of nested DbScopes
                Console.WriteLine("Creating 2 new users called John and Jeanne in an atomic transaction...");
                var johnSpec = new UserCreationSpec("John", "*****@*****.**");
                var jeanneSpec = new UserCreationSpec("Jeanne", "*****@*****.**");
                userCreationService.CreateListOfUsers(johnSpec, jeanneSpec);
                Console.WriteLine("Done.\n");

                Console.WriteLine("Trying to retrieve our newly created users from the data store...");
                var createdUsers = userQueryService.GetUsers(johnSpec.Id, jeanneSpec.Id);
                Console.WriteLine("OK. Found {0} persisted users.", createdUsers.Count());

                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                //-- Demo of nested DbScopes in the face of an exception.
                // If any of the provided users failed to get persisted, none should get persisted.
                Console.WriteLine("Creating 2 new users called Julie and Marc in an atomic transaction. Will make the persistence of the second user fail intentionally in order to test the atomicity of the transaction...");
                var julieSpec = new UserCreationSpec("Julie", "*****@*****.**");
                var marcSpec = new UserCreationSpec("Marc", "*****@*****.**");
                try
                {
                    userCreationService.CreateListOfUsersWithIntentionalFailure(julieSpec, marcSpec);
                    Console.WriteLine("Done.\n");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine();
                }

                Console.WriteLine("Trying to retrieve our newly created users from the data store...");
                var maybeCreatedUsers = userQueryService.GetUsers(julieSpec.Id, marcSpec.Id);
                Console.WriteLine("Found {0} persisted users. If this number is 0, we're all good. If this number is not 0, we have a big problem.", maybeCreatedUsers.Count());

                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                //-- Demo of DbScope within an async flow
                Console.WriteLine("Trying to retrieve two users John and Jeanne sequentially in an asynchronous manner...");
                // We're going to block on the async task here as we don't have a choice. No risk of deadlocking in any case as console apps
                // don't have a synchronization context.
                var usersFoundAsync = userQueryService.GetTwoUsersAsync(johnSpec.Id, jeanneSpec.Id).Result;
                Console.WriteLine("OK. Found {0} persisted users.", usersFoundAsync.Count());

                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                //-- Demo of explicit database transaction.
                Console.WriteLine("Trying to retrieve user John within a READ UNCOMMITTED database transaction...");
                // You'll want to use SQL Profiler or Entity Framework Profiler to verify that the correct transaction isolation
                // level is being used.
                var userMaybeUncommitted = userQueryService.GetUserUncommitted(johnSpec.Id);
                Console.WriteLine("OK. User found: {0}", userMaybeUncommitted);

                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                //-- Demo of disabling the DbScope nesting behaviour in order to force the persistence of changes made to entities
                // This is a pretty advanced feature that you can safely ignore until you actually need it.
                Console.WriteLine("Will simulate sending a Welcome email to John...");

                using (var parentScope = dbScopeFactory.Create())
                {
                    var parentDbContext = parentScope.Get<UserManagementDbContext>();

                    // Load John in the parent DbContext
                    var john = parentDbContext.Users.Find(johnSpec.Id);
                    Console.WriteLine("Before calling SendWelcomeEmail(), john.WelcomeEmailSent = " + john.WelcomeEmailSent);

                    // Now call our SendWelcomeEmail() business logic service method, which will
                    // update John in a non-nested child context
                    userEmailService.SendWelcomeEmail(johnSpec.Id);

                    // Verify that we can see the modifications made to John by the SendWelcomeEmail() method
                    Console.WriteLine("After calling SendWelcomeEmail(), john.WelcomeEmailSent = " + john.WelcomeEmailSent);

                    // Note that even though we're not calling SaveChanges() in the parent scope here, the changes
                    // made to John by SendWelcomeEmail() will remain persisted in the database as SendWelcomeEmail()
                    // forced the creation of a new DbScope.
                }

                Console.WriteLine("Press enter to continue...");
                Console.ReadLine();

                //-- Demonstration of DbScope and parallel programming
                Console.WriteLine("Calculating and storing the credit score of all users in the database in parallel...");
                userCreditScoreService.UpdateCreditScoreForAllUsers();
                Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine();
            Console.WriteLine("The end.");
            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }