Example #1
0
 private static IEnumerable <categories> GetCategorByID()
 {
     using (IBikeStoresCategoriesRepository repository = new CategoriesRepository())
     {
         return(repository.GetCategoryById("[production].[GetCategoryById]", 5));
     }
 }
Example #2
0
 public IActionResult Create()
 {
     return(View(new CreateUpdatePostViewModel()
     {
         Categories = CategoriesRepository.GetAll()
     }));
 }
Example #3
0
 private static string GetIdColumn()
 {
     using (IBikeStoresCategoriesRepository repository = new CategoriesRepository())
     {
         return(repository.GetIdColumn());
     }
 }
Example #4
0
 private static IEnumerable <categories> ExecuteGetCategories()
 {
     using (IBikeStoresCategoriesRepository repository = new CategoriesRepository())
     {
         return(repository.GetCategories("[production].[GetCategories]"));
     }
 }
Example #5
0
 private static void Delete(int Id)
 {
     using (IBikeStoresCategoriesRepository repository = new CategoriesRepository())
     {
         repository.DeleteById(Id);
     }
 }
Example #6
0
 private static IEnumerable <categories> Get()
 {
     using (IBikeStoresCategoriesRepository repository = new CategoriesRepository())
     {
         return(repository.GetAll());
     }
 }
Example #7
0
            public void ThrowsExceptionWhenCategoryWithMismatchedUserIds()
            {
                // Arrange.
                this.category.UserId = 1;
                this.userId          = 2;

                // Act.
                Exception caughtException = null;

                try
                {
                    using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                    {
                        CategoriesRepository repository = new CategoriesRepository(context);
                        repository.Save(this.category, this.userId);
                    }
                }
                catch (Exception ex)
                {
                    caughtException = ex;
                }

                // Assert.
                Assert.IsNotNull(caughtException, "An exception should be thrown.");
                Assert.IsInstanceOfType(caughtException, typeof(ArgumentException), "This should be an argument exception.");
                string exceptionMessage = "A user ID is expected to match the passed in user ID for a category.\r\nParameter name: category.UserId";

                Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct.");
            }
Example #8
0
        public HttpResponseMessage ListRants()
        {
            var             repo  = new CategoriesRepository();
            List <Category> rants = repo.GetAll();

            return(Request.CreateResponse(HttpStatusCode.OK, rants));
        }
Example #9
0
            public void ThrowsExceptionWhenIdZero()
            {
                // Arrange.
                this.category.Id = 0;

                // Act.
                Exception caughtException = null;

                try
                {
                    using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                    {
                        CategoriesRepository repository = new CategoriesRepository(context);
                        repository.Save(this.category, this.userId);
                    }
                }
                catch (Exception ex)
                {
                    caughtException = ex;
                }

                // Assert.
                Assert.IsNotNull(caughtException, "An exception should be thrown.");
                Assert.IsInstanceOfType(caughtException, typeof(ArgumentException), "This should be an argument exception.");
                string exceptionMessage = "A category with a specified ID should have been used. To add a category, use the Add method.\r\nParameter name: category.Id";

                Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct.");
            }
Example #10
0
            public void UpdatesCategoryInTheContext()
            {
                // Act.
                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    CategoriesRepository repository = new CategoriesRepository(context);
                    repository.Save(this.category, this.userId);
                }

                // Assert.
                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    int expectedCategoryCount = 4;
                    Assert.AreEqual(expectedCategoryCount, context.Categories.Count(), "The number of categories should not change.");

                    Category actual = ContextDataService.GetCategoriesSet(context)
                                      .FirstOrDefault(x => x.Id == this.category.Id);
                    Assert.IsNotNull(actual, "A category should be found.");

                    Category expected = this.category;
                    Assert.AreEqual(expected.Id, actual.Id, "The ID for the entity should match.");
                    Assert.AreEqual(expected.Name, actual.Name, "The name for the entity should match.");
                    Assert.AreEqual(expected.UserId, actual.UserId, "The user ID for the entity should match.");
                }
            }
