public void AddCaseOk()
        {
            NSI.REST.Models.CaseCategoryCreateModel caseCategory = new CaseCategoryCreateModel()
            {
                CaseCategoryName = "firstCase",
                IsDeleted        = false,
                CustomerId       = 1,
                DateCreated      = DateTime.Now,
                DateModified     = DateTime.Now
            };

            var caseCategory1 = new CaseCategoryDto
            {
                CaseCategoryName = "firstCase",
                IsDeleted        = false,
                CustomerId       = 1,
                DateCreated      = DateTime.Now,
                DateModified     = DateTime.Now
            };

            var mockRepo = new Mock <IAdminRepository>();

            mockRepo.Setup(x => x.CreateCaseCategory(It.IsAny <CaseCategoryDto>())).Returns(caseCategory1);
            var adminManipulation = new AdminManipulation(mockRepo.Object);
            var controller        = new AdminController(adminManipulation);
            var result            = controller.PostCase(caseCategory);

            Assert.IsType <OkObjectResult>(result);
        }
예제 #2
0
        public void AddContactTest()
        {
            //Empty Model

            var controller = new AdminController(this.adminManipulation);

            // Empty Model state
            controller.ModelState.AddModelError("error", "some error");

            var result = controller.PostCase(new CaseCategoryDto());

            Assert.IsType <BadRequestObjectResult>(result);

            //Bad Case Model

            var caseCategory = new CaseCategoryDto()
            {
                CaseCategoryId   = 1,
                CaseCategoryName = "firstCase",
                IsDeleted        = false,
            };

            result = controller.PostCase(caseCategory);
            Assert.IsType <BadRequestObjectResult>(result);

            //Bad Validation

            caseCategory.CaseCategoryName = "----------!!!";
            caseCategory.CustomerId       = 1;
            result = controller.PostCase(caseCategory);
            Assert.IsType <BadRequestObjectResult>(result);
        }
예제 #3
0
        public void UpdateCaseCategoryTest()
        {
            var caseCategory = new CaseCategoryDto()
            {
                CaseCategoryId   = 10,
                CaseCategoryName = "firstCase",
                IsDeleted        = false,
                CustomerId       = 1,
                DateCreated      = DateTime.Now,
                DateModified     = DateTime.Now
            };

            var mockRepo = new Mock <IAdminManipulation>();

            mockRepo.Setup(x => x.CreateCaseCategory(It.IsAny <CaseCategoryDto>())).Returns(caseCategory);
            var controller = new AdminController(mockRepo.Object);

            controller.PostCase(caseCategory);

            //No content Result

            caseCategory.CaseCategoryName = "NewName";
            var result = controller.PutCase(1, caseCategory);

            Assert.IsType <NoContentResult>(result);

            //Bad Case Model
            controller.ModelState.AddModelError("error", "some error");

            result = controller.PutCase(30, model: null);
            Assert.IsType <BadRequestObjectResult>(result);
        }
예제 #4
0
 public IActionResult PostCase([FromBody] CaseCategoryDto model)
 {
     Console.Write(model);
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var caseCategory = adminRepository.CreateCaseCategory(model);
         if (caseCategory != null)
         {
             return(Ok(caseCategory));
         }
         else
         {
             return(NoContent());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
     return(NoContent());
 }
예제 #5
0
        public void DeleteCaseCategoryTest()
        {
            var caseCategory = new CaseCategoryDto()
            {
                CaseCategoryId   = 10,
                CaseCategoryName = "firstCase",
                IsDeleted        = false,
                CustomerId       = 1,
                DateCreated      = DateTime.Now,
                DateModified     = DateTime.Now
            };

            var mockRepo   = new Mock <IAdminManipulation>();
            var controller = new AdminController(mockRepo.Object);

            controller.ModelState.AddModelError("error", "some error");

            // Invalid Model
            var result = controller.DeleteCase(10000);

            Assert.IsType <NoContentResult>(result);

            //OK
            mockRepo.Setup(x => x.CreateCaseCategory(It.IsAny <CaseCategoryDto>())).Returns(caseCategory);
            mockRepo.Setup(x => x.DeleteCaseCategoryById(It.IsAny <int>())).Returns(true);
            controller.PostCase(caseCategory);

            result = controller.DeleteCase(10);
            Assert.IsType <OkObjectResult>(result);
        }
예제 #6
0
        public IActionResult PostCase([FromBody] CaseCategoryCreateModel model)
        {
            Console.Write(model);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CaseCategoryDto caseCategoryDto = new CaseCategoryDto()
            {
                CaseCategoryName = model.CaseCategoryName,
                CustomerId       = model.CustomerId,
                DateCreated      = DateTime.Now,
                DateModified     = DateTime.Now
            };

            try
            {
                var caseCategory = adminRepository.CreateCaseCategory(caseCategoryDto);
                if (caseCategory != null)
                {
                    return(Ok(caseCategory));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(NoContent());
        }
예제 #7
0
        public CaseCategoryDto CreateCaseCategory(CaseCategoryDto model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "Model is null!");
            }


            var sameName = _dbContext.CaseCategory.FirstOrDefault(x => x.CaseCategoryName == model.CaseCategoryName && x.IsDeleted == false);

            if (sameName != null)
            {
                throw new Exception("Case category with this name already exists.");
            }

            try
            {
                var caseCategory = Mappers.AdminRepository.MapToDbEntity(model);
                caseCategory.DateModified = caseCategory.DateCreated = DateTime.Now;
                caseCategory.IsDeleted    = false;
                _dbContext.Add(caseCategory);
                if (_dbContext.SaveChanges() != 0)
                {
                    return(Mappers.AdminRepository.MapToDto(caseCategory));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                throw new Exception("Cannot create new case category!");
            }
            return(null);
        }
예제 #8
0
        public IActionResult PutCase(int id, [FromBody] CaseCategoryEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CaseCategoryDto caseCategoryDto = new CaseCategoryDto()
            {
                CaseCategoryId   = model.CaseCategoryId,
                CaseCategoryName = model.CaseCategoryName,
                CustomerId       = model.CustomerId,
                DateCreated      = DateTime.Now,
                DateModified     = DateTime.Now
            };

            try
            {
                var caseCategory = adminRepository.EditCaseCategory(id, caseCategoryDto);
                if (caseCategory)
                {
                    return(Ok(caseCategory));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #9
0
        //Case Category

        public static CaseCategory MapToDbEntity(CaseCategoryDto caseCategoryDto)
        {
            return(new CaseCategory()
            {
                CaseCategoryId = caseCategoryDto.CaseCategoryId,
                CaseCategoryName = caseCategoryDto.CaseCategoryName,
                DateCreated = caseCategoryDto.DateCreated,
                DateModified = caseCategoryDto.DateModified,
                IsDeleted = caseCategoryDto.IsDeleted,
                CustomerId = caseCategoryDto.CustomerId
            });
        }
예제 #10
0
        public async Task DeleteRecursive(List <CaseCategory> category)
        {
            CaseCategoryDto dto = new CaseCategoryDto();

            foreach (var item in category)
            {
                await DeleteRecursive(item.Children);

                var del = await CatGetById(item.CaseCategoryId);

                _context.CaseCategories.Remove(del);
            }
            await _context.SaveChangesAsync();
        }
예제 #11
0
 public CaseCategoryDto CreateCaseCategory(CaseCategoryDto caseCategoryDto)
 {
     try
     {
         var caseCategory = Mappers.AdminRepository.MapToDbEntity(caseCategoryDto);
         caseCategory.DateModified = caseCategory.DateCreated = DateTime.Now;
         caseCategory.IsDeleted    = false;
         _dbContext.Add(caseCategory);
         if (_dbContext.SaveChanges() != 0)
         {
             return(Mappers.AdminRepository.MapToDto(caseCategory));
         }
     }
     catch (Exception ex)
     {
         //log ex
         throw new Exception(ex.Message);
     }
     return(null);
 }
예제 #12
0
 public bool EditCaseCategory(int caseCategoryId, CaseCategoryDto model)
 {
     try
     {
         var caseCategory = _dbContext.CaseCategory.FirstOrDefault(x => x.CaseCategoryId == caseCategoryId);
         if (caseCategory != null)
         {
             caseCategory.CaseCategoryName = model.CaseCategoryName;
             caseCategory.CustomerId       = model.CustomerId;
             caseCategory.DateModified     = DateTime.Now;
             _dbContext.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.InnerException);
         throw new Exception("Cannot update case category!");
     }
 }
예제 #13
0
 public bool EditCaseCategory(int caseCategoryId, CaseCategoryDto caseCategoryDto)
 {
     try
     {
         var caseCategory = _dbContext.CaseCategory.FirstOrDefault(x => x.CaseCategoryId == caseCategoryId);
         if (caseCategory != null)
         {
             caseCategory.CaseCategoryName = caseCategoryDto.CaseCategoryName;
             caseCategory.CustomerId       = caseCategoryDto.CustomerId;
             caseCategory.DateModified     = DateTime.Now;
             _dbContext.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         //log ex
         throw new Exception(ex.Message);
     }
 }
예제 #14
0
 public IActionResult PutCase(int id, [FromBody] CaseCategoryDto model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var caseCategory = adminRepository.EditCaseCategory(id, model);
         if (caseCategory)
         {
             return(Ok(caseCategory));
         }
         else
         {
             return(NoContent());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #15
0
 public CaseCategoryDto CreateCaseCategory(CaseCategoryDto model)
 {
     return(_adminRepository.CreateCaseCategory(model));
 }
예제 #16
0
 public ClientTypeDto CreateClientType(CaseCategoryDto model)
 {
     throw new NotImplementedException();
 }
예제 #17
0
 public bool EditCaseCategory(int caseCategoryId, CaseCategoryDto caseCategory)
 {
     return(_adminRepository.EditCaseCategory(caseCategoryId, caseCategory));
 }
예제 #18
0
 public CaseCategoryDto CreateCaseCategory(CaseCategoryDto caseCategoryDto)
 {
     return(_adminRepository.CreateCaseCategory(caseCategoryDto));
 }