private void Load_Data() { ProductTypeService productTypeService = new ProductTypeService(); UnitTypeService unitService = new UnitTypeService(); LanguageService languageService = new LanguageService(); CurrencyService currencyService = new CurrencyService(); CategoryService categoryService = new CategoryService(); TypeBox.ItemsSource = productTypeService.GetAll(); TypeBox.SelectedValuePath = "Id"; TypeBox.DisplayMemberPath = "Name"; TypeBox.SelectedIndex = 0; UnitBox.ItemsSource = unitService.GetUnitTypesByLanguage(2); UnitBox.SelectedValuePath = "Id"; UnitBox.DisplayMemberPath = "Name"; LanguageBox.ItemsSource = languageService.GetAll(); LanguageBox.SelectedValuePath = "Id"; LanguageBox.DisplayMemberPath = "Name"; LanguageBox.SelectedIndex = 0; CurrencyBox.ItemsSource = currencyService.GetAll(); CurrencyBox.SelectedValuePath = "Id"; CurrencyBox.DisplayMemberPath = "Name"; CurrencyBox.SelectedIndex = 0; CategoryBox.ItemsSource = categoryService.GetDefaultCategories(2); CategoryBox.SelectedValuePath = "Id"; CategoryBox.DisplayMemberPath = "Name"; }
public void TestGetAllManyCurrencies() { ILoggerFactory loggerFactory = new LoggerFactory(); using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyFactory = new CurrencyFactory(); var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true); var gbpCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Gbp, false); currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity); currencyFactory.Add(sqliteMemoryWrapper.DbContext, gbpCurrencyEntity); var currencyService = new CurrencyService(loggerFactory, sqliteMemoryWrapper.DbContext); List <Currency> currencies = currencyService.GetAll().ToList(); Assert.AreEqual(2, currencies.Count); Assert.AreEqual(usdCurrencyEntity.Name, currencies[0].Name); Assert.AreEqual(usdCurrencyEntity.ShortName, currencies[0].ShortName); Assert.AreEqual(usdCurrencyEntity.Symbol, currencies[0].Symbol); Assert.AreEqual(usdCurrencyEntity.IsPrimary, currencies[0].IsPrimary); Assert.AreEqual(gbpCurrencyEntity.Name, currencies[1].Name); Assert.AreEqual(gbpCurrencyEntity.ShortName, currencies[1].ShortName); Assert.AreEqual(gbpCurrencyEntity.Symbol, currencies[1].Symbol); Assert.AreEqual(gbpCurrencyEntity.IsPrimary, currencies[1].IsPrimary); } }
/// <inheritdoc /> /// <summary> /// Exports to structure info. /// </summary> /// <param name="packageInfo"> The package info. </param> /// <returns> </returns> public StructureInfo Export(PackageInfo packageInfo) { var languagedMap = _languageService.GetAll().ToDictionary(x => x.SystemId, x => x.CultureInfo.Name); var visitorGroupId = (_groupService.Get <Group>("Visitors") ?? _groupService.Get <Group>("Besökare")).SystemId; var currencies = _currencyService.GetAll().ToList(); var relationTemplates = _fieldTemplateService.GetAll().OfType <Customers.FieldTemplateBase>().ToDictionary(x => x.SystemId, x => x.Id); var website = _websiteStructurePackage.Export(packageInfo); var mediaArchive = _mediaStructurePackage.Export(packageInfo); var productCatalog = _productStructurePackage.Export(packageInfo); var ecommerce = _ecommerceStructurePackage.Export(packageInfo); var structureInfo = new StructureInfo { Foundation = new StructureInfo.FoundationStructure { LanguageMap = languagedMap, VisitorGroupId = visitorGroupId, Currencies = currencies, RelationTemplates = relationTemplates }, Website = website, MediaArchive = mediaArchive, ProductCatalog = productCatalog, ECommerce = ecommerce }; return(structureInfo); }
public ActionResult Create(long?id) { var viewModel = new CustomerViewModel { Currencies = currencyService.GetAll(), Id = id ?? 0 }; return(View(viewModel)); }
// GET: Settings/Default public ActionResult Index() { var viewModel = new DefaultViewModel { Accounts = accountService.GetAll(), Currencies = currencyService.GetAll(), Taxs = taxService.GetAll() }; return(View(viewModel)); }
public void TestGetAllNoCurrencies() { ILoggerFactory loggerFactory = new LoggerFactory(); using (var sqliteMemoryWrapper = new SqliteMemoryWrapper()) { var currencyService = new CurrencyService(loggerFactory, sqliteMemoryWrapper.DbContext); IEnumerable <Currency> currencies = currencyService.GetAll(); Assert.AreEqual(0, currencies.Count()); } }
public ActionResult Create(long?id) { var viewModel = new InvoiceViewModel { Categories = categoryService.GetAll(), Currencies = currencyService.GetAll(), Customers = customerService.GetAll(), Items = itemService.GetAll(), Taxes = taxService.GetAll(), DefaultSetting = defaultService.GetByUserId(LogedInUser.Id), Invoice_Number = id > 0 ? string.Empty : invoiceService.GenerateInvoiceNumber(), Invoice = id > 0 ? invoiceService.GetById(id ?? 0) : new Invoice() }; return(View(viewModel)); }
public ActionResult Create(long?id) { var viewModel = new BillViewModel { Categories = categoryService.GetAll(), Currencies = currencyService.GetAll(), Vendors = vendorService.GetAll(), Items = itemService.GetAll(), Taxes = taxService.GetAll(), DefaultSetting = defaultService.GetByUserId(LogedInUser.Id), Bill = id > 0 ? billService.GetById((long)id) : new Bill { Number = billService.GenerateBillNumber() } }; return(View(viewModel)); }
// GET: User/SingleList public ActionResult SingleList(int?id, int?templateId, int?sortingId) { if (Session["UserId"] != null && id != null) { ViewBag.Message = TempData["SuccessMessage"]; ViewBag.Error = TempData["ErrorMessage"]; ShoppingListService listService = new ShoppingListService(); var userLists = listService.GetListsByUserId(int.Parse(Session["UserId"].ToString())); var requestedList = listService.Get((int)id); //checking whether the list the user tries to access is his or if he has access rights foreach (ShoppingListDto x in userLists) { if (x.Id == requestedList.Id) { SingleListVM list = new SingleListVM { ShoppingList_Id = requestedList.Id }; var listObj = listService.Get(list.ShoppingList_Id, int.Parse(Session["UserId"].ToString())); list.ListName = listObj.Name; list.ListAccessTypeId = listObj.ListAccessTypeId; LanguageService languageService = new LanguageService(); var langId = languageService.GetByCode(Session["LanguageCode"].ToString()).Id; ProductService productService = new ProductService(); list.ListEntries = productService.GetEntriesAsProducts(list.ShoppingList_Id, langId); if (list.ListEntries.Count() == 0) { ViewBag.Message = "You don't have any entries yet. Start creating your entries now!"; } TemplateSortingService templateService = new TemplateSortingService(); UserListSortingService listSortingService = new UserListSortingService(); UserListSortingDto sorting = new UserListSortingDto(); if (listObj.ChosenSortingId != null) { sorting.Id = (int)listObj.ChosenSortingId; } sorting.ShoppingList_Id = list.ShoppingList_Id; if (listObj.ChosenSortingId != null) { list.ListEntries = listSortingService.ApplyUserSorting((int)listObj.ChosenSortingId, list.ListEntries); } if (templateId != null) { list.ListEntries = templateService.SortByTemplate((int)templateId, list.ListEntries); listSortingService.SaveSorting(sorting, list.ListEntries); ViewBag.Message = "Your list has been sorted according to the template. This sorting has been saved permanently for you."; } else if (sortingId != null) { switch ((int)sortingId) { case 1: // A - Z { list.ListEntries = list.ListEntries.OrderBy(z => z.Name).ToList(); listSortingService.SaveSorting(sorting, list.ListEntries); break; } case 2: // Z - A { list.ListEntries = list.ListEntries.OrderByDescending(z => z.Name).ToList(); listSortingService.SaveSorting(sorting, list.ListEntries); break; } case 3: // lowest price { list.ListEntries = list.ListEntries.OrderBy(z => z.Price).ToList(); listSortingService.SaveSorting(sorting, list.ListEntries); break; } case 4: // highest price { list.ListEntries = list.ListEntries.OrderByDescending(z => z.Price).ToList(); listSortingService.SaveSorting(sorting, list.ListEntries); break; } default: break; } } list.ChosenProductId = 0; //By default no defaultProduct should be selected list.ChooseProductsList = (from item in productService.GetDefaultAndReusableProductsByLanguage(langId) select new SelectListItem() { Text = item.Name, Value = item.ProductId.ToString() }).ToList(); UnitTypeService unitTypeService = new UnitTypeService(); list.UnitTypesListId = 8; //default value: pc. list.UnitTypesList = (from item in unitTypeService.GetUnitTypesByLanguage(langId) select new SelectListItem() { Text = item.Name, Value = item.Id.ToString() }).ToList(); CurrencyService currencyService = new CurrencyService(); list.CurrencyListId = 5; //default DKK list.CurrencyList = (from item in currencyService.GetAll() select new SelectListItem() { Text = item.Code, Value = item.Id.ToString() }).ToList(); CategoryService categoryService = new CategoryService(); list.CategoryListId = 20; //default category: others list.CategoryList = (from item in categoryService.GetAllCategories(langId, int.Parse(Session["UserId"].ToString())) select new SelectListItem() { Text = item.Name, Value = item.Id.ToString() }).ToList(); list.ChosenTemplateId = 0; list.Templates = (from item in templateService.GetTemplates() select new SelectListItem() { Text = item.TemplateName, Value = item.Id.ToString() }).ToList(); return(View(list)); } } TempData["ErrorMessage"] = "The list you tried to access isn't yours!!"; return(RedirectToAction("Lists", "List")); } else { return(RedirectToAction("Login", "User")); } }
//[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult SaveSorting(FormCollection collection) //{ // try // { // var listId = int.Parse(collection["ShoppingList_Id"]); // var sortingName = collection["SortingName"]; // var listEntries = collection["listEntries"]; // UserListSortingService listSortingService = new UserListSortingService(); // ShoppingListService listService = new ShoppingListService(); // UserListSortingDto sortingDto = new UserListSortingDto // { // Id = (int)listService.Get(listId).ChosenSortingId, // UserSortingName = sortingName, // ShoppingList_Id = listId // }; // listSortingService.SaveSorting(sortingDto, listEntries); // TempData["SuccessMessage"] = "Saved this sorting successfully."; // return RedirectToAction("SingleList", "List", new { @id = listId }); // } // catch // { // TempData["ErrorMessage"] = "Saving this sorting wasn't possible."; // return RedirectToAction("SingleList"); // } //} #endregion Sorting #region Items //GET List/Item -> EditItemView public ActionResult Item(int?id, int?listId) { if (Session["UserId"] != null) { ViewBag.Message = TempData["SuccessMessage"]; ViewBag.Error = TempData["ErrorMessage"]; ItemsVM item = new ItemsVM { ListId = (int)listId, ProductId = (int)id }; LanguageService languageService = new LanguageService(); var langId = languageService.GetByCode(Session["LanguageCode"].ToString()).Id; ProductService productService = new ProductService(); var entry = productService.Get(langId, (int)id, (int)listId); //Gets productDto by langId(for translation if default or api product) and ProductId item.Id = entry.Id; item.Name = entry.Name; item.Price = entry.Price; item.Quantity = Convert.ToUInt32(entry.Quantity); item.Unit_Id = entry.Unit_Id; item.Currency_Id = entry.Currency_Id; item.Category_Id = entry.Category_Id; item.ProductTypeId = entry.ProductTypeId; UnitTypeService unitTypeService = new UnitTypeService(); item.UnitTypesListId = item.Unit_Id; //saved value from db entry item.UnitTypesList = (from x in unitTypeService.GetUnitTypesByLanguage(langId) select new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); CurrencyService currencyService = new CurrencyService(); item.CurrencyListId = item.Currency_Id; //saved value from db entry item.CurrencyList = (from x in currencyService.GetAll() select new SelectListItem() { Text = x.Code, Value = x.Id.ToString() }).ToList(); CategoryService categoryService = new CategoryService(); if (item.Category_Id == null) { item.CategoryListId = 0; } else { item.CategoryListId = (int)item.Category_Id; //saved value from db entry } if (item.ProductTypeId == 1) //if deafult product -> only show UserCategories { item.CategoryList = (from x in categoryService.GetUserCategories(langId, int.Parse(Session["UserId"].ToString())) select new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); } else { item.CategoryList = (from x in categoryService.GetAllCategories(langId, int.Parse(Session["UserId"].ToString())) select new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); } return(View(item)); } else if (id == 0 || listId == 0) { TempData["ErrorMessage"] = "There is no item of a specific list selected to edit."; return(Redirect(Request.UrlReferrer.ToString())); } else { return(RedirectToAction("Login", "User")); } }