public IHttpActionResult AddCategory(CategoryResponseModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Category category = new Category(model); //Beacon beacon = new Beacon() //{ // Beacon_id = model.Beacon_id, // Beacon_major = model.Beacon_major, // Beacon_minor = model.Beacon_minor, // Beacon_message = model.Beacon_message, // Beacon_rssi = model.Beacon_rssi, // Beacon_title = model.Beacon_title, // Beacon_trigger_interval = model.Beacon_trigger_interval, // Beacon_trigger_proximity = model.Beacon_trigger_proximity, // Beacon_uuid = model.Beacon_uuid, // IsDeleted = false //}; int response = _categoryLog.CategoryInsert(category); //int inserData = binding.Save(); if (response == 1) { return(Ok("Record added to the database")); } else { return(BadRequest("Not able to save the record in database")); } }
public void PutTest() { Category category = GetCategory(); CategoryRequestModel categoryRequest = GetCategoryRequestModel(); CategoryResponseModel categoryResponse = GetCategoryResponseModel(); ValidationResponse <Category> validationResponse = GetOkValidationResponse(); _mockMapper .Setup(mapper => mapper.Map <CategoryRequestModel, Category>(categoryRequest)) .Returns(category); _mockService .Setup(serv => serv.Update(category)) .Returns(validationResponse); _mockMapper .Setup(mapper => mapper.Map <Category, CategoryResponseModel>(validationResponse.ResponseData)) .Returns(categoryResponse); IActionResult actionResult = _controller.Put(_categoryId, categoryRequest); OkObjectResult actual = (OkObjectResult)actionResult; string actualName = ((CategoryResponseModel)actual.Value).Name; Assert.Equal(category.Name, actualName); Assert.Equal(StatusCodes.Status200OK, actual.StatusCode); }
public LegislationGroupItem(CategoryResponseModel model) { this.Heading = model.Heading; foreach (var item in model.Items) { this.Add(item); } }
public CategoryResponseModel ToResponseModel() { CategoryResponseModel p = new CategoryResponseModel { Id = Id, Name = Name, ParentCategoryId = ParentCategoryId }; return(p); }
public IActionResult GetById(Guid id) { ValidationResponse <Category> validationResponse = _categoryService.GetById(id); if (validationResponse.Status == ValidationStatus.NotFound) { return(NotFound(validationResponse.Message)); } CategoryResponseModel categoryResponse = _mapper.Map <Category, CategoryResponseModel>(validationResponse.ResponseData); return(Ok(categoryResponse)); }
public IActionResult Post([FromBody] CategoryRequestModel categoryRequest) { Category category = _mapper.Map <CategoryRequestModel, Category>(categoryRequest); ValidationResponse <Category> validationResponse = _categoryService.Add(category); if (validationResponse.Status == ValidationStatus.Failed) { return(BadRequest(validationResponse.Message)); } CategoryResponseModel categoryResponse = _mapper.Map <Category, CategoryResponseModel>(validationResponse.ResponseData); return(CreatedAtAction("Get", new { id = categoryResponse.Id }, categoryResponse)); }
public async Task <CategoryResponseModel> CreateCategory(CategoryRequestModel requestModel) { if (requestModel == null) { throw new ArgumentNullException(); } var categoryResponse = new CategoryResponseModel() { CategoryName = requestModel.CategoryName, CreateDate = DateTime.Now }; categoryResponse.CategoryId = await _db.CategoriesRequest.CategoriesRequest.CreateAsync(requestModel); return(categoryResponse); }
public IHttpActionResult GetCategories() { var categories = db.Categories.ToList(); List <CategoryResponseModel> categoryResponses = new List <CategoryResponseModel>(); foreach (var category in categories) { CategoryResponseModel model = new CategoryResponseModel() { Id = category.Id, Name = category.Name, }; categoryResponses.Add(model); } return(Ok(categoryResponses)); }
public async Task <IActionResult> Get(Guid?id) { var serviceModel = new GetCategoryServiceModel { Id = id, Language = CultureInfo.CurrentCulture.Name }; var validator = new GetCategoryModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var category = await this.categoryService.GetAsync(serviceModel); if (category != null) { var response = new CategoryResponseModel { Id = category.Id, IsLeaf = category.IsLeaf, Level = category.Level, Name = category.Name, Order = category.Order, ParentCategoryName = category.ParentCategoryName, ParentId = category.ParentId, ThumbnailMediaId = category.ThumbnailMediaId, LastModifiedDate = category.LastModifiedDate, CreatedDate = category.CreatedDate }; return(this.StatusCode((int)HttpStatusCode.OK, response)); } else { return(this.StatusCode((int)HttpStatusCode.NotFound)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); }
public IActionResult Create([FromBody] CategoryCreateRequestModel model) { try { var isExist = CommonSeedModel.CategoriesV1.Exists(x => x.Name == model.Name && x.Status == Status.ACTIVE); if (isExist) { return(UnprocessableEntity(new BaseResponseModel("Aynı isimde aktif bir kategori bulunmaktadır."))); } var category = new CategoryResponseModel(model.Name); CommonSeedModel.CategoriesV1.Add(category); var response = new BaseResponseModel <CategoryResponseModel>(category); return(Created(Request.QueryString.ToString(), this.CreateLinksForCategory(response))); } catch (Exception) { throw; } }
private CategoryResponseModel GetLegDocsByClassifier(SearchApiModel searchModel, string classifier, string headingName, string baseClassifier) { searchModel.Classifiers = new List <string>(); searchModel.Classifiers.Add(baseClassifier); searchModel.Classifiers.Add(classifier); var res = new CategoryResponseModel(); var ids = this.searchService.Search(searchModel); ids = this.euCaselawFilterService.Filter(ids); ids = this.sortService.SortIds(searchModel.Classifiers, ids); var sr = this.docService.GetDocList(ids, searchModel); //sort this.sortService.SortSearchResult(searchModel.Classifiers, sr); res.Items.AddRange(sr.Data); res.Heading = headingName; return(res); }
public IHttpActionResult Put(int id, CategoryResponseModel model) { if (!this.User.IsInRole("Admin")) { return(this.StatusCode(HttpStatusCode.Unauthorized)); } var categoryToUpdate = this.data.Categories .All() .Where(c => c.Id == id) .FirstOrDefault(); if (categoryToUpdate == null) { return(this.NotFound()); } categoryToUpdate.Name = model.Name; data.Savechanges(); return(this.Ok(categoryToUpdate)); }
public void GetByIdTest() { ValidationResponse <Category> validationResponse = GetOkValidationResponse(); CategoryResponseModel categoryResponse = GetCategoryResponseModel(); _mockService .Setup(serv => serv.GetById(_categoryId)) .Returns(validationResponse); _mockMapper .Setup(mapper => mapper.Map <Category, CategoryResponseModel>(validationResponse.ResponseData)) .Returns(categoryResponse); IActionResult actionResult = _controller.GetById(_categoryId); OkObjectResult actual = (OkObjectResult)actionResult; Guid actualId = ((CategoryResponseModel)actual.Value).Id; Assert.Equal(_categoryId, actualId); Assert.Equal(StatusCodes.Status200OK, actual.StatusCode); }
public IActionResult Put(Guid id, [FromBody] CategoryRequestModel categoryRequest) { Category category = _mapper.Map <CategoryRequestModel, Category>(categoryRequest); category.Id = id; ValidationResponse <Category> validationResponse = _categoryService.Update(category); if (validationResponse.Status == ValidationStatus.NotFound) { return(NotFound(validationResponse.Message)); } if (validationResponse.Status == ValidationStatus.Failed) { return(BadRequest(validationResponse.Message)); } CategoryResponseModel categoryResponse = _mapper.Map <Category, CategoryResponseModel>(validationResponse.ResponseData); return(Ok(categoryResponse)); }
public Category(CategoryResponseModel category) { this.Category_id = category.Category_id; this.Category_name = category.Category_name; }
public async Task <IActionResult> Save(CategoryRequestModel request) { var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim); if (request.Id.HasValue) { var serviceModel = new UpdateCategoryServiceModel { Id = request.Id, Files = request.Files, Name = request.Name, ParentId = request.ParentCategoryId, Language = CultureInfo.CurrentCulture.Name, Username = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new UpdateCategoryModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var category = await this.categoryService.UpdateAsync(serviceModel); if (category != null) { var response = new CategoryResponseModel { Id = category.Id, IsLeaf = category.IsLeaf, Level = category.Level, Name = category.Name, Order = category.Order, ParentCategoryName = category.ParentCategoryName, ParentId = category.ParentId, ThumbnailMediaId = category.ThumbnailMediaId, LastModifiedDate = category.LastModifiedDate, CreatedDate = category.CreatedDate }; return(this.StatusCode((int)HttpStatusCode.OK, response)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); } else { var serviceModel = new CreateCategoryServiceModel { Name = request.Name, ParentId = request.ParentCategoryId, Files = request.Files, Language = CultureInfo.CurrentCulture.Name, Username = this.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value, OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value) }; var validator = new CreateCategoryModelValidator(); var validationResult = await validator.ValidateAsync(serviceModel); if (validationResult.IsValid) { var category = await this.categoryService.CreateAsync(serviceModel); if (category != null) { var response = new CategoryResponseModel { Id = category.Id, IsLeaf = category.IsLeaf, Level = category.Level, Name = category.Name, Order = category.Order, ParentCategoryName = category.ParentCategoryName, ParentId = category.ParentId, ThumbnailMediaId = category.ThumbnailMediaId, LastModifiedDate = category.LastModifiedDate, CreatedDate = category.CreatedDate }; return(this.StatusCode((int)HttpStatusCode.Created, response)); } } throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity); } }
public IHttpActionResult Put(int id, CategoryResponseModel model) { if (!this.User.IsInRole("Admin")) { return this.StatusCode(HttpStatusCode.Unauthorized); } var categoryToUpdate = this.data.Categories .All() .Where(c => c.Id == id) .FirstOrDefault(); if (categoryToUpdate == null) { return this.NotFound(); } categoryToUpdate.Name = model.Name; data.Savechanges(); return this.Ok(categoryToUpdate); }