Ejemplo n.º 1
0
        public ArticleInfo(User user, string title, List <Bookmark> bookmarks = null, List <Reference> references = null)
        {
            this.InfoType = "ArticleInfo";
            Article article = new ArticleRepo().GetFullArticleWithTitle(user, title);

            this.ID              = (int)article.ID;
            this.Title           = article.Title;
            this.Authors         = article.Authors;
            this.Keywords        = article.Keywords;
            this.Year            = article.Year;
            this.FileName        = article.FileName;
            this.PersonalComment = article.PersonalComment;
            this.SIC             = article.SIC;
            this.Bookmarks       = new List <BookmarkInfo>();
            this.References      = new List <ReferenceInfo>();

            if (bookmarks != null)
            {
                bookmarks.ForEach((cur) =>
                {
                    BookmarkInfo info = new BookmarkInfo(cur.Name, user);
                    this.Bookmarks.Add(info);
                });
            }

            if (bookmarks != null)
            {
                references.ForEach((cur) =>
                {
                    ReferenceInfo info = new ReferenceInfo(cur.Name);
                    this.References.Add(info);
                });
            }
        }
Ejemplo n.º 2
0
 public Manager(UserRepo _userGenericRepository,
                AuthorRepo _authorGenericRepository,
                ArticleRepo _articleGenericRepository)
 {
     this._userGenericRepository    = _userGenericRepository;
     this._authorGenericRepository  = _authorGenericRepository;
     this._articleGenericRepository = _articleGenericRepository;
 }
Ejemplo n.º 3
0
 public Manager(UserRepo _userGenericRepository, 
                AuthorRepo _authorGenericRepository, 
                ArticleRepo _articleGenericRepository)
 {
     this._userGenericRepository = _userGenericRepository;
     this._authorGenericRepository = _authorGenericRepository;
     this._articleGenericRepository = _articleGenericRepository;
 }
Ejemplo n.º 4
0
        private async Task SeedArticle()
        {
            var col = await InitCollection <Article>("article");

            var articles = new List <Article>()
            {
                new Article()
                {
                    Code = "XC10<3", Type = "TO", Densite = 8.0f, Prix = 0.75f
                },
                new Article()
                {
                    Code = "XC10>=3", Type = "TO", Densite = 8.0f, Prix = 0.68f
                },
                new Article()
                {
                    Code = "215", Type = "MO", Designation = "Laser Bystronic", TxPrep = 70, TxOpe = 110, TpPrep = 0.0f, TpBase = 0.0f
                },
                new Article()
                {
                    Code = "300", Type = "MO", Designation = "Pliage", TxPrep = 60, TxOpe = 80, TpPrep = 0.0f, TpBase = 0.0f
                },
                new Article()
                {
                    Code = "ARTICLE TEST", Designation = "Designation test", Type = "CH"
                }
            };
            await col.InsertManyAsync(articles);

            var art = await ArticleRepo.GetAsync(art => art.Code == "ARTICLE TEST");

            var nome = await ArticleRepo.GetAsync(art => art.Code == "XC10>=3");

            var ope = await ArticleRepo.GetAsync(art => art.Code == "215");

            var ope1 = await ArticleRepo.GetAsync(art => art.Code == "300");

            art.Nomenclatures = new List <Nomenclature>()
            {
                new Nomenclature()
                {
                    Code = nome.Id, Operation = 10, Quantite = 0.5f
                }
            };
            art.Operations = new List <Operation>()
            {
                new Operation()
                {
                    Code = ope.Id, Ordre = 10, Nombre = 2, TxPrep = ope.TxPrep, TxOpe = ope.TxOpe, TpPrep = ope.TpPrep, TpOpe = ope.TpOpe, BaseOpe = 0.5f
                },
                new Operation()
                {
                    Code = ope1.Id, Ordre = 20, Nombre = 5, TxPrep = ope1.TxPrep, TxOpe = ope1.TxOpe, TpPrep = ope1.TpPrep, TpOpe = ope1.TpOpe, BaseOpe = 0.003f
                }
            };
            await ArticleRepo.UpdateAsync(art);
        }
Ejemplo n.º 5
0
 public Add()
 {
     InitializeComponent();
     articleRepo = new ArticleRepo();
     article     = new Article()
     {
         Reference = Guid.NewGuid().ToString(),
         Prix      = 0,
     };
     PriceTextBox.Text     = "0.00";
     ReferenceTextBox.Text = article.Reference;
 }
Ejemplo n.º 6
0
 public Edit()
 {
     InitializeComponent();
     articleRepo                  = new ArticleRepo();
     article                      = Factures.selectedArticle;
     ReferenceTextBox.Text        = article.Reference;
     DescriptionTextBox.Text      = article.Designation;
     PriceTextBox.Text            = article.Prix.ToString();
     QuantityTextBox.Text         = article.Quantite.ToString();
     InPromotionCheckBox.Checked  = article.Promo.Value;
     DateEndPromotTimePicker.Text = article.DateFinPromo.ToString();
 }
        public async void LoadArticles(object input = null)
        {
            try
            {
                _workStatus(true);

                List <Article> articles = new List <Article>();
                await Task.Run(() =>
                {
                    // 2. Calculate total pages
                    int record_count = new ArticleRepo().GetRecordCount(
                        Users[UserIndex],
                        FilterTitle,
                        FilterAuthors.ToList(),
                        FilterKeywords.ToList(),
                        FilterYear,
                        FilterPersonalComment,
                        SelectedSection);
                    if ((record_count % ItemsPerPage) == 0)
                    {
                        TotalPages = record_count / ItemsPerPage;
                    }
                    else
                    {
                        TotalPages = (record_count / ItemsPerPage) + 1;
                    }

                    CurrentPage = 1;
                });

                await PopulateArticles();

                if (!string.IsNullOrEmpty(SelectedSection) && SelectedSection != "None")
                {
                    this.IsSectionSelected = true;
                }
                else
                {
                    this.IsSectionSelected = false;
                }

                _workStatus(false);
            }
            catch (Exception e)
            {
                new BugTracker().Track("Data View", "Load Articles", e.Message, e.StackTrace);
                _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
            }
            finally
            {
                _workStatus(false);
            }
        }
        public void UpdateArticle(object input)
        {
            try
            {
                ArticleRepo articleRepo = new ArticleRepo();

                // 0. Retrieve old article id so we can track which article was updated
                string oldName = articleRepo.GetArticleTitleWithId((int)Article.ID);
                // 1. Update article record in database
                articleRepo.UpdateArticle(Article, User);

                // 1.1 Track article update
                ArticleInfo info = new ArticleInfo(User, Article.Title);
                new Tracker(User).TrackUpdate <ArticleInfo>(info, oldName);

                // 2. If new file was selected overwrite it to older one
                if (SelectedFile != null)
                {
                    File.Copy(SelectedFile, Path.Combine(Environment.CurrentDirectory, "Files\\") + Article.FileName + ".pdf", true);
                }

                // 3. Copy new article properties to parent's selected article (so that the values will be updated on data grid)
                SelectedArticle.CopyByValue(Article, false, true);
                OnPropertyChanged("SelectedArticle");
            }

            catch (Exception e)
            {
                // Message = "constraint failed\r\nUNIQUE constraint failed: tblArticle.Title"
                if (e.Message.Contains("UNIQUE") && e.Message.Contains("Title"))
                {
                    _dialogService.OpenDialog(new DialogOkViewModel("Article with that name already exists", "Duplicate", DialogType.Warning));
                }
                else
                {
                    new BugTracker().Track("Data View (sub window)", "Update Article", e.Message, e.StackTrace);
                    _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
                }
            }

            // Close window
            (input as ICommand).Execute(null);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            UserRepo userRepo = new UserRepo();
            ArticleRepo articleRepo = new ArticleRepo();
            AuthorRepo authorRepo = new AuthorRepo();

            UserValidator userValidator = new UserValidator();
            ArticleValidator articleValidator = new ArticleValidator();
            AuthorValidator authorValidator = new AuthorValidator();

            userRepo.SetValidator(userValidator);
            articleRepo.SetValidator(articleValidator);
            authorRepo.SetValidator(authorValidator);

            Manager manager = new Manager(userRepo, authorRepo, articleRepo);

            ConsoleUI console = new ConsoleUI(manager);
            console.Run();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            UserRepo    userRepo    = new UserRepo();
            ArticleRepo articleRepo = new ArticleRepo();
            AuthorRepo  authorRepo  = new AuthorRepo();

            UserValidator    userValidator    = new UserValidator();
            ArticleValidator articleValidator = new ArticleValidator();
            AuthorValidator  authorValidator  = new AuthorValidator();

            userRepo.SetValidator(userValidator);
            articleRepo.SetValidator(articleValidator);
            authorRepo.SetValidator(authorValidator);

            Manager manager = new Manager(userRepo, authorRepo, articleRepo);

            ConsoleUI console = new ConsoleUI(manager);

            console.Run();
        }
Ejemplo n.º 11
0
        public async Task <IHttpActionResult> GetArticel(int id)
        {
            var article = new ArticleRepo().GetArticle(id);

            return(Ok(article));
        }
Ejemplo n.º 12
0
        public async Task <IHttpActionResult> GetArticleLength(int id)
        {
            var articleLength = new ArticleRepo().GetArticleLength(id);

            return(Ok(articleLength));
        }
Ejemplo n.º 13
0
        public async Task <IHttpActionResult> GetAllArticle()
        {
            var listOfAllArticles = new ArticleRepo().GetAllArticles();

            return(Ok(listOfAllArticles));
        }
Ejemplo n.º 14
0
        public async Task <IHttpActionResult> GetArticlesFromBookingSystem(int id)
        {
            var listOfArticles = new ArticleRepo().GetArticlesFromBookingSystem(id);

            return(Ok(listOfArticles));
        }
Ejemplo n.º 15
0
 public ArticleController()
 {
     _articleRepo = new ArticleRepo();
     //_genericRepo = new GenericRepo<FoodCategory>();
 }
        public async void SaveArticle(object input = null)
        {
            try
            {
                _workingStatus(true);

                await Task.Run(() =>
                {
                    ArticleRepo articleRepo = new ArticleRepo();

                    // Regex to switch multiple spaces into one (Restricts user to enter more than one space in Title textboxes)
                    RegexOptions options = RegexOptions.None;
                    Regex regex          = new Regex("[ ]{2,}", options);

                    // 1. Format title
                    Article.Title = Article.Title.Trim();
                    Article.Title = regex.Replace(Article.Title, " ");

                    // 2. Add article to database
                    articleRepo.SaveArticle(Article, User);

                    // 3. Copy selected file to root folder with the new ID-based name
                    File.Copy(SelectedFile, Path.Combine(Environment.CurrentDirectory, "Files\\") + Article.FileName + ".pdf");

                    // 4.1 Retrieve id (in reality we retrieve whole article) of newly added article
                    Article currently_added_article = articleRepo.GetArticleWithTitle(Article.Title);

                    // 4.2 Add bookmarks
                    foreach (Bookmark bookmark in Bookmarks)
                    {
                        new BookmarkRepo().AddArticleToBookmark(bookmark, currently_added_article);
                    }

                    // 4.3 Add references
                    foreach (Reference reference in References)
                    {
                        new ReferenceRepo().AddArticleToReference(reference, currently_added_article);
                    }

                    // 4.4 Tracking
                    ArticleInfo info = new ArticleInfo(User, Article.Title, Bookmarks, References);
                    Tracker tracker  = new Tracker(User);
                    tracker.TrackCreate <ArticleInfo>(info);
                    File.Copy(SelectedFile, tracker.GetFilesPath() + "\\" + Article.FileName + ".pdf");

                    // 6. Move the selected file into "Done" subfolder
                    string done_path = Path.GetDirectoryName(SelectedFile) + "\\Done\\";
                    Directory.CreateDirectory(Path.GetDirectoryName(SelectedFile) + "\\Done");
                    File.Move(SelectedFile, done_path + System.IO.Path.GetFileName(SelectedFile));
                });

                // 5. Clear article attributes
                ClearArticleAttributesCommand.Execute(null);
                Bookmarks.Clear();
                References.Clear();

                _workingStatus(false);
            }
            catch (Exception e)
            {
                new BugTracker().Track("Data Entry", "Add article", e.Message, e.StackTrace);
                _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
            }
            finally
            {
                _workingStatus(false);
            }
        }
Ejemplo n.º 17
0
 public ArticleController(ArticleRepo repo)
 {
     this.repo = repo;
 }
Ejemplo n.º 18
0
        public void Sync()
        {
            // 1. Sync information
            _logs.ForEach((log) =>
            {
                User user = new UserRepo().GetUserByName(log.Username);

                switch (log.Type)
                {
                case "Create":
                    // Create article
                    if (log.Info.InfoType == "ArticleInfo")
                    {
                        ArticleInfo local_info = log.Info as ArticleInfo;
                        Article article        = new Article(local_info);
                        ArticleRepo repo       = new ArticleRepo();

                        // Edge case: Article already exists
                        if (repo.GetArticleWithTitle(article.Title) != null)
                        {
                            string mismatch = $"Article '{local_info.Title}' already exists.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        // 1. Add article to database
                        repo.SaveArticle(article, user);

                        // 2. Copy file
                        string fileName = repo.GetFileWithTitle(local_info.Title);
                        File.Copy(
                            Path.Combine(_filesPath, local_info.FileName + ".pdf"),
                            Path.Combine(Path.Combine(Environment.CurrentDirectory, "Files"), fileName + ".pdf"));

                        Article dbArticle = repo.GetArticleWithTitle(local_info.Title);

                        // 3. Add references and bookmarks
                        BookmarkRepo bookmarkRepo   = new BookmarkRepo();
                        ReferenceRepo referenceRepo = new ReferenceRepo();

                        // Bookmarks
                        local_info.Bookmarks.ForEach((bookmark) =>
                        {
                            Bookmark dbBookmark = bookmarkRepo.GetBookmark(bookmark.Name, user);
                            bookmarkRepo.AddArticleToBookmark(dbBookmark, dbArticle);
                        });

                        // References
                        local_info.References.ForEach((reference) =>
                        {
                            Reference dbReference = referenceRepo.GetReference(reference.Name);
                            referenceRepo.AddArticleToReference(dbReference, dbArticle);
                        });
                    }
                    // Create bookmark
                    else if (log.Info.InfoType == "BookmarkInfo")
                    {
                        BookmarkInfo local_info = log.Info as BookmarkInfo;
                        BookmarkRepo repo       = new BookmarkRepo();

                        // Edge case: Bookmark already exists
                        if (repo.GetBookmark(local_info.Name, user) != null)
                        {
                            string mismatch = $"Bookmark '{local_info.Name}' already exists.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        repo.AddBookmark(local_info.Name, local_info.Global, user);
                    }
                    // Create reference
                    else if (log.Info.InfoType == "ReferenceInfo")
                    {
                        ReferenceInfo local_info = log.Info as ReferenceInfo;
                        ReferenceRepo repo       = new ReferenceRepo();

                        // Edge case: Reference already exists
                        if (repo.GetReference(local_info.Name) != null)
                        {
                            string mismatch = $"Reference '{local_info.Name}' already exists.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        new ReferenceRepo().AddReference(local_info.Name);
                    }
                    break;

                case "Update":
                    // Update article
                    if (log.Info.InfoType == "ArticleInfo")
                    {
                        ArticleInfo local_info  = (ArticleInfo)log.Info;
                        ArticleRepo repo        = new ArticleRepo();
                        Article existingArticle = repo.GetFullArticleWithTitle(user, log.Changed);

                        // Edge case: Article I am trying to update doesn't exist
                        if (existingArticle == null)
                        {
                            string mismatch = $"Article '{log.Changed}' doesn't exist and can't be updated.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        Article newArticle = new Article(local_info);
                        newArticle.ID      = existingArticle.ID;
                        repo.UpdateArticle(newArticle, user);
                    }
                    // Update bookmark
                    else if (log.Info.InfoType == "BookmarkInfo")
                    {
                        BookmarkInfo local_info   = (BookmarkInfo)log.Info;
                        BookmarkRepo repo         = new BookmarkRepo();
                        Bookmark existingBookmark = repo.GetBookmark(log.Changed, user);

                        // Edge case: Bookmark I am trying to update doesn't exist
                        if (existingBookmark == null)
                        {
                            string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        Bookmark newBookmark = new Bookmark(local_info);
                        newBookmark.ID       = existingBookmark.ID;
                        repo.UpdateBookmark(newBookmark);
                    }
                    // Update reference
                    else if (log.Info.InfoType == "ReferenceInfo")
                    {
                        ReferenceInfo local_info    = (ReferenceInfo)log.Info;
                        ReferenceRepo repo          = new ReferenceRepo();
                        Reference existingReference = repo.GetReference(log.Changed);

                        // Edge case: Reference I am trying to update doesn't exist
                        if (existingReference == null)
                        {
                            string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        Reference newReference = new Reference(local_info);
                        newReference.ID        = existingReference.ID;
                        if (local_info.Title != null)
                        {
                            newReference.ArticleID = (int)new ArticleRepo().GetArticleWithTitle(local_info.Title).ID;
                        }
                        repo.UpdateReference(newReference);
                    }
                    break;

                case "Coupling":
                    Couple info = (Couple)log.Info;
                    // Couple bookmark
                    if (info.CollectionType == "Bookmark")
                    {
                        BookmarkRepo bookmarkRepo = new BookmarkRepo();
                        ArticleRepo articleRepo   = new ArticleRepo();

                        Bookmark bookmark = bookmarkRepo.GetBookmark(info.Name, user);
                        Article article   = articleRepo.GetArticleWithTitle(info.Title);

                        // Edge case: Article or bookmark doesn't exist or Article is already in bookmark
                        if (bookmark == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because bookmark doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }
                        else if (article == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because article doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        // Add
                        if (info.ActionType == "Add")
                        {
                            // Edge case: Article is already in bookmark
                            if (bookmarkRepo.CheckArticleInBookmark(bookmark, article))
                            {
                                string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            bookmarkRepo.AddArticleToBookmark(bookmark, article);
                        }
                        // Remove
                        else if (info.ActionType == "Remove")
                        {
                            // Edge case: Article is not in bookmark
                            if (!bookmarkRepo.CheckArticleInBookmark(bookmark, article))
                            {
                                string mismatch = $"Article - '{info.Title}' can not be removed from bookmark '{info.Name}' (Its not there)";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            bookmarkRepo.RemoveArticleFromBookmark(bookmark, article);
                        }
                    }
                    // Couple reference
                    else if (info.CollectionType == "Reference")
                    {
                        ReferenceRepo referenceRepo = new ReferenceRepo();
                        ArticleRepo articleRepo     = new ArticleRepo();

                        Reference reference = referenceRepo.GetReference(info.Name);
                        Article article     = articleRepo.GetArticleWithTitle(info.Title);

                        // Edge case: Article or bookmark doesn't exist
                        if (reference == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because reference doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }
                        else if (article == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because article doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        // Add
                        if (info.ActionType == "Add")
                        {
                            if (referenceRepo.CheckArticleInReference(reference, article))
                            {
                                string mismatch = $"Article - '{info.Title}' is already in reference '{info.Name}'";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            referenceRepo.AddArticleToReference(reference, article);
                        }
                        // Remove
                        else if (info.ActionType == "Remove")
                        {
                            if (!referenceRepo.CheckArticleInReference(reference, article))
                            {
                                string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            referenceRepo.RemoveArticleFromReference(reference, article);
                        }
                    }
                    break;

                case "Delete":
                    DeleteInfo local_info1 = (DeleteInfo)log.Info;
                    // Delete article
                    if (local_info1.ObjectType == "Article")
                    {
                        ArticleRepo repo = new ArticleRepo();
                        Article article  = repo.GetArticleWithTitle(local_info1.Name);

                        // Edge case: Article I am trying to delete doesn't exist
                        if (article == null)
                        {
                            string mismatch = $"Can't delete article '{local_info1.Name}' because it doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        string file = repo.GetFileWithTitle(local_info1.Name);
                        repo.DeleteArticle(article);
                        File.Delete(Path.Combine(Environment.CurrentDirectory, "Files", file + ".pdf"));
                    }
                    // Delete bookmark
                    else if (local_info1.ObjectType == "Bookmark")
                    {
                        BookmarkRepo repo = new BookmarkRepo();
                        Bookmark bookmark = repo.GetBookmark(local_info1.Name, user);

                        // Edge case: Bookmark I am trying to delete doesn't exist
                        if (bookmark == null)
                        {
                            string mismatch = $"Can't delete bookmark '{local_info1.Name}' because it doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        repo.DeleteBookmark(bookmark);
                    }
                    // Delete reference
                    else if (local_info1.ObjectType == "Reference")
                    {
                        ReferenceRepo repo  = new ReferenceRepo();
                        Reference reference = repo.GetReference(local_info1.Name);

                        // Edge case: Reference I am trying to delete doesn't exist
                        if (reference == null)
                        {
                            string mismatch = $"Can't delete reference '{local_info1.Name}' because it doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        repo.DeleteReference(reference);
                    }
                    break;

                case "Personal":
                    PersonalInfo local_info2 = (PersonalInfo)log.Info;
                    ArticleRepo repo1        = new ArticleRepo();
                    Article article3         = repo1.GetArticleWithTitle(local_info2.Title);

                    // Edge case: Article I am trying to add personal doesn't exist
                    if (article3 == null)
                    {
                        string mismatch = $"Can't add personal to article '{local_info2.Title}' because it doesn't exist";
                        _mismatches.Add(mismatch);
                        return;
                    }

                    article3.PersonalComment = local_info2.PersonalComment;
                    article3.SIC             = local_info2.SIC;

                    repo1.UpdatePersonal(article3, user);
                    break;

                case "Pending":
                    PendingInfo l_info = (PendingInfo)log.Info;

                    // 1. Remove pending section status from db
                    new GlobalRepo().RemovePending(l_info.Section);

                    // 2. Remove section from json
                    string path            = Path.Combine(Environment.CurrentDirectory, "sections.json");
                    string textInfo        = File.ReadAllText(path);
                    List <string> sections = JsonConvert.DeserializeObject <List <string> >(textInfo);
                    sections.Remove(l_info.Section);
                    textInfo = JsonConvert.SerializeObject(sections);
                    File.WriteAllText(path, textInfo);
                    break;

                default:
                    break;
                }
            });

            // 2. Write mismatches
            WriteMismatches();
        }
Ejemplo n.º 19
0
 public CategoryService(CategoryRepo categoryRepo, ArticleRepo articleRepo)
 {
     _categoryRepo = categoryRepo;
     _articleRepo  = articleRepo;
 }
Ejemplo n.º 20
0
        private void StubInventoryRepositories()
        {
            #region EntityRepository LoadAsync GetAsync
            A.CallTo(() => EntityRepository.LoadAsync <Article>(Product1InteriorDoor.Id)).Returns(Product1InteriorDoor);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Product1InteriorDoor.Id)).Returns(Product1InteriorDoor);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Product2InteriorDoor.Id)).Returns(Product2InteriorDoor);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Product2InteriorDoor.Id)).Returns(Product2InteriorDoor);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Material1Timber.Id)).Returns(Material1Timber);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Material1Timber.Id)).Returns(Material1Timber);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Material2Foil.Id)).Returns(Material2Foil);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Material2Foil.Id)).Returns(Material2Foil);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Material4TintedGlass.Id)).Returns(Material4TintedGlass);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Material4TintedGlass.Id)).Returns(Material4TintedGlass);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Material3Mdf.Id)).Returns(Material3Mdf);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Material3Mdf.Id)).Returns(Material3Mdf);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Component1Vertical.Id)).Returns(Component1Vertical);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Component1Vertical.Id)).Returns(Component1Vertical);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Component2Horizontal.Id)).Returns(Component2Horizontal);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Component2Horizontal.Id)).Returns(Component2Horizontal);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Component3MdfFiller.Id)).Returns(Component3MdfFiller);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Component3MdfFiller.Id)).Returns(Component3MdfFiller);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(Component4GlassFiller.Id)).Returns(Component4GlassFiller);
            A.CallTo(() => EntityRepository.GetAsync <Article>(Component4GlassFiller.Id)).Returns(Component4GlassFiller);

            A.CallTo(() => EntityRepository.LoadAsync <Article>(ArticleToArchive.Id)).Returns(ArticleToArchive);
            A.CallTo(() => EntityRepository.GetAsync <Article>(ArticleToArchive.Id)).Returns(ArticleToArchive);

            #endregion

            #region ArticleRepository LoadAsync GetAsync

            A.CallTo(() => ArticleRepo.LoadAsync(Product1InteriorDoor.Id)).Returns(Product1InteriorDoor);
            A.CallTo(() => ArticleRepo.GetAsync(Product1InteriorDoor.Id)).Returns(Product1InteriorDoor);

            A.CallTo(() => ArticleRepo.LoadAsync(Product2InteriorDoor.Id)).Returns(Product2InteriorDoor);
            A.CallTo(() => ArticleRepo.GetAsync(Product2InteriorDoor.Id)).Returns(Product2InteriorDoor);

            A.CallTo(() => ArticleRepo.LoadAsync(Material1Timber.Id)).Returns(Material1Timber);
            A.CallTo(() => ArticleRepo.GetAsync(Material1Timber.Id)).Returns(Material1Timber);

            A.CallTo(() => ArticleRepo.LoadAsync(Material2Foil.Id)).Returns(Material2Foil);
            A.CallTo(() => ArticleRepo.GetAsync(Material2Foil.Id)).Returns(Material2Foil);

            A.CallTo(() => ArticleRepo.LoadAsync(Material4TintedGlass.Id)).Returns(Material4TintedGlass);
            A.CallTo(() => ArticleRepo.GetAsync(Material4TintedGlass.Id)).Returns(Material4TintedGlass);

            A.CallTo(() => ArticleRepo.LoadAsync(Material3Mdf.Id)).Returns(Material3Mdf);
            A.CallTo(() => ArticleRepo.GetAsync(Material3Mdf.Id)).Returns(Material3Mdf);

            A.CallTo(() => ArticleRepo.LoadAsync(Component1Vertical.Id)).Returns(Component1Vertical);
            A.CallTo(() => ArticleRepo.GetAsync(Component1Vertical.Id)).Returns(Component1Vertical);

            A.CallTo(() => ArticleRepo.LoadAsync(Component2Horizontal.Id)).Returns(Component2Horizontal);
            A.CallTo(() => ArticleRepo.GetAsync(Component2Horizontal.Id)).Returns(Component2Horizontal);

            A.CallTo(() => ArticleRepo.LoadAsync(Component3MdfFiller.Id)).Returns(Component3MdfFiller);
            A.CallTo(() => ArticleRepo.GetAsync(Component3MdfFiller.Id)).Returns(Component3MdfFiller);

            A.CallTo(() => ArticleRepo.LoadAsync(Component4GlassFiller.Id)).Returns(Component4GlassFiller);
            A.CallTo(() => ArticleRepo.GetAsync(Component4GlassFiller.Id)).Returns(Component4GlassFiller);

            A.CallTo(() => ArticleRepo.LoadAsync(ArticleToArchive.Id)).Returns(ArticleToArchive);
            A.CallTo(() => ArticleRepo.GetAsync(ArticleToArchive.Id)).Returns(ArticleToArchive);

            #endregion

            var ids0 = Product1InteriorDoor.BillsOfMaterial.First().Input.Select(i => i.Article.Id);
            A.CallTo(() => EntityRepository.LoadSomeAsync(A <IEnumerable <Guid> > .That.IsSameSequenceAs(ids0), A <Expression <Func <Article, bool> > > .Ignored, A <int?> .Ignored, A <int?> .Ignored, A <string> .Ignored, A <string> .Ignored))
            .Returns(Product1InteriorDoor.BillsOfMaterial.First().Input.Select(i => i.Article).ToList());

            var ids1 = new[] { Component1Vertical.Id, Component2Horizontal.Id, Component3MdfFiller.Id, Material2Foil.Id };
            A.CallTo(() => EntityRepository.LoadSomeAsync(A <IEnumerable <Guid> > .That.IsSameSequenceAs(ids1), A <Expression <Func <Article, bool> > > .Ignored, A <int?> .Ignored, A <int?> .Ignored, A <string> .Ignored, A <string> .Ignored))
            .Returns(new List <Article> {
                Component1Vertical, Component2Horizontal, Component3MdfFiller, Material2Foil
            });

            A.CallTo(() => ArticleRepo.FindSpoiledCounterpartAsync(Product1InteriorDoor, true))
            .Returns(Product1InteriorDoorSpoiled);
            A.CallTo(() => ArticleRepo.FindSpoiledCounterpartAsync(Component1Vertical, true))
            .Returns(Component1VerticalSpoiled);

            A.CallTo(() => EntityRepository.GetSomeAsync(A <IEnumerable <Guid> > .That.Contains(Product1InteriorDoor.Id), A <Expression <Func <Article, bool> > > .Ignored, A <int?> .Ignored, A <int?> .Ignored, A <string> .Ignored, A <string> .Ignored))
            .Returns(new[] { Product1InteriorDoor });

            A.CallTo(() => EntityRepository.GetSomeAsync(A <IEnumerable <Guid> > .That.Contains(Material2Foil.Id), A <Expression <Func <Article, bool> > > .Ignored, A <int?> .Ignored, A <int?> .Ignored, A <string> .Ignored, A <string> .Ignored))
            .Returns(new[] { Material2Foil });

            A.CallTo(() => EntityRepository.LoadAsync <Uom>(PieceUom.Id)).Returns(PieceUom);
            A.CallTo(() => EntityRepository.GetAsync <Uom>(PieceUom.Id)).Returns(PieceUom);

            A.CallTo(() => EntityRepository.LoadAsync <Uom>(CubicMeterUom.Id)).Returns(CubicMeterUom);
            A.CallTo(() => EntityRepository.GetAsync <Uom>(CubicMeterUom.Id)).Returns(CubicMeterUom);

            A.CallTo(() => EntityRepository.LoadAsync <BillOfMaterial>(Component2Horizontal.PrimaryBillOfMaterial.Id))
            .Returns(Component2Horizontal.PrimaryBillOfMaterial);
            A.CallTo(() => EntityRepository.GetAsync <BillOfMaterial>(Component2Horizontal.PrimaryBillOfMaterial.Id))
            .Returns(Component2Horizontal.PrimaryBillOfMaterial);

            A.CallTo(() => EntityRepository.LoadAsync <BillOfMaterial>(Product1InteriorDoor.PrimaryBillOfMaterial.Id))
            .Returns(Product1InteriorDoor.PrimaryBillOfMaterial);
            A.CallTo(() => EntityRepository.GetAsync <BillOfMaterial>(Product1InteriorDoor.PrimaryBillOfMaterial.Id))
            .Returns(Product1InteriorDoor.PrimaryBillOfMaterial);

            A.CallTo(() => EntityRepository.LoadAsync <BillOfMaterial>(Product2InteriorDoor.PrimaryBillOfMaterial.Id))
            .Returns(Product2InteriorDoor.PrimaryBillOfMaterial);
            A.CallTo(() => EntityRepository.GetAsync <BillOfMaterial>(Product2InteriorDoor.PrimaryBillOfMaterial.Id))
            .Returns(Product2InteriorDoor.PrimaryBillOfMaterial);

            var inStockP1 = Shops.SelectMany(s => s.Inventory).Where(i => i.Article == Product1InteriorDoor)
                            .Sum(i => i.Amount);
            A.CallTo(() => InventoryRepo.FindTotalAmountInStockAsync(Product1InteriorDoor)).Returns(inStockP1);

            var inOrdersP1 = Orders.SelectMany(s => s.ItemsOrdered).Where(i => i.Article == Product1InteriorDoor)
                             .Sum(i => i.Amount);
            A.CallTo(() => InventoryRepo.FindSpareInventoryAsync(Product1InteriorDoor)).Returns(inStockP1 - inOrdersP1);

            var inStockC1 = Shops.SelectMany(s => s.Inventory).Where(i => i.Article == Component1Vertical)
                            .Sum(i => i.Amount);
            A.CallTo(() => InventoryRepo.FindTotalAmountInStockAsync(Component1Vertical)).Returns(inStockC1);
            A.CallTo(() => InventoryRepo.FindSpareInventoryAsync(Component1Vertical)).Returns(inStockC1);

            var inStockC2 = Shops.SelectMany(s => s.Inventory).Where(i => i.Article == Component2Horizontal)
                            .Sum(i => i.Amount);
            A.CallTo(() => InventoryRepo.FindTotalAmountInStockAsync(Component2Horizontal)).Returns(inStockC2);
            A.CallTo(() => InventoryRepo.FindSpareInventoryAsync(Component2Horizontal)).Returns(inStockC2);

            var inStockC3 = Shops.SelectMany(s => s.Inventory).Where(i => i.Article == Component3MdfFiller)
                            .Sum(i => i.Amount);
            A.CallTo(() => InventoryRepo.FindTotalAmountInStockAsync(Component3MdfFiller)).Returns(inStockC3);
            A.CallTo(() => InventoryRepo.FindSpareInventoryAsync(Component3MdfFiller)).Returns(inStockC3);

            A.CallTo(() => InventoryRepo.FindTotalAmountInOrdersAsync(Product2InteriorDoor)).Returns(1);

            A.CallTo(() => InventoryRepo.FindTotalAmountInOrdersAsync(Material1Timber))
            .Returns(AmountInOrders(Material1Timber));
            A.CallTo(() => InventoryRepo.FindTotalAmountInOrdersAsync(Material2Foil))
            .Returns(AmountInOrders(Material2Foil));
            A.CallTo(() => InventoryRepo.FindTotalAmountInOrdersAsync(Material3Mdf)).Returns(AmountInOrders(Material3Mdf));
            A.CallTo(() => InventoryRepo.FindTotalAmountInOrdersAsync(Material4TintedGlass))
            .Returns(AmountInOrders(Material4TintedGlass));
        }
Ejemplo n.º 21
0
 public ArticleService(ArticleRepo articleRepo, CategoryService categoryService, CategoryRepo categoryRepo)
 {
     _articleRepo     = articleRepo;
     _categoryService = categoryService;
     _categoryRepo    = categoryRepo;
 }