kima2/src/core/seller.cpp

64 lines
1.9 KiB
C++
Raw Normal View History

2018-07-09 16:06:27 +02:00
#include "seller.h"
2018-07-11 11:53:46 +02:00
Seller::Seller() : Entity() {}
2018-07-09 16:06:27 +02:00
2018-07-11 11:53:46 +02:00
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
2018-07-12 14:39:08 +02:00
int numArticlesOffered)
2018-07-11 11:53:46 +02:00
: Entity()
2018-07-09 16:06:27 +02:00
{
2018-07-10 12:51:03 +02:00
firstName_ = firstName;
lastName_ = lastName;
2018-07-11 11:53:46 +02:00
sellerNo_ = sellerNo;
2018-07-12 14:39:08 +02:00
numArticlesOffered_ = numArticlesOffered;
2018-07-09 16:06:27 +02:00
}
2018-07-11 15:59:38 +02:00
void Seller::setSellerNo(int seller_no) { sellerNo_ = seller_no; }
2018-07-09 16:06:27 +02:00
2018-07-11 11:53:46 +02:00
inline void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; }
inline void Seller::setLastName(const std::string& lastName) { lastName_ = lastName; }
2018-07-12 14:39:08 +02:00
inline void Seller::setNumArticlesOffered(int number) { numArticlesOffered_ = number; }
2018-07-11 11:53:46 +02:00
2018-07-12 14:39:08 +02:00
void Seller::addArticle(std::shared_ptr<Article> article)
{
article->setSeller(this);
articles_.push_back(article);
}
2018-07-11 15:59:38 +02:00
std::string Seller::getFirstName() const { return firstName_; }
std::string Seller::getLastName() const { return lastName_; }
int Seller::getSellerNo() const { return sellerNo_; }
2018-07-11 13:25:39 +02:00
std::vector<Article*> Seller::getArticles(bool onlySold) const
2018-07-11 13:25:39 +02:00
{
std::vector<Article*> articles;
2018-07-12 08:26:03 +02:00
for (const auto article : articles_) {
if (onlySold && article->isSold()) {
articles.push_back(article.get());
2018-07-11 13:25:39 +02:00
} else if (!onlySold) {
articles.push_back(article.get());
2018-07-11 12:54:10 +02:00
}
}
2018-07-11 13:25:39 +02:00
return articles;
}
2018-07-12 14:39:08 +02:00
int Seller::numArticlesSold() const { return static_cast<int>(getArticles(true).size()); }
int Seller::numArticlesOffered() const { return numArticlesOffered_; }
2018-07-13 13:54:02 +02:00
void Seller::cleanupArticles()
{
articles_.erase(std::remove_if(begin(articles_), end(articles_),
[](const std::shared_ptr<Article>& article) {
return article->getState() == Article::State::DELETE;
}));
for (auto& article : articles_) {
article->setState(Article::State::OK);
}
}
// int Seller::numArticlesTotal() const { return static_cast<int>(getArticles().size()); }