public void VerifyThatWhenCategoryIsUpdateViewModelIsUpdate() { var name = "name"; var shortname = "shortname"; var containerRdl = "containerrdl"; var category = new Category(Guid.NewGuid(), null, null) { ShortName = shortname, Name = name }; var container = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null) { ShortName = "containerrdl" }; container.DefinedCategory.Add(category); this.rowViewModel = new CategoryRowViewModel(category, this.session.Object, null); category.Name = "updated name"; category.ShortName = "updated shortname"; container.ShortName = "updated containerrdl"; // workaround to modify a read-only field var type = category.GetType(); type.GetProperty("RevisionNumber").SetValue(category, 50); CDPMessageBus.Current.SendObjectChangeEvent(category, EventKind.Updated); Assert.AreEqual("updated shortname", this.rowViewModel.ShortName); Assert.AreEqual("updated name", this.rowViewModel.Name); Assert.AreEqual("updated containerrdl", this.rowViewModel.ContainerRdl); }
public PartialViewResult GetSubscribedCategories() { var viewModel = new List <CategoryRowViewModel>(); using (UnitOfWorkManager.NewUnitOfWork()) { var categories = LoggedOnUser.CategoryNotifications.Select(x => x.Category); foreach (var category in categories) { var permissionSet = RoleService.GetPermissions(category, UsersRole); var topicCount = category.Topics.Count; var latestTopicInCategory = category.Topics.OrderByDescending(x => x.LastPost.DateCreated).FirstOrDefault(); var postCount = (category.Topics.SelectMany(x => x.Posts).Count() - 1); var model = new CategoryRowViewModel { Category = category, LatestTopic = latestTopicInCategory, Permissions = permissionSet, PostCount = postCount, TopicCount = topicCount }; viewModel.Add(model); } } return(PartialView(viewModel)); }
private void AddChildrenList(ObservableCollection <CategoryRowViewModel> targetList, Predicate <Category> filter, int deep, NamingModes mode, CategoryRowViewModel parentRow, Category source) { foreach (var item in source.ChildrenCategories.OrderBy(x => x.Name)) { if (filter != null && !filter(item)) { continue; } CategoryRowViewModel crvm = new CategoryRowViewModel(); crvm.Id = item.Id; crvm.Level = parentRow.Level + 1; switch (mode) { case NamingModes.FullName: crvm.Name = parentRow.Name + ":" + item.Name; break; case NamingModes.SimpleName: crvm.Name = item.Name; break; default: break; } targetList.Add(crvm); AddChildrenList(targetList, filter, deep + 1, mode, crvm, item); } }
//ITEM COMPLETION PERCENT //public double GetProductCompletionPercent(int prodId) //{ // double result = 0; // using (var context = new RestaurantDBEntities()) // { // result = GetProductCompletionPercent(context.Products.Single(x => x.Id == prodId)); // } // return result; //} //public double GetProductCompletionPercent(Product p) //{ // double totalConditionsCount = 1;//category // double passedConditions = 0; // if (p.CategoryId != null) passedConditions++; // //if (!string.IsNullOrWhiteSpace(p.Description)) passedConditions++; // if (p.ProductType == ProductType.FinishedGoods) // { // totalConditionsCount += 3; // if (p.Code > 0) passedConditions++; // if (p.SalePrice > 0) passedConditions++; // if (p.Ingredients.Count > 0) passedConditions++; // //if (!string.IsNullOrWhiteSpace(p.ProductionProcess)) passedConditions++; // } // else if (p.ProductType == ProductType.WorkInProcess) // { // totalConditionsCount += 1; // if (p.Ingredients.Count > 0) passedConditions++; // //if (p.Outgredients.Count > 0) passedConditions++; // //if (!string.IsNullOrWhiteSpace(p.ProductionProcess)) passedConditions++; // } // else if (p.ProductType == ProductType.RawMaterials) // { // totalConditionsCount += 2; // if (p.ArbitraryCost > 0) passedConditions++; // //if (p.EdiblePart < 1) passedConditions++; // if (p.Outgredients.Count > 0) passedConditions++; // } // else if (p.ProductType == ProductType.CompraVenta) // { // totalConditionsCount += 3; // if (p.Code > 0) passedConditions++; // if (p.SalePrice > 0) passedConditions++; // if (p.ArbitraryCost > 0) passedConditions++; // } // return passedConditions * 100 / totalConditionsCount; //} #endregion #region Category List public void CreateCategoryList(IUnitOfWork unitOfWork, ObservableCollection <CategoryRowViewModel> targetList, NamingModes mode = NamingModes.SimpleName, Predicate <Category> filter = null) { if (targetList == null) { throw new ArgumentException("targetList"); } //targetList.Clear(); //start with root categories var query = from c in unitOfWork.CategoryRepository.Get(x => x.ParentCategory_Id == null) orderby c.Name select c; foreach (var item in query) { if (filter != null && !filter(item)) { continue; } CategoryRowViewModel crvm = new CategoryRowViewModel(); crvm.Id = item.Id; crvm.Name = item.Name; crvm.Level = 0; targetList.Add(crvm); AddChildrenList(targetList, filter, 1, mode, crvm, item); } }
public void Verify_that_EU_properties_are_set_when_rowviewmodel_is_constructed() { var rowViewModel = new CategoryRowViewModel(this.elementUsageCategory, this.elementUsage); Assert.That(rowViewModel.Category, Is.EqualTo(this.elementUsageCategory)); Assert.That(rowViewModel.Name, Is.EqualTo("EUCategory")); Assert.That(rowViewModel.ShortName, Is.EqualTo("EU_CAT")); Assert.That(rowViewModel.SuperCategories, Is.EqualTo("PROD")); Assert.That(rowViewModel.ContainerRdl, Is.EqualTo("Gemeric")); Assert.That(rowViewModel.Level, Is.EqualTo("EU")); }
/// <summary> /// Populate the <see cref="Category"/> instances of the referenced <see cref="ElementDefinition"/> /// </summary> private void PopulateAppliedCategories() { this.AppliedCategories = new List <CategoryRowViewModel>(); foreach (var category in this.Thing.ElementDefinition.Category.OrderBy(x => x.ShortName)) { var categoryRowViewModel = new CategoryRowViewModel(category, this.Thing.ElementDefinition); this.AppliedCategories.Add(categoryRowViewModel); } foreach (var category in this.Thing.Category.OrderBy(x => x.ShortName)) { var categoryRowViewModel = new CategoryRowViewModel(category, this.Thing); this.AppliedCategories.Add(categoryRowViewModel); } }
public void VerifyThatSuperCategoriesAreAsExpected() { var category = new Category(Guid.NewGuid(), null, null); var superCategory_1 = new Category(Guid.NewGuid(), null, null) { ShortName = "supercategory_1" }; var superCategory_2 = new Category(Guid.NewGuid(), null, null) { ShortName = "supercategory_2" }; var container = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null) { ShortName = "containerrdl" }; container.DefinedCategory.Add(category); container.DefinedCategory.Add(superCategory_1); container.DefinedCategory.Add(superCategory_2); this.rowViewModel = new CategoryRowViewModel(category, this.session.Object, null); Assert.AreEqual(string.Empty, this.rowViewModel.SuperCategories); var category_1 = new Category(Guid.NewGuid(), null, null); container.DefinedCategory.Add(category_1); category_1.SuperCategory.Add(superCategory_1); this.rowViewModel = new CategoryRowViewModel(category_1, this.session.Object, null); Assert.AreEqual("{supercategory_1}", this.rowViewModel.SuperCategories); var category_2 = new Category(Guid.NewGuid(), null, null); container.DefinedCategory.Add(category_2); category_2.SuperCategory.Add(superCategory_1); category_2.SuperCategory.Add(superCategory_2); this.rowViewModel = new CategoryRowViewModel(category_2, this.session.Object, null); Assert.AreEqual("{supercategory_1, supercategory_2}", this.rowViewModel.SuperCategories); }
public void VerifyThatStartDragOnCategoryRowReturnsExpectedPayloadAndEffect() { var dragInfo = new Mock <IDragInfo>(); dragInfo.SetupProperty(x => x.Payload); dragInfo.SetupProperty(x => x.Effects); var name = "name"; var shortname = "shortname"; var category = new Category(Guid.NewGuid(), this.assembler.Cache, null) { ShortName = shortname, Name = name }; this.rowViewModel = new CategoryRowViewModel(category, this.session.Object, null); this.rowViewModel.StartDrag(dragInfo.Object); Assert.AreEqual(category, dragInfo.Object.Payload); Assert.AreEqual(DragDropEffects.Copy, dragInfo.Object.Effects); }
public void VerifyThatTheConstructorSetsTheProperties() { var name = "name"; var shortname = "shortname"; var containerRdl = "containerrdl"; var category = new Category(Guid.NewGuid(), null, null) { ShortName = shortname, Name = name }; var container = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null) { ShortName = "containerrdl" }; container.DefinedCategory.Add(category); this.rowViewModel = new CategoryRowViewModel(category, this.session.Object, null); Assert.AreEqual(name, this.rowViewModel.Name); Assert.AreEqual(shortname, this.rowViewModel.ShortName); Assert.AreEqual(containerRdl, this.rowViewModel.ContainerRdl); Assert.AreEqual(string.Empty, this.rowViewModel.SuperCategories); }
public void VerifyThatWhenContainerRdlIsUpdatedViewModelIsUpdated() { var name = "name"; var shortname = "shortname"; var containerRdl = "containerrdl"; var category = new Category(Guid.NewGuid(), this.assembler.Cache, null) { ShortName = shortname, Name = name }; var container = new SiteReferenceDataLibrary(Guid.NewGuid(), this.assembler.Cache, null) { ShortName = containerRdl }; container.DefinedCategory.Add(category); this.rowViewModel = new CategoryRowViewModel(category, this.session.Object, null); Assert.AreEqual(containerRdl, this.rowViewModel.ContainerRdl); container.ShortName = "updated containerrdl"; CDPMessageBus.Current.SendObjectChangeEvent(container, EventKind.Updated); Assert.AreEqual("updated containerrdl", this.rowViewModel.ContainerRdl); }