Ejemplo n.º 1
0
        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";
        }
Ejemplo n.º 2
0
 public ProjectsController(FileService fileService, ProjectService projectService, LocationService locationService, ProjectTypeService projectTypeService, PropertyTypeService propertyTypeService, UnitTypeService unitTypeService)
 {
     _fileService         = fileService;
     _projectService      = projectService;
     _locationService     = locationService;
     _projectTypeService  = projectTypeService;
     _propertyTypeService = propertyTypeService;
     _unitTypeService     = unitTypeService;
 }
Ejemplo n.º 3
0
        // 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"));
            }
        }
Ejemplo n.º 4
0
        //[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"));
            }
        }