예제 #1
0
        public async Task <ActionResult> Edit(ArtefactCategoryDto category, HttpPostedFileBase imageFile)
        {
            var request = new HTTPrequest();
            ArtefactCategoryDto category_editted = await request.Get <ArtefactCategoryDto>("api/artefactCatergory/" + category.Id);

            if (ModelState.IsValid)
            {
                category_editted.Name         = category.Name;
                category_editted.Description  = category.Description;
                category_editted.ModifiedDate = DateTime.Now;
                HttpPostedFileBase imgFile = Request.Files["ImageFile"];

                if (imageFile != null)
                {
                    category_editted.Image = new byte[imageFile.ContentLength];
                    imageFile.InputStream.Read(category_editted.Image, 0, imageFile.ContentLength);
                }
                else
                {
                    category_editted.Image = category_editted.Image;
                }

                await request.Put <ArtefactCategoryDto>("api/artefactCatergory", category_editted);

                return(RedirectToAction("Index", new { recentAction = "Editted", recentName = category.Name, recentId = category.Id }));
            }
            return(View(category));
        }
예제 #2
0
        public async Task <ActionResult> Create(ArtefactCategoryDto category, HttpPostedFileBase imageFile)
        {
            if (string.IsNullOrEmpty(category.Name))
            {
                ViewBag.ValidationName = "Name field is required.";
                return(View(category));
            }

            if (ModelState.IsValid)
            {
                var request = new HTTPrequest();

                HttpPostedFileBase imgFile = Request.Files["ImageFile"];
                if (imgFile != null)
                {
                    category.Image = new byte[imgFile.ContentLength];
                    imgFile.InputStream.Read(category.Image, 0, imgFile.ContentLength);
                }

                category = await request.Post <ArtefactCategoryDto>("api/artefactCatergory", category);

                return(RedirectToAction("Index", new { recentAction = "Created", recentName = category.Name, recentId = category.Id }));
            }

            return(View(category));
        }
        public void TestUpdate_EmptyName()
        {
            //Get valid category
            ArtefactCategoryDto category = GetArtefactCategory();

            category.Name        = string.Empty;
            category.Description = "Test Edit";
            category.Image       = testImage;

            _controller.Update(category);
        }
 public ArtefactCategoryDto Update([FromBody] ArtefactCategoryDto dto)
 {
     try
     {
         return(new ArtefactCategoryHandler(isTest).Update(dto));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public void TestCreate_EmptyName()
        {
            //Set up dto
            ArtefactCategoryDto category = new ArtefactCategoryDto()
            {
                Name        = string.Empty,
                Description = "Test",
                Image       = testImage
            };

            _controller.Create(category);
        }
        public void TestGetById_ValidId()
        {
            //Get a valid artefact category
            ArtefactCategoryDto validCategory = GetArtefactCategory();

            //Try to get this category
            ArtefactCategoryDto categoryResult = _controller.GetById(validCategory.Id);

            Assert.IsNotNull(categoryResult);
            Assert.IsNotNull(categoryResult.Id);
            Assert.AreEqual(validCategory.Id, categoryResult.Id);
        }
        ArtefactCategoryDto CreateTestArtefactCategory()
        {
            ArtefactCategoryDto category = new ArtefactCategoryDto()
            {
                Name        = "Test",
                Description = "Test",
                Image       = testImage
            };

            category = _controller.Create(category);

            return(category);
        }
예제 #8
0
        // GET: ArtefactCategoryDtoes/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var request = new HTTPrequest();
            ArtefactCategoryDto category = await request.Get <ArtefactCategoryDto>("api/artefactCatergory/" + id);

            if (category == null)
            {
                return(HttpNotFound());
            }
            return(View(category));
        }
        public void TestUpdate_InvalidId()
        {
            //Get valid category
            ArtefactCategoryDto category = GetArtefactCategory();

            ArtefactCategoryDto updateCategory = new ArtefactCategoryDto()
            {
                Id          = 0,
                Name        = category.Name,
                Description = category.Description,
                Image       = category.Image
            };

            _controller.Update(updateCategory);
        }
        public void TestGetFiltered_AllFilters()
        {
            //Create Category for getfiltered validation
            ArtefactCategoryDto validCategory = CreateTestArtefactCategory();

            var results = _controller.GetFiltered(new ArtefactFilter()
            {
                isDeleted = false, numPerPage = 100, pageNumber = 0
            });

            Assert.IsNotNull(results);
            Assert.IsTrue(!results.Any(m => m.IsDeleted));
            Assert.IsTrue(results.Count <= 100);
            Assert.IsTrue(results.Count == results.Distinct().Count());
        }
예제 #11
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                var request = new HTTPrequest();
                ArtefactCategoryDto category = await request.Get <ArtefactCategoryDto>("api/artefactCatergory/" + id);

                await request.Delete("api/artefactCatergory/" + id);

                return(RedirectToAction("Index", new { recentAction = "Editted", recentName = category.Name, recentId = category.Id }));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void TestUpdate_NoImage()
        {
            //Get valid category
            ArtefactCategoryDto category = GetArtefactCategory();

            category.Name        = "Test Edit";
            category.Description = "Test Edit";
            category.Image       = null;

            ArtefactCategoryDto updatedCategory = _controller.Update(category);

            Assert.IsNotNull(updatedCategory);
            Assert.IsNotNull(updatedCategory.Id);
            Assert.AreEqual(category.Id, updatedCategory.Id);
            Assert.AreEqual(category.Name, updatedCategory.Name);
            Assert.AreEqual(category.Description, updatedCategory.Description);
        }
        public void TestCreate_NoImage()
        {
            //Set up dto
            ArtefactCategoryDto category = new ArtefactCategoryDto()
            {
                Name        = "Test",
                Description = "Test",
                Image       = null
            };

            //Make test request
            ArtefactCategoryDto categoryResult = _controller.Create(category);

            //Assert Values
            Assert.IsNotNull(categoryResult);
            Assert.IsNotNull(categoryResult.Id);
            Assert.IsTrue(categoryResult.Id != 0);
        }
        public void TestDelete_ValidId()
        {
            //Get valid category
            ArtefactCategoryDto validCategory = GetArtefactCategory();

            //Delete category
            bool result = _controller.Delete(validCategory.Id);

            Assert.IsTrue(result);

            //Get Category for comparison
            ArtefactCategoryDto categoryResult = _controller.GetById(validCategory.Id);

            Assert.IsNotNull(categoryResult);
            Assert.IsNotNull(categoryResult.Id);
            Assert.AreEqual(validCategory.Id, categoryResult.Id);
            Assert.IsTrue(categoryResult.IsDeleted);
        }
        public void TestGetFiltered_IsDeleted()
        {
            //Create a category to test on
            ArtefactCategoryDto validCategory = CreateTestArtefactCategory();

            //delete for test
            _controller.Delete(validCategory.Id);

            var results = _controller.GetFiltered(new ApiFilter()
            {
                isDeleted = true, numPerPage = 100, pageNumber = 0
            });

            Assert.IsNotNull(results);
            Assert.IsTrue(!results.Any(m => !m.IsDeleted));
            Assert.IsTrue(results.Count <= 100);
            Assert.IsTrue(results.Count == results.Distinct().Count());
        }
        public void TestCreate_ShouldSucceed()
        {
            //Set up dto
            ArtefactCategoryDto category = new ArtefactCategoryDto()
            {
                Name        = "Test",
                Description = "Test",
                Image       = testImage
            };

            //Make test request
            ArtefactCategoryDto categoryResult = _controller.Create(category);

            //Assert Values
            Assert.IsNotNull(categoryResult);
            Assert.IsNotNull(categoryResult.Id);
            Assert.IsTrue(categoryResult.Id != 0);
            Assert.AreEqual(category.Name, categoryResult.Name);
            Assert.AreEqual(category.Description, categoryResult.Description);
            Assert.IsNotNull(categoryResult.CreatedDate);
            Assert.IsNotNull(categoryResult.ModifiedDate);
        }
        public ArtefactCategoryDto Create(ArtefactCategoryDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArgumentNullException("Name");
            }

            ArtefactCategory category = new ArtefactCategory
            {
                Name         = dto.Name,
                Description  = dto.Description,
                Image        = dto.Image,
                CreatedDate  = DateTime.UtcNow,
                ModifiedDate = DateTime.UtcNow,
                IsDeleted    = false
            };

            Db.ArtefactCategories.Add(category);

            Db.SaveChanges();

            return(Mapper.Map <ArtefactCategoryDto>(category));
        }
        public ArtefactCategoryDto Update(ArtefactCategoryDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArgumentNullException("Name");
            }

            ArtefactCategory category = Db.ArtefactCategories.FirstOrDefault(m => m.Id == dto.Id);

            if (category == null)
            {
                NotFoundException();
            }

            category.Name         = dto.Name;
            category.Description  = dto.Description;
            category.Image        = dto.Image;
            category.ModifiedDate = DateTime.UtcNow;
            category.IsDeleted    = dto.IsDeleted;

            Db.SaveChanges();

            return(Mapper.Map <ArtefactCategoryDto>(category));
        }