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); }
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); }
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); }
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()); }
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); }
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()); }
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); }
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)); } }
//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 }); }
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(); }
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); }
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!"); } }
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); } }
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)); } }
public CaseCategoryDto CreateCaseCategory(CaseCategoryDto model) { return(_adminRepository.CreateCaseCategory(model)); }
public ClientTypeDto CreateClientType(CaseCategoryDto model) { throw new NotImplementedException(); }
public bool EditCaseCategory(int caseCategoryId, CaseCategoryDto caseCategory) { return(_adminRepository.EditCaseCategory(caseCategoryId, caseCategory)); }
public CaseCategoryDto CreateCaseCategory(CaseCategoryDto caseCategoryDto) { return(_adminRepository.CreateCaseCategory(caseCategoryDto)); }