public void AddUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser = userRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //create new user messsage
                var newUserMessage = new UserMessage()
                {
                    User = existingUser,
                    Message = existingMessage
                };

                //add the new user message to the repository
                var userMessageRepository = new UserMessageRepository(uow);
                userMessageRepository.Add(newUserMessage);

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                                (
                                    e =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                    }
                                );
                        }
                    );

                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1 = new CapriconContext();
                var repository = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User.FirstName, existingUser.FirstName = "james");
                Assert.AreEqual(savedUserMessages[0].Message.MessageId, existingMessage.MessageId = 1);
            };
        }
Пример #2
0
        public void AddUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser   = userRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage   = messageRepository.GetAll().FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //create new user messsage
                var newUserMessage = new UserMessage()
                {
                    User    = existingUser,
                    Message = existingMessage
                };

                //add the new user message to the repository
                var userMessageRepository = new UserMessageRepository(uow);
                userMessageRepository.Add(newUserMessage);

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                    {
                        v.ValidationErrors.ToList().ForEach
                        (
                            e =>
                        {
                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                        }
                        );
                    }
                    );

                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1              = new CapriconContext();
                var repository        = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User.FirstName, existingUser.FirstName       = "james");
                Assert.AreEqual(savedUserMessages[0].Message.MessageId, existingMessage.MessageId = 1);
            };
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public List <UserMessageModel> GetUserMessages()
        {
            var items = UserMessageRepository.GetAll();

            if (items != null)
            {
                return(items.Select(p => p.ToModel()).ToList());
            }
            return(new List <UserMessageModel>());
        }
Пример #4
0
        public ActionResult Details(long messageID, int?pageIndex)
        {
            pageIndex = pageIndex ?? 1;
            UserMessageRepository.LoadWith(x => x.CreatorUser, x => x.MessageSection);
            var message = UserMessageRepository.GetByPK(messageID);

            if (message == null || message.ReceiverUserID.HasValue)
            {
                return(null);
            }
            var studentIds = _.List(message.CreatorUser.Student_ID.GetValueOrDefault());

            var userMessages = UserMessageRepository.GetAll(x => x.ParentMessageID == messageID)
                               .OrderBy(x => x.UserMessageID)
                               .ToPagedList(pageIndex.Value - 1);

            studentIds.AddRange(userMessages.Select(x => x.CreatorUser.Student_ID.GetValueOrDefault()));
            studentIds = studentIds.Where(x => x > 0).ToList();

            /*	var	bestStudents = ProfileService.FilterBestGraduate(studentIds);
             *      var	excelMasterStudents = ProfileService.FilterExcelMaster(studentIds);*/
            var realStudents = ProfileService.FilterRealGraduate(studentIds);

            var model = new MessageVM {
                Message = message,
                Answers = userMessages
            };

            model.AllMessages.ForEach(x => {
                var studentId = x.CreatorUser.Student_ID.GetValueOrDefault();
                if (studentId > 0)
                {
                    var types = new List <string>();

                    /*	if(bestStudents.Contains(studentId)) {
                     *              types.Add(UserMessage.BestGraduate);
                     *      }
                     *      if(excelMasterStudents.Contains(studentId)) {
                     *              types.Add(UserMessage.ExcelMaster);
                     *      }*/
                    var real = realStudents.GetValueOrDefault(studentId);
                    if (real != null)
                    {
                        types.Add(UserMessage.RealSpecialist + real);
                    }
                    x.BestTypes = types;
                }
            });
            return(View(model));
        }
        public void UpdateUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                var userMessageRepository = new UserMessageRepository(uow);

                var existingUserMessage = userMessageRepository.Find(um => um.Id == 1).FirstOrDefault();

                Assert.IsNotNull(existingUserMessage);

                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser = userRepository.Find(u => u.UserId == 1).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage = messageRepository.Find(m => m.MessageId == 1).FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //edit an existing user message
                existingUserMessage.User = existingUser;
                existingUserMessage.Message = existingMessage;

                userMessageRepository.Attach(existingUserMessage);
                uow.Entry(existingUserMessage).State = EntityState.Modified;

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                        {
                            v.ValidationErrors.ToList().ForEach
                                (
                                    e =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                                    }
                                );
                        }
                    );
                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1 = new CapriconContext();
                var repository = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User, existingUser);
                Assert.AreEqual(savedUserMessages[0].Message, existingMessage);
            };
        }
Пример #6
0
        public void UpdateUserMessage()
        {
            using (var uow = new CapriconContext())
            {
                var userMessageRepository = new UserMessageRepository(uow);

                var existingUserMessage = userMessageRepository.Find(um => um.Id == 1).FirstOrDefault();


                Assert.IsNotNull(existingUserMessage);

                //retreive an existing user
                var userRepository = new UserRepository(uow);
                var existingUser   = userRepository.Find(u => u.UserId == 1).FirstOrDefault();

                Assert.IsNotNull(existingUser);

                //retreive an existing message
                var messageRepository = new MessageRepository(uow);
                var existingMessage   = messageRepository.Find(m => m.MessageId == 1).FirstOrDefault();

                Assert.IsNotNull(existingMessage);

                //edit an existing user message
                existingUserMessage.User    = existingUser;
                existingUserMessage.Message = existingMessage;

                userMessageRepository.Attach(existingUserMessage);
                uow.Entry(existingUserMessage).State = EntityState.Modified;

                try
                {
                    uow.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Retrieve validation errors
                    ex.EntityValidationErrors.ToList().ForEach
                    (
                        v =>
                    {
                        v.ValidationErrors.ToList().ForEach
                        (
                            e =>
                        {
                            System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
                        }
                        );
                    }
                    );
                    Assert.Fail("Test failed");
                }

                //retrieve saved object
                var uow1              = new CapriconContext();
                var repository        = new UserMessageRepository(uow1);
                var savedUserMessages = repository.GetAll().ToList();

                Assert.AreEqual(savedUserMessages[0].User, existingUser);
                Assert.AreEqual(savedUserMessages[0].Message, existingMessage);
            };
        }