public async Task <RequestResult <ResourceTypeViewModel> > GetResourceType(int resTypeId) { var resType = await _resourceTypeRepository.FindResourceType(resTypeId, false); return(resType == null ? RequestResult <ResourceTypeViewModel> .Failed("Тип не найден") : RequestResult <ResourceTypeViewModel> .Success(new ResourceTypeViewModel(resType))); }
public async Task <RequestResult <ResourceParameterViewModel> > AddResourceParameter(int resTypeId, CreateResourceParameterViewModel parameterViewModel) { var existingParam = await _resourceParameterRepository.GetResourceParametersByType(resTypeId); if (existingParam.Count(p => p.ResourceParameterName == parameterViewModel.Name || p.ResourceParameterAlias == parameterViewModel.Alias) > 0) { return(RequestResult <ResourceParameterViewModel> .Failed("У этого типа параметр с таким именем или псевдонимом уже существует")); } var resType = await _resourceTypeRepository.FindResourceType(resTypeId, false); var resParam = new ResourceParameter { ResourceParameterName = parameterViewModel.Name, ResourceParameterAlias = parameterViewModel.Alias, ResourceType = resType }; await _resourceParameterRepository.AddResourceParameter(resParam); return(RequestResult <ResourceParameterViewModel> .Success(new ResourceParameterViewModel(resParam))); }
public async Task <RequestResult <ResourceViewModel> > AddResource(int typeId, CreateResourceViewModel resourceViewModel) { var resType = await _resourceTypeRepository.FindResourceType(typeId, true); if (resType == null) { return(RequestResult <ResourceViewModel> .Failed("Тип ресурса не найден")); } var existingResource = await _resourceRepository.FindResourceByName(resourceViewModel.Name); if (existingResource != null) { return(RequestResult <ResourceViewModel> .Failed("Ресурс с таким именем уже существует")); } var resParameterValues = resType.ResourceParameters.Select(resParam => new ResourceParameterValue { ParameterValue = "", ResourceParameter = resParam }).ToList(); await _resourceParameterValueRepository.AddResourceParameterValues(resParameterValues); var resource = new Resource { ResourceName = resourceViewModel.Name, Price = resourceViewModel.Price, ResourceType = resType, ResourceParameterValues = resParameterValues }; await _resourceRepository.AddResource(resource); return(RequestResult <ResourceViewModel> .Success(new ResourceViewModel(resource))); }