コード例 #1
0
        public async System.Threading.Tasks.Task <IActionResult> Single(int?apartmentId)
        {
            if (apartmentId == null)
            {
                return(NotFound());
            }

            // get apartment
            Apartment apartment = await apartmentRepository.GetAsync(apartmentId.Value);

            if (apartment == null)
            {
                return(NotFound());
            }

            // get current user id
            int loggedUserId = this.GetClaim <int>(nameof(DataAccess.Entities.User.Id));

            SingleViewModel singleViewModel = new SingleViewModel()
            {
                UserId         = loggedUserId,
                Apartment      = apartment,
                IsRenter       = apartmentRepository.IsRenter(apartmentId.Value, loggedUserId),
                HasUserRequest = apartmentRepository.HasRequest(loggedUserId, apartmentId.Value),
            };

            return(View(singleViewModel));
        }
コード例 #2
0
        private void UpdateGenres(SingleViewModel recordToUpdate)
        {
            List <string> splitGenres = recordToUpdate.genreName?.Split(',').ToList() == null ? new List <string>() : recordToUpdate.genreName?.Split(',').ToList();

            foreach (string genre in splitGenres)
            {
                int    genreId;
                string neatGenre = genre.Trim().ToLower();

                List <Genres> genres = _connection.Table <Genres>().Where(g => g.GenreName == neatGenre).ToList();

                if (genres.Count == 0)
                {
                    genreId = InsertGenre(neatGenre);
                }
                else
                {
                    genreId = genres.First().GenreId;
                }

                List <SingleGenres> singleGenres = _connection.Table <SingleGenres>().Where(sg => sg.SingleId == recordToUpdate.singleId && sg.GenreId == genreId).ToList();

                if (singleGenres.Count == 0)
                {
                    InsertSingleGenre(recordToUpdate.singleId, genreId);
                }
            }
        }
コード例 #3
0
        internal void RemoveSingleFromCollection(SingleViewModel singleToRemove)
        {
            int     artistId       = GetArtistId(singleToRemove);
            Singles recordToRemove = MapSingleData(singleToRemove, artistId);

            _connection.Delete(recordToRemove);
        }
コード例 #4
0
        public ActionResult Single(SingleViewModel model)
        {
            // Repopulate grid
            model.Claims = ExampleMapper.ToClaimViewModelList(UserService.Identity.Claims.AsEnumerable());

            if (model.SelectedKey != null)
            {
                // Reapply row selections based on matching [Key]
                model.Claims.ForEach(c => { if (model.SelectedKey == c.HashKey)
                                            {
                                                c.Selected = true;
                                            }
                                     });

                // Get selected row
                var claim = model.Claims.FirstOrDefault(c => c.HashKey == model.SelectedKey);

                if (claim != null)
                {
                    model.Selections = new ContentViewModel().AddParagraph("You selected claim type '{0}' which has a value of '{1}'.", claim.ClaimType, claim.Value);
                }
            }

            return(View(model));
        }
コード例 #5
0
        public async void Single_ViewResult()
        {
            // Arrange
            int       userId = 1, apartmentId = 1;
            bool      isRenter = true, hasRequest = false;
            Apartment apartment = new Apartment {
                Id = 1
            };

            Mock <ApartmentRepository> mockApartmentRepository = new Mock <ApartmentRepository>();

            mockApartmentRepository
            .Setup(ar => ar.GetAsync(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(Task.FromResult(apartment));
            mockApartmentRepository
            .Setup(ar => ar.IsRenter(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(isRenter);
            mockApartmentRepository
            .Setup(ar => ar.HasRequest(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(hasRequest);

            Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork
            .Setup(u => u.GetRepository <Apartment, ApartmentRepository>())
            .Returns(mockApartmentRepository.Object);

            ControllerBase controller = new ApartmentsController(mockUnitOfWork.Object);

            Mock <ClaimsPrincipal> userMock = new Mock <ClaimsPrincipal>();

            userMock
            .Setup(p => p.FindFirst(It.IsAny <string>()))
            .Returns(new Claim(nameof(User.Id), userId.ToString()));

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = userMock.Object
                }
            };

            // Act
            IActionResult result = await(controller as ApartmentsController)?.Single(apartmentId);

            // Assert
            Assert.NotNull(result);
            ViewResult viewResult = Assert.IsType <ViewResult>(result);

            Assert.NotNull(viewResult.Model);
            SingleViewModel singleViewModel = Assert.IsType <SingleViewModel>(viewResult.Model);

            Assert.Equal(userId, singleViewModel.UserId);
            Assert.Same(apartment, singleViewModel.Apartment);
            Assert.Equal(isRenter, singleViewModel.IsRenter);
            Assert.Equal(hasRequest, singleViewModel.HasUserRequest);
            Assert.Null(viewResult.ViewName);
        }
コード例 #6
0
        internal int AddSingleToCollection(SingleViewModel recordToAdd)
        {
            int     artistId    = GetArtistId(recordToAdd);
            Singles singleToAdd = MapSingleData(recordToAdd, artistId);

            _connection.Insert(singleToAdd);
            return(_connection.ExecuteScalar <int>("SELECT LAST_INSERT_ROWID()"));
        }
コード例 #7
0
        internal void UpdateSingle(SingleViewModel recordToUpdate)
        {
            int     artistId       = GetArtistId(recordToUpdate);
            Singles singleToChange = MapSingleData(recordToUpdate, artistId);

            UpdateGenres(recordToUpdate);
            _connection.Update(singleToChange);
        }
コード例 #8
0
        public ActionResult Single()
        {
            var model = new SingleViewModel();

            // Populate
            model.Claims = ExampleMapper.ToClaimViewModelList(UserService.Identity.Claims.AsEnumerable());//MappingEngine.Map<IEnumerable<ClaimViewModel>>(UserService.Identity.Claims.AsEnumerable());

            return(View(model));
        }
コード例 #9
0
        public IActionResult Index(string l)
        {
            ViewBag.Location = l;

            var model = new SingleViewModel
            {
            };

            return(View(model));
        }
コード例 #10
0
        public async Task <IActionResult> Single(string?id)
        {
            var task = await toDoService.GetTaskAsync(id);

            var viewModel = new SingleViewModel
            {
                Task = task,
            };

            return(View(viewModel));
        }
コード例 #11
0
        private void TextBlock_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            SingleViewModel singleToDelete = (SingleViewModel)((TextBlock)sender).Tag;

            MessageBoxResult deleteResult = MessageBox.Show(string.Format("Are you sure you want to delete {0} by {1}?\n\nIt will also be removed from any jukebox selections you have made.", singleToDelete.aSideTitle, singleToDelete.artistName), "Delete Single", MessageBoxButton.YesNo);

            if (deleteResult == MessageBoxResult.Yes)
            {
                viewModel.RemoveFromCollection(singleToDelete);
            }
        }
コード例 #12
0
ファイル: HomeController.cs プロジェクト: nexlukic/Blog
        public ActionResult Single(int id)
        {
            OpSelectOnePost op = new OpSelectOnePost();

            op.id = id;
            ResultOperation postOne = manager.ExecuteOperation(op);
            SingleViewModel vm      = new SingleViewModel
            {
                post = (postOne.items as PostDto[]).ToList()
            };

            return(View(vm));
        }
コード例 #13
0
        private int GetArtistId(SingleViewModel recordToUpdate)
        {
            List <Artists> artists = _connection.Table <Artists>().Where(a => a.ArtistName == recordToUpdate.artistName).ToList();

            if (artists.Count == 0)
            {
                return(InsertArtist(recordToUpdate.artistName));
            }
            else
            {
                return(artists.First().ArtistId);
            }
        }
コード例 #14
0
        private Singles MapSingleData(SingleViewModel recordToUpdate, int artistId)
        {
            Singles singleToChange = new Singles()
            {
                SingleId           = recordToUpdate.singleId,
                ASideTitle         = recordToUpdate.aSideTitle,
                BSideTitle         = recordToUpdate.bSideTitle,
                SingleYear         = recordToUpdate.singleYear,
                Dinked             = recordToUpdate.dinked,
                JukeboxCardPrinted = recordToUpdate.jukeboxCardPrinted,
                PictureCover       = recordToUpdate.pictureCover,
                SingleLabelPrinted = recordToUpdate.singleLabelPrinted,
                ArtistId           = artistId
            };

            return(singleToChange);
        }
コード例 #15
0
        public ActionResult Index(int id)
        {
            ViewBag.BredCrumbs = _productRepository.GetBreadCrumbs(id);

            var viewModel = new SingleViewModel()
            {
                Product         = _productRepository.Get(id),
                RelatedProducts = _productRepository.RelatedProducts(id)
            };

            _productRepository.EnhancementPopularField(id);

            //var existColer=viewModel.Product.Categories.e

            var category = viewModel.Product.Categories.FirstOrDefault();

            if (category != null)
            {
                var cat = _categoryRepository.Get(category.Id);
                ViewBag.Recommendations = cat.Recommendations;
                ViewBag.IsFromParent    = _categoryRepository.IsChildFromParent(category.Id, 1344);
            }
            else
            {
                ViewBag.IsFromParent = false;
            }

            ViewBag.MetaTitle   = viewModel.Product.Seo != null? viewModel.Product.Seo.MetaTitle : viewModel.Product.Title;
            ViewBag.Keywords    = viewModel.Product.Seo != null ? viewModel.Product.Seo.MetaKeywords : null;
            ViewBag.Description = viewModel.Product.Seo != null ? viewModel.Product.Seo.MetaDescription : null;
            ViewBag.Shipping    = _globalOptionRepository.Get("shipping").OptionContent;
            bool WillBeAddedFlag   = viewModel.Product.TypeStatusProduct == Common.TypeStatusProduct.WillBeAdded;
            bool willbeRelatedFlag = viewModel.RelatedProducts.Any(i => i.TypeStatusProduct == Common.TypeStatusProduct.WillBeAdded);

            WillBeAddedFlag         = willbeRelatedFlag || willbeRelatedFlag;
            ViewBag.WillBeAddedFlag = WillBeAddedFlag;
            if (WillBeAddedFlag)
            {
                ViewBag.WillBeAddedFlagText = _globalOptionRepository.Get("footnote");
            }
            return(View(viewModel));
        }
コード例 #16
0
        public ActionResult Single(int?Id)
        {
            if (Id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Advert          adv    = (from a in ent.Adverts where a.Id == Id select a).FirstOrDefault();
            ApplicationUser Seller = (from u in ent.Users where u.Id == adv.SellerId select u).FirstOrDefault();
            SingleViewModel model  = new SingleViewModel();

            model.Color          = adv.Color;
            model.CreateDate     = adv.CreateDate;
            model.Description    = adv.Description;
            model.Image1         = adv.Image1;
            model.Image2         = adv.Image2;
            model.Image3         = adv.Image3;
            model.Price          = adv.Price;
            model.ProductName    = adv.ProductName;
            model.SellerId       = Seller.Id;
            model.SellerUserName = Seller.UserName;
            model.Views          = adv.Views;
            model.Warranty       = adv.Warranty;
            if (Id == 0)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                try
                {
                    adv.Views += 1;
                    ent.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }

                return(View(model));
            }
        }
コード例 #17
0
        public ActionResult Category(int id, int?p, int?commend, int?f, string order)
        {
            var category   = MyService.GetCategoryById(id);
            var currenturl = WebUtils.GetCateUrl(category);
            var webPath    = MyService.GetCategoryPathUrl(category.Path);
            var pager      = new Pager {
                PageNo = p ?? 1
            };

            switch (category.Type)
            {
            case 2:
                var re = MyService.GetVArticles(0, id, 0);
                if (re.Any())
                {
                    var varticle        = re.ToList()[0];
                    var singleViewModel = new SingleViewModel
                    {
                        WebTitle    = category.CateName,
                        WebPath     = webPath,
                        CurrentUrl  = currenturl,
                        ArticleInfo = varticle,
                        Category    = category
                    };
                    return(View(WebUtils.GetViewName(category.CustomView, "Single"), singleViewModel));
                }
                return(View("Error"));

            case 4:
                var albumsViewModel = new AlbumsViewModel
                {
                    WebTitle   = category.CateName,
                    WebPath    = webPath,
                    CurrentUrl = currenturl,
                    Category   = category,
                    Albums     = MyService.GetAlbums(id),
                };
                return(View(WebUtils.GetViewName(category.CustomView, "Albums"), albumsViewModel));

            case 6:
                var note = new NoteModel
                {
                    CategoryId = id,
                    NoteId     = 0,
                    DataType   = 1,
                    UserId     = UserInfo == null ? 0 : UserInfo.userid,
                    UserName   = UserInfo == null ? string.Empty : UserInfo.username
                };
                pager.PageSize = Configinfo.NotePagerCount;
                var orderType = string.IsNullOrEmpty(order) ? "desc" : order;
                if (f != null && f > 0)
                {
                    pager = MyService.GetFloorNoteByOrderId(pager, id, (long)f, orderType);
                }
                else
                {
                    pager = MyService.GetFloorNotePaging(pager, id, orderType);
                }
                var noteViewModel = new NoteViewModel
                {
                    WebTitle   = category.CateName,
                    WebPath    = webPath,
                    CurrentUrl = currenturl,
                    Note       = note,
                    NoteList   = new NoteListViewModel {
                        NotePagerInfo = pager
                    },
                    NoteOrderType = orderType,
                    Category      = category
                };
                return(View(WebUtils.GetViewName(category.CustomView, "Note"), noteViewModel));

            default:
                var iscommend = commend ?? 0;
                pager.PageSize = Configinfo.CatePagerCount;
                pager          = category.SubCount > 0
                        ? MyService.GetArticlePaging(pager, 0, id, MyService.GetCategoryIds(id), iscommend, order)
                        : MyService.GetArticlePaging(pager, 0, id, iscommend, order: order, articleListType: "category");
                var categoryViewModel = new CategoryViewModel
                {
                    WebTitle         = category.CateName,
                    WebPath          = webPath,
                    CurrentUrl       = currenturl,
                    IsCommend        = iscommend,
                    CateId           = id,
                    ArticlePagerInfo = pager,
                    Category         = category
                };
                var articleListParasInfo = new AjaxArticleListParamsModel
                {
                    ArticleListType = "category",
                    CategoryId      = id,
                    Commend         = iscommend,
                    Order           = order
                };
                ViewBag.ArticleListParasInfo = articleListParasInfo;
                return(View(WebUtils.GetViewName(category.CustomView, "Category"), categoryViewModel));
            }
        }