public async Task <IActionResult> Create(int id) { var organization = await _bll.OrganizationsService.GetOrganizationWithCategoriesAsync(id); if (organization == null) { return(BadRequest()); } var vm = new CreateChangeViewModel { OrganizationName = organization.Name, OrganizationId = organization.Id, Categories = organization.Categories .Select(dto => new SelectListItem(dto.CategoryName, dto.CategoryId.ToString())) .ToList() }; return(View(vm)); }
public async Task <IActionResult> Create(CreateChangeViewModel vm) { if (ModelState.IsValid) { var changeDto = new BLLChangeDTO() { OrganizationId = vm.OrganizationId, Name = vm.ChangeName, CurrentPrice = vm.Price, Categories = vm.SelectedCategories.Select(id => new BLLCategoryMinDTO(id)).ToList() }; var result = await _bll.ChangeService.AddChangeAsync(changeDto); if (result == false) { return(BadRequest("Something went wrong while adding change")); } } return(RedirectToAction("Organization", "Dashboard", new { Id = vm.OrganizationId })); }