Example #11
0
            public void ThrowsExceptionWhenRecordFoundDoesNotBelongToTheUser()
            {
                // Arrange.
                this.categoryId = 1;
                this.userId     = 2;

                // Act.
                Exception caughtException = null;

                try
                {
                    using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                    {
                        CategoriesRepository repository = new CategoriesRepository(context);
                        repository.Get(this.categoryId, this.userId);
                    }
                }
                catch (Exception ex)
                {
                    caughtException = ex;
                }

                // Assert.
                Assert.IsNotNull(caughtException, "An exception should be thrown.");
                Assert.IsInstanceOfType(caughtException, typeof(NotFoundException), "This should be an argument exception.");
                string exceptionMessage = "The category was not found.";

                Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct.");
            }
Example #12
0
        public async Task <IActionResult> Create(CreateUpdatePostViewModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser CurrentUser = await this.UserManager.GetUserAsync(HttpContext.User);

                //Upload File
                String UploadPath = Path.Combine(HostingEnvironment.WebRootPath, "Uploads");
                if (!Directory.Exists(UploadPath))
                {
                    Directory.CreateDirectory(UploadPath);
                }
                String ThumbnailName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "-" + model.Thumbnail.FileName;
                String FullPath      = Path.Combine(UploadPath, ThumbnailName);
                using (FileStream stream = new FileStream(FullPath, FileMode.Create, FileAccess.Write))
                { model.Thumbnail.CopyTo(stream); }
                Post post = new Post()
                {
                    CategoryId    = model.CategoryId,
                    Status        = model.Status,
                    Content       = model.Content,
                    ThumbnailPath = ThumbnailName,
                    Title         = model.Title,
                    UserId        = CurrentUser.Id,
                };
                PostsRepository.Add(post);
                await PostsRepository.CommitAsync();

                return(RedirectToAction("Index"));
            }
            model.Categories = CategoriesRepository.GetAll();
            return(View(model));
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            db         = new ContentManagementEntities();
            rep        = new ArticlesRepository();
            repCat     = new CategoriesRepository();
            Authorid   = AddArticle.myid;
            AdminVarmi = AdminLogin.isAdmin;
            catList    = repCat.List();
            author     = db.Authors.Where(c => c.Id == Authorid).FirstOrDefault();
            ArticleId  = Convert.ToInt32(Request.QueryString["id"].ToString());
            article    = db.Articles.Where(c => c.Id == ArticleId).FirstOrDefault();
            if (AdminVarmi)
            {
                author = article.Authors;
            }


            if (IsPostBack)
            {
                article.ArticleBody = Request.Form["ArticleBody"].ToString();
                article.Title       = Request.Form["Title"].ToString();
                article.IsVisible   = true;
                article.CreateDate  = DateTime.Now;
                article.CategoryId  = Convert.ToInt32(Request.Form["CatType"]);
                article.Authors.Id  = Authorid;

                rep.Update(article);
                Response.Redirect("/ReadArticleDetail?id=" + article.Id);
            }
        }
        public MasterPresenter(IMasterView masterView = null)
        {
            this.masterView = masterView;

            db = new PortalAukcyjnyEntities();

            if (IsUserLoggedIn())
            {
                currentUserId = GetCurrentUserId();
            }
            else
            {
                currentUserId = Guid.Empty;
            }

            currencyRepo   = new CurrencyExchangeRepository(db);
            auctionsRepo   = new AuctionsRepository(db);
            catRepo        = new CategoriesRepository(db);
            offersRepo     = new OffersRepository(db);
            usersRepo      = new UsersRepository(db);
            commentsRepo   = new CommentsRepository(db);
            observersRepo  = new ObserversRepository(db);
            shipmentsRepo  = new ShipmentsRepository(db);
            imagesRepo     = new ImagesRepository(db);
            buyedItemsRepo = new BuyedItemsRepository(db);
        }
        public ActionResult Edit(int id)
        {
            Inventory inv = new Inventory();

            inv = _repo.Get(id);

            InventoryModel model  = new InventoryModel();
            Stream         stream = new MemoryStream(inv.ProductImage);

            //HttpPostedFileWrapper file = new HttpPostedFileWrapper(stream);
            //model.ProductImage = stream;
            model.ID                 = inv.ID;
            model.ProductName        = inv.ProductName;
            model.ProductCode        = inv.ProductCode;
            model.CategoryID         = inv.CategoryID;
            model.ProductDescription = inv.ProductDescription;
            model.Price              = inv.Price;
            model.Quantity           = inv.Quantity;

            List <Category>      temp = new List <Category>();
            CategoriesRepository repo = new CategoriesRepository();

            temp = repo.GetList();

            model.categories = new List <SelectListItem>();
            foreach (Category c in temp)
            {
                model.categories.Add(new SelectListItem {
                    Text = c.CategoryName, Value = c.ID.ToString()
                });
            }
            return(View(model));
        }
        public void GetAllTest()
        {
            var repository = new CategoriesRepository();
            var list       = repository.GetAll().ToList();

            Assert.IsTrue(list.Count() > 0);
        }
        public void GetByIDTest()
        {
            var repository = new CategoriesRepository();
            var result     = repository.GetByID(1);

            Assert.IsTrue(result.CategoryName == "上衣");
        }
Example #18
0
        public void ShouldCreateNote()
        {
            //arrange
            var Categ = new CategoriesRepository(_connectionstring).Create(new Category()
            {
                Name = "TestCategory", Id = Guid.NewGuid()
            });
            var GuidCreator = new UsersRepository(_connectionstring).Create(new ApplicationUser()
            {
                UserName = "******", Password = string.Empty
            }).Id_;
            var GuidCategory = Categ.Id;

            UsersForTests.Add(GuidCreator);
            CategoriesForTests.Add(GuidCategory);
            var note = new Note()
            {
                Title    = "TestNote",
                Text     = "TestText",
                Creator  = GuidCreator,
                Category = GuidCategory,
                Id       = Guid.NewGuid()
            };
            var repository = new NotesRepository(_connectionstring);

            //act
            var CreatedNote = repository.Create(note);

            NotesForTests.Add(CreatedNote.Id);
            var NoteFromDB = repository.GetNote(CreatedNote.Id);

            //assert
            Assert.AreEqual(CreatedNote.Id, NoteFromDB.Id);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null)
            {
                db = new ContentManagementEntities();
                if (Request.Form["action"] == "save")
                {
                    SaveToDb();
                }

                id = Convert.ToInt32(Request.QueryString["id"]);
                if (id != 0)
                {
                    myid = id;
                }

                author      = author = db.Authors.Where(c => c.Id == myid).FirstOrDefault();
                rep         = new ArticlesRepository();
                repCat      = new CategoriesRepository();
                repAuthor   = new AuthorsRepository();
                articleList = rep.List();
                catList     = repCat.List();
                authorsList = repAuthor.List();
            }
            else
            {
                Response.Redirect("/AuthorLogin");
            }
        }
Example #20
0
            public void ReturnsCategoriesOnlyForTheUser()
            {
                // Act.
                List <Category> actualList;

                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    CategoriesRepository repository = new CategoriesRepository(context);
                    actualList = repository.GetAll(this.userId).ToList();
                }

                // Assert.
                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    int numberOfCategoryUsers = context.Categories
                                                .GroupBy(a => a.UserId)
                                                .Count();
                    Assert.AreNotEqual(numberOfCategoryUsers, 0, "For the test to work there must be more than one user with categories.");
                    Assert.AreNotEqual(numberOfCategoryUsers, 1, "For the test to work there must be more than one user with categories.");
                }

                foreach (Category actual in actualList)
                {
                    Assert.AreEqual(this.userId, actual.UserId, "The user ID for each category should match the input user ID.");
                }
            }
        public HttpResponseMessage Delete(int id)
        {
            CategoriesRepository.DeleteCategory(id);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "Deleted");

            return(response);
        }
        public void UpdateNote()
        {
            User _user = new UsersRepository(_connectionString, new CategoriesRepository(_connectionString)).Create(new User {
                Name = "TestUserUpdater"
            });
            Category _category = new CategoriesRepository(_connectionString).Create(_user.Id, $"CategoryUpdater {_user.Name}");


            Note testNote = new Note
            {
                Title       = "TestTitleUpdate",
                Content     = "TestContentUpdate",
                Owner       = _user,
                DateCreated = DateTime.Now,
                DateChanged = DateTime.Now,
                Categories  = new CategoriesRepository(_connectionString).GetUserCategories(_user.Id),
                SharedNote  = null
            };
            var noteToSQL = new NoteRepository(_connectionString).Create(testNote);

            noteToSQL.Title   = "SuccessUpdate";
            noteToSQL.Content = "eeee";

            var noteAfterUpdate = new NoteRepository(_connectionString).UpdateNote(noteToSQL);

            Assert.AreEqual(noteToSQL.Content, noteAfterUpdate.Content);
        }
        public HttpResponseMessage PutCategory(int id, [FromBody] Category category)
        {
            var categories = CategoriesRepository.UpdateCategory(id, category);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, categories);

            return(response);
        }
Example #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            db          = new ContentManagementEntities();
            authorid    = AddArticle.myid;
            author      = db.Authors.Where(c => c.Id == authorid).FirstOrDefault();
            rep         = new ArticlesRepository();
            repAutors   = new AuthorsRepository();
            repCat      = new CategoriesRepository();
            articleList = rep.List();
            isonclick   = false;
            if (IsPostBack)
            {
                isonclick = true;
            }
            if (isonclick)
            {
                articleListFilter = rep.FilterList(Title.Value, Request.Form["CatType"], Request.Form["Autors"], ArticleBody.Value);
            }
            else
            {
                articleListFilter = rep.List();
            }

            catList    = repCat.List();
            authorList = repAutors.List();
        }
        public HttpResponseMessage GetFiltreCategories(string filtre)
        {
            var users = CategoriesRepository.GetFiltreCategories(filtre);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, users);

            return(response);
        }
        public HttpResponseMessage PostPost([FromBody] Category category)
        {
            var categorys = CategoriesRepository.InsertCategory(category);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, categorys);

            return(response);
        }
        public HttpResponseMessage GetIdCategoryPerStringWindows(string nom)
        {
            var category = CategoriesRepository.GetIdCategoryPerString(nom);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, category);

            return(response);
        }
        public HttpResponseMessage GetSingleCategory(int id)
        {
            var category = CategoriesRepository.GetSingleCategory(id);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, category);

            return(response);
        }
        public HttpResponseMessage GetCategoriesString()
        {
            List <string>       categories = CategoriesRepository.GetCategoriesNames();
            HttpResponseMessage response   = Request.CreateResponse(HttpStatusCode.OK, categories);

            return(response);
        }
        public HttpResponseMessage GetAllCategories()
        {
            List <Category>     categories = CategoriesRepository.GetAllCategories();
            HttpResponseMessage response   = Request.CreateResponse(HttpStatusCode.OK, categories);

            return(response);
        }
Example #31
0
 public static CategoriesRepository GetCategoriesRepository(IUnitOfWork unitOfWork)
 {
     var repository = new CategoriesRepository();
     repository.UnitOfWork = unitOfWork;
     return repository;
 }
Example #32
0
 public CategoriesController()
 {
     _categoriesRepository = new CategoriesRepository(this);
 }
Example #33
0
 public static CategoriesRepository GetCategoriesRepository()
 {
     var repository = new CategoriesRepository();
     repository.UnitOfWork = GetUnitOfWork();
     return repository;
 }