public ListModel SaveList(UserProfile user, UserSelectedContext catalogInfo, ListModel list)
        {
            FavoritesListHeader header = _headerRepo.GetFavoritesList(user.UserId, catalogInfo);

            if (header == null)
            {
                foreach (var item in list.Items)
                {
                    FavoritesListDetail detail = item.ToFavoritesListDetail(0);
                    detail.Active = !item.IsDelete;
                    Save(user, catalogInfo, detail);
                }
            }
            else
            {
                foreach (var item in list.Items)
                {
                    FavoritesListDetail detail = item.ToFavoritesListDetail(header.Id);
                    detail.Active = !item.IsDelete;
                    Save(user, catalogInfo, detail);
                }
            }

            return(GetFavoritesList(user.UserId, catalogInfo, false));
        }
        public void Save(UserProfile user, UserSelectedContext catalogInfo, FavoritesListDetail model)
        {
            // try to find the parent header id if it is not in the model
            if (model.HeaderId == 0)
            {
                FavoritesListHeader header = _headerRepo.GetFavoritesList(user.UserId, catalogInfo);

                if (header == null)
                {
                    // create the header
                    model.HeaderId = _headerRepo.SaveFavoriteListHeader(new FavoritesListHeader()
                    {
                        BranchId       = catalogInfo.BranchId,
                        CustomerNumber = catalogInfo.CustomerId,
                        UserId         = user.UserId
                    });
                }
                else
                {
                    model.HeaderId = header.Id;
                }
            }

            _detailRepo.SaveFavoriteListDetail(model);
        }
        public static ListModel ToListModel(this FavoritesListHeader header, List <ListItemModel> items)
        {
            ListModel retVal = header.ToListModel();

            retVal.Items = items.OrderBy(l => l.Position)
                           .ToList();
            return(retVal);
        }
Beispiel #4
0
        public long SaveFavoriteListHeader(FavoritesListHeader model)
        {
            DynamicParameters parms = new DynamicParameters();

            parms.Add(PARMNAME_BRANCH, model.BranchId);
            parms.Add(PARMNAME_CUSTID, model.CustomerNumber);
            parms.Add(PARMNAME_USERID, model.UserId);

            return(ExecuteScalarSPCommand <long>(SPNAME_SAVE, parms));
        }
Beispiel #5
0
            public void InitializedHeader_HasDefaultValue()
            {
                // arrange
                FavoritesListHeader test = new FavoritesListHeader();

                // act

                // assert
                test.UserId
                .Should()
                .BeNull();
            }
Beispiel #6
0
            public void GoodHeader_ReturnsExpectedValue()
            {
                // arrange
                FavoritesListHeader fakeHeader = MakeHeader();
                Guid expected = new Guid("a08bb907-ab8e-4e56-9f22-b94b3d6a08e3");

                // act

                // assert
                fakeHeader.UserId
                .Should()
                .Be(expected);
            }
        public static ListModel ToListModel(this FavoritesListHeader header, List <FavoritesListDetail> items)
        {
            ListModel retVal = header.ToListModel();

            if (items != null)
            {
                retVal.Items = items.Select(i => i.ToWebModel())
                               .OrderBy(l => l.Position)
                               .ToList();
            }

            return(retVal);
        }
Beispiel #8
0
            public void GoodHeader_ItemsIsNull()
            {
                // arrange
                FavoritesListHeader header = MakeHeader();

                // act
                ListModel results = header.ToListModel();

                // assert
                results.Items
                .Should()
                .BeNull();
            }
Beispiel #9
0
            public void GoodHeader_ReturnsExpectedCustomerNumber()
            {
                // arrange
                FavoritesListHeader header = MakeHeader();
                string expected            = "SEWRLD";

                // act
                ListModel results = header.ToListModel();

                // assert
                results.CustomerNumber
                .Should()
                .Be(expected);
            }
Beispiel #10
0
            public void GoodHeader_ReturnsExpectedIsFavoriteList()
            {
                // arrange
                bool expected = true;
                FavoritesListHeader header = MakeHeader();

                // act
                ListModel results = header.ToListModel();

                // assert
                results.IsFavorite
                .Should()
                .Be(expected);
            }
Beispiel #11
0
            public void GoodHeader_ReturnsExpectedListId()
            {
                // arrange
                FavoritesListHeader header = MakeHeader();
                int expected = 21;

                // act
                ListModel results = header.ToListModel();

                // assert
                results.ListId
                .Should()
                .Be(expected);
            }
Beispiel #12
0
            public void GoodHeader_ItemsIsNotNull()
            {
                // arrange
                FavoritesListHeader  header = MakeHeader();
                List <ListItemModel> items  = MakeListOfModels();

                // act
                ListModel results = header.ToListModel(items);

                // assert
                results.Items
                .Should()
                .NotBeNull();
            }
Beispiel #13
0
            public void GoodHeader_ReturnsExpectedBranchId()
            {
                // arrange
                string expected            = "BYE";
                FavoritesListHeader header = MakeHeader();

                // act
                ListModel results = header.ToListModel();

                // assert
                results.BranchId
                .Should()
                .Be(expected);
            }
Beispiel #14
0
            public void GoodHeader_ItemsIsNotNull()
            {
                // arrange
                FavoritesListHeader        header  = MakeHeader();
                List <FavoritesListDetail> details = MakeListOfDetails();

                // act
                ListModel results = header.ToListModel(details);

                // assert
                results.Items
                .Should()
                .NotBeNull();
            }
Beispiel #15
0
            public void GoodHeader_ReturnsExpectedType()
            {
                // arrange
                FavoritesListHeader header   = MakeHeader();
                ListType            expected = ListType.Favorite;

                // act
                ListModel results = header.ToListModel();

                // assert
                results.Type
                .Should()
                .Be(expected);
            }
Beispiel #16
0
            public void GoodHeader_ReturnsExpectedReadonly()
            {
                // arrange
                bool expected = false;
                FavoritesListHeader header = MakeHeader();

                // act
                ListModel results = header.ToListModel();

                // assert
                results.ReadOnly
                .Should()
                .Be(expected);
            }
Beispiel #17
0
            public void GoodHeader_ReturnsExpectedName()
            {
                // arrange
                string expected             = "Favorites";
                FavoritesListHeader  header = MakeHeader();
                List <ListItemModel> items  = MakeListOfModels();

                // act
                ListModel results = header.ToListModel(items);

                // assert
                results.Name
                .Should()
                .Be(expected);
            }
Beispiel #18
0
            public void GoodHeader_ReturnsExpectedIsWorksheet()
            {
                // arrange
                bool expected = false;
                FavoritesListHeader  header = MakeHeader();
                List <ListItemModel> items  = MakeListOfModels();

                // act
                ListModel results = header.ToListModel(items);

                // assert
                results.IsWorksheet
                .Should()
                .Be(expected);
            }
Beispiel #19
0
            public void GoodHeader_ReturnsExpectedIsReminder()
            {
                // arrange
                bool expected = false;
                FavoritesListHeader        header  = MakeHeader();
                List <FavoritesListDetail> details = MakeListOfDetails();

                // act
                ListModel results = header.ToListModel(details);

                // assert
                results.IsReminder
                .Should()
                .Be(expected);
            }
Beispiel #20
0
            public void GoodHeader_TwoItems()
            {
                // arrange
                int expected = 2;
                FavoritesListHeader  header = MakeHeader();
                List <ListItemModel> items  = MakeListOfModels();

                // act
                ListModel results = header.ToListModel(items);

                // assert
                results.Items
                .Count()
                .Should()
                .Be(expected);
            }
        public long CreateList(UserProfile user, UserSelectedContext catalogInfo)
        {
            FavoritesListHeader header = _headerRepo.GetFavoritesList(user.UserId, catalogInfo);

            if (header == null)
            {
                // create the header
                return(_headerRepo.SaveFavoriteListHeader(new FavoritesListHeader()
                {
                    BranchId = catalogInfo.BranchId,
                    CustomerNumber = catalogInfo.CustomerId,
                    UserId = user.UserId
                }));
            }
            else
            {
                return(header.Id);
            }
        }
 public static ListModel ToListModel(this FavoritesListHeader header)
 {
     return(new ListModel()
     {
         CustomerNumber = header.CustomerNumber,
         BranchId = header.BranchId,
         IsContractList = false,
         IsFavorite = true,
         IsWorksheet = false,
         IsReminder = false,
         IsMandatory = false,
         IsRecommended = false,
         IsCustomInventory = false,
         Type = ListType.Favorite,
         ListId = header.Id,
         Name = LISTNAME_FAVORITE,
         ReadOnly = false,
         Items = null
     });
 }
        public ListModel GetFavoritesList(Guid userId, UserSelectedContext catalogInfo, bool headerOnly)
        {
            FavoritesListHeader header = _headerRepo.GetFavoritesList(userId, catalogInfo);

            if (header == null)
            {
                return(null);
            }
            else
            {
                List <FavoritesListDetail> items = null;

                if (!headerOnly)
                {
                    items = _detailRepo.GetFavoritesListDetails(header.Id);
                }

                return(header.ToListModel(items));
            }
        }