public async Task <IHttpActionResult> GetCategories() { List <ApiModels.CategoryModel> categoryModels = new List <CategoryModel>(); try { using (AuctionDb context = new AuctionDb()) { BaseModelRepository <DomainModels.Categories.CategoryModel> repository = new BaseModelRepository <DomainModels.Categories.CategoryModel>(context); var categoriesModels = repository.GetAll().ToList(); //foreach (var category in categoriesModels) //{ // categoryModels.Add(new CategoryModel() // { // Id = category.Id, // SubCategoryModels = // }); //} categoriesModels.ForEach(elem => categoryModels.Add(new ApiModels.CategoryModel() { Id = elem.Id, CategoryName = elem.CategoryName, SubCategoryModels = elem.SubCategoryId.Select(sub => new SubCategoryModel() { Id = sub.Id, SubCategoryName = sub.SubCategoryName }).ToList() //SubCategoryModels = new List<SubCategoryModel>() //{ // new SubCategoryModel() // { // Id = elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.Id, // SubCategoryName = // elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.SubCategoryName // } //} })); } } catch (Exception exception) { var ex = exception; return(NotFound()); } return(Ok(categoryModels)); }
public async Task<IHttpActionResult> GetCategories() { List<ApiModels.CategoryModel> categoryModels = new List<CategoryModel>(); try { using (AuctionDb context = new AuctionDb()) { BaseModelRepository<DomainModels.Categories.CategoryModel> repository = new BaseModelRepository<DomainModels.Categories.CategoryModel>(context); var categoriesModels = repository.GetAll().ToList(); //foreach (var category in categoriesModels) //{ // categoryModels.Add(new CategoryModel() // { // Id = category.Id, // SubCategoryModels = // }); //} categoriesModels.ForEach(elem => categoryModels.Add(new ApiModels.CategoryModel() { Id = elem.Id, CategoryName = elem.CategoryName, SubCategoryModels = elem.SubCategoryId.Select(sub => new SubCategoryModel() { Id = sub.Id, SubCategoryName = sub.SubCategoryName }).ToList() //SubCategoryModels = new List<SubCategoryModel>() //{ // new SubCategoryModel() // { // Id = elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.Id, // SubCategoryName = // elem.SubCategoryId.Where(sub => sub.CategoriesId.Contains(elem)).GetEnumerator().Current.SubCategoryName // } //} })); } } catch (Exception exception) { var ex = exception; return NotFound(); } return Ok(categoryModels); }
public void SetUp() { this.category = new Category { CategoryName = "Electronics" }; this.auctionDbMock = EntityFrameworkMock.Create <AuctionDb>(); EntityFrameworkMock.PrepareMock(this.auctionDbMock); this.productService = new ProductService( new ProductRepository(this.auctionDbMock), new CategoriesService(new CategoriesRepository(this.auctionDbMock))); }
public void SetUp() { this.auctionDbMock = EntityFrameworkMock.Create <AuctionDb>(); EntityFrameworkMock.PrepareMock(this.auctionDbMock); this.reviewService = new ReviewService(new ReviewRepository(this.auctionDbMock)); this.fromUser = new User { Id = 1, FirstName = "Dan", LastName = "Brown" }; this.toUser = new User { Id = 2, FirstName = "Mihai", LastName = "Anghel" }; }
public IAuction CreateAuction(string description, DateTime endsOn, double startingPrice) { if (description is null) { throw new ArgumentNullException(); } if (description == "") { throw new ArgumentException(); } if (startingPrice < 0) { throw new ArgumentOutOfRangeException(); } if (endsOn < _alarmClock.Now) { throw new UnavailableTimeMachineException(); } if (!this.IsValid()) { throw new InvalidOperationException(); } using (var context = new SiteContext(_connectionString)) { var site = context.Sites.SingleOrDefault(a => a.SiteName == Site.Name); if (site is null) { throw new InvalidOperationException(); } var session = context.Sessions.Find(Id); if (session is null) { throw new InvalidOperationException(); } var tupla = new AuctionDb() { Seller = session.User, Description = description, EndsOn = endsOn, SiteName = Site.Name, CurrentPrice = startingPrice }; context.Auctions.Add(tupla); context.SaveChanges(); ValidUntil = _alarmClock.Now.AddSeconds(Site.SessionExpirationInSeconds); session.ValidUntil = ValidUntil; return(new Auction(tupla.Id, User, description, endsOn, startingPrice, Site, _connectionString, _alarmClock)); } }
public void SetUp() { this.auctionDbMock = EntityFrameworkMock.Create <AuctionDb>(); EntityFrameworkMock.PrepareMock(this.auctionDbMock); this.bidService = new BidService(new BidRepository(this.auctionDbMock)); this.price = new Price { ThePrice = 150, Currency = "USD" }; this.user = new User { Id = 1, FirstName = "Dan", LastName = "Brown" }; this.bid = new Bid(); this.bid.User = this.user; this.bid.Price = this.price; }
public void SetUp() { this.auctionDbMock = EntityFrameworkMock.Create <AuctionDb>(); this.reviewService = new ReviewService(new ReviewRepository(this.auctionDbMock)); this.userService = new UserService(new UserRepository(this.auctionDbMock), new ReviewRepository(this.auctionDbMock)); this.user = new User(); this.user.FirstName = "Mihai"; this.user.LastName = "Dan"; this.user.Gender = "M"; this.user.Email = "*****@*****.**"; this.user.Address = "brasov"; this.user.PhoneNumber = "1234567891"; this.user.Id = 1; var fromUser = new User { Id = 1, FirstName = "Dan", LastName = "Brown" }; var review = new Review { FromUser = fromUser, ToUser = this.user, Score = 5.0 }; var result = this.reviewService.AddReview(review); }
public void DefaultParameters() { AuctionDb db = new AuctionDb(); AdminSettings admin = db.adminSettings.FirstOrDefault(); admin.N = 10; admin.D = 18000; admin.S = 30; admin.G = 50; admin.P = 100; admin.C = "RSD"; admin.T = 100; db.Entry(admin).State = EntityState.Modified; db.SaveChanges(); }
public void SetUp() { this.auctionDbMock = EntityFrameworkMock.Create <AuctionDb>(); EntityFrameworkMock.PrepareMock(this.auctionDbMock); this.priceService = new PriceService(new PriceRepository(this.auctionDbMock)); }
public void SetUp() { this._auctionDbMock = EntityFrameworkMock.Create <AuctionDb>(); this._categoriesService = new CategoriesService(new CategoriesRepository(this._auctionDbMock)); }