private void OnApplyChanges(grs_TblUserview currentView, BLL_UserView newEntity)
 {
     if (!newEntity.Layout.IsNullOrEmpty())
     {
         currentView.Layout = newEntity.Layout;
     }
 }
 private void AssignDefaults(grs_TblUserview currentView, BLL_UserView newEntity)
 {
     currentView.Userid     = UserIdentity.UserId;
     currentView.Screenname = newEntity.ScreenName;
     currentView.Viewname   = newEntity.ViewName;
     currentView.Layout     = newEntity.Layout;
     currentView.Customview = newEntity.CustomView ?? true;
     currentView.Sortorder  = newEntity.SortOrder ?? 1;
 }
        private void SetupUserViewRepository()
        {
            var userviewdata = new grs_TblUserview()
            {
                ViewId     = 101,
                Userid     = 100,
                Default    = false,
                Screenname = "GRS.UW_Workbench",
                Viewname   = "mysubmissions",
                Layout     = "SomeJason",
                Customview = false,
                Sortorder  = 1
            };

            userViewRepository.Setup(p => p.Get(It.IsAny <Expression <Func <grs_TblUserview, bool> > >())).Returns(userviewdata);
        }
 public BLL_UserView Transform(grs_TblUserview dbModel)
 {
     if (dbModel == null)
     {
         return(null);
     }
     return(new BLL_UserView()
     {
         ViewId = dbModel.ViewId,
         UserId = dbModel.Userid,
         ScreenName = dbModel.Screenname,
         ViewName = dbModel.Viewname,
         Default = dbModel.Default,
         Layout = dbModel.Layout,
         SortOrder = dbModel.Sortorder,
         CustomView = dbModel.Customview
     });
 }
        public EntityResult <BLL_UserView> AddUserView(BLL_UserView bLL_UserView)
        {
            try
            {
                validateParams(bLL_UserView);

                if (bLL_UserView.CustomView ?? true)
                {
                    bLL_UserView.SortOrder = _UserViewRepository.GetNextSortOrder(UserIdentity.UserId, bLL_UserView.ScreenName);
                }

                grs_TblUserview tbUserView = new grs_TblUserview();
                AssignDefaults(tbUserView, bLL_UserView);

                var userview = _UserViewRepository.Get(d => d.Userid == tbUserView.Userid &&
                                                       d.Screenname == tbUserView.Screenname &&
                                                       d.Viewname == tbUserView.Viewname);

                if (!(userview == null))
                {
                    throw new IllegalArgumentAPIException(string.Format("User view already exists with combination of screen '{0}' and view '{1}'", tbUserView.Screenname, tbUserView.Viewname));
                }

                if (bLL_UserView.Default ?? false) //reset existing then update default column
                {
                    _UserViewRepository.FindBy(d => d.Userid == UserIdentity.UserId &&
                                               d.Screenname == bLL_UserView.ScreenName && d.Default).ToList().ForEach(v => v.Default = false);
                    tbUserView.Default = true;
                }

                _UserViewRepository.Add(tbUserView);
                _UserViewRepository.Save(tbUserView);

                return(new EntityResult <BLL_UserView>(_UserViewTransformationManager.Transform(_UserViewRepository.Get(d => d.ViewId == tbUserView.ViewId))));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void SetupUserViewRepository(out Mock <IUserViewRepository> userViewRepository)
        {
            //Create mock repository
            userViewRepository = new Mock <IUserViewRepository>();

            //Build response
            var userViewDataList = new List <grs_TblUserview> {
                new grs_TblUserview()
                {
                    ViewId     = 101,
                    Userid     = 100,
                    Default    = false,
                    Screenname = "GRS.UW_Workbench",
                    Viewname   = "mysubmissions",
                    Layout     = "SomeJason",
                    Customview = false,
                    Sortorder  = 1
                }
            };

            var userViewData = new grs_TblUserview()
            {
                ViewId     = 101,
                Userid     = 100,
                Default    = false,
                Screenname = "GRS.UW_Workbench",
                Viewname   = "mysubmissions",
                Layout     = "SomeJason",
                Customview = false,
                Sortorder  = 1
            };

            //            userviewRepository.Setup(p => p.ExecuteQuery(It.IsAny<string>())).Returns(userViewDataList);
            userViewRepository.Setup(p => p.Get(It.IsAny <Expression <Func <grs_TblUserview, bool> > >())).Returns(userViewData);
            userViewRepository.Setup(p => p.Save(It.IsAny <grs_TblUserview>(), false));
            userViewRepository.Setup(p => p.Add(It.IsAny <grs_TblUserview>()));
        }
 private void OnApplyChangesForStaus(grs_TblUserview currentView, BLL_UserViewDelete newEntity)
 {
     currentView.Default = true;
 }
        public void UserViewController_Post_Returns_Created(UserView userViews)
        {
            #region Arrange

            SetupUserIdentity();
            userViewRepository = new Mock <IUserViewRepository>();
            //SetupUserViewRepository(out Mock<IUserViewRepository> userviewsRepository);

            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPPOST), $"{AppSettings.BASEURL}{RouteHelper.UserviewRoutePrefix}");
            UserViewController userviewController = CreateUserViewController(httpRequest, userViewRepository.Object, userViewScreenRepository.Object);

            var userviewdata = new grs_TblUserview()
            {
                ViewId     = 101,
                Userid     = 100,
                Default    = false,
                Screenname = "GRS.UW_Workbench",
                Viewname   = "mysubmissions",
                Layout     = "SomeJason",
                Customview = false,
                Sortorder  = 1
            };

            grs_TblUserview nullData = null;
            userViewRepository.SetupSequence(p => p.Get(It.IsAny <Expression <Func <grs_TblUserview, bool> > >()))
            .Returns(nullData)
            .Returns(userviewdata);

            #endregion

            #region Act

            var response = userviewController.Post(userViews);

            #endregion

            #region Expected Data

            var expectedUserViewdata =
                new UserView()
            {
                ViewId     = 101,
                UserId     = 100,
                Default    = false,
                ScreenName = "GRS.UW_Workbench",
                ViewName   = "mysubmissions",
                Layout     = "SomeJason",
                CustomView = false,
                SortOrder  = 1
            };

            #endregion

            #region Assert
            var contentResult = response as NegotiatedContentResult <ResponseItem <UserView> >;
            Assertions.AssertCreatedResponse(contentResult);
            var usrViewData = contentResult.Content.data;

            //Data
            var actualUserViewdata = usrViewData;
            Assertions.AssertData(expectedUserViewdata, actualUserViewdata);


            //Links & Messages
            //  Assert.IsEmpty(contentResult.Content.links);
            Assert.IsEmpty(contentResult.Content.messages);
            #endregion
        }
        public void UserViewController_Put_Returns_OkCode(UserView userveiws)
        {
            #region Arrange
            SetupUserIdentity();

            SetupUserViewRepository(out Mock <IUserViewRepository> userViewRepository);

            var usrViewRepository = new Mock <IUserViewRepository>();

            #endregion
            #region Act

            var usrViewDbData = new grs_TblUserview()
            {
                ViewId     = 46,
                Userid     = 4896,
                Default    = false,
                Screenname = "GRS.UW_Workbench",
                Viewname   = "mysubmissions",
                Layout     = "SomeJason",
                Customview = false,
                Sortorder  = 1
            };

            usrViewRepository.Setup(p => p.Get(It.IsAny <Expression <Func <grs_TblUserview, bool> > >())).Returns(usrViewDbData);
            usrViewRepository.Setup(p => p.Get(46)).Returns(usrViewDbData);

            var             httpRequest     = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPPOST), $"{AppSettings.BASEURL}{RouteHelper.UserviewRoutePrefix}");
            UserViewManager UserViewManager = new UserViewManager(userManager.Object, cacheStoreManager.Object, mockLogManager.Object, usrViewRepository.Object, transformationManager);

            UserPreferencesAPIManager userViewAPIManager = new UserPreferencesAPIManager(userManager.Object, cacheStoreManager.Object, mockLogManager.Object, UserViewManager);

            UserViewController userviewController = new UserViewController(userManager.Object, userViewAPIManager)
            {
                Request       = httpRequest,
                Configuration = new HttpConfiguration()
            };


            #endregion

            #region Act

            var response = userviewController.Put(userveiws.ViewId, userveiws);

            #endregion

            #region Expected Data

            var expectedUserViewdata = new UserView()
            {
                ViewId     = 46,
                UserId     = 4896,
                Default    = false,
                ScreenName = "GRS.UW_Workbench",
                ViewName   = "mysubmissions",
                Layout     = "SomeJason",
                CustomView = false,
                SortOrder  = 1
            };

            #region Assert
            var contentResult = response as NegotiatedContentResult <ResponseItem <UserView> >;

            Assertions.AssertOkResponse(contentResult);
            var usrViewData = contentResult.Content.data;

            //Data
            var actualUserViewdata = usrViewData;
            Assertions.AssertData(expectedUserViewdata, actualUserViewdata);

            //Links & Messages
            //  Assert.IsEmpty(contentResult.Content.links);
            Assert.IsEmpty(contentResult.Content.messages);
            #endregion
        }