/// <summary> /// Create fingerprint for provider /// </summary> /// <param name="providerId">Target provider id</param> /// <param name="model">Create fingerprint model</param> /// <returns>Provider fingerprint display model</returns> public async Task <ProviderFingerprintDisplayModel> CreateFingerprint(string providerId, ProviderFingerprintCreateModel model) { if (string.IsNullOrWhiteSpace(providerId)) { throw new ModelDamagedException(nameof(providerId), "is required"); } if (model == null) { throw new ModelDamagedException(nameof(model), "is required"); } if (string.IsNullOrWhiteSpace(model.Name)) { throw new ModelDamagedException(nameof(model.Name), "is required"); } var entity = await _providerRepository.Get(providerId); if (entity == null) { throw new EntityNotFoundException(providerId, typeof(Provider)); } if (entity.Owner.Id != (await GetCurrentUser())?.Id) { throw new AccessDeniedException(entity.Id, typeof(Provider)); } if (entity.Fingerprints == null) { entity.Fingerprints = new List <ProviderFingerprint>(); } if (entity.Fingerprints.Any(x => x.Name.ToLower() == model.Name.ToLower())) { throw new MRSystemException($"Fingerprint with name {model.Name} already exists"); } if (entity.Fingerprints == null) { entity.Fingerprints = new List <ProviderFingerprint>(); } var fingerprint = _mapper.Map <ProviderFingerprint>(model); fingerprint.Fingerprint = FingerprintGenerator.Generate(); fingerprint.FingerprintUpdateTime = DateTime.UtcNow; entity.Fingerprints.Add(fingerprint); await _providerRepository.UpdateFingerprints(entity); return(_mapper.Map <ProviderFingerprintDisplayModel>(fingerprint)); }
public void Get_Success_ReturnEntity() { // Arrange var repository = new ProviderRepository(); var input = repository.Create(GenerateInput()); // Act var result = repository.Get(input.Id); // Assert Assert.IsInstanceOf <Provider>(result); }
public void Delete_Success_ReturnNull() { // Arrange var repository = new ProviderRepository(); var input = repository.Create(GenerateInput()); // Act repository.Delete(input.Id); var result = repository.Get(input.Id); // Assert Assert.IsNull(result); }
private void DeleteBtn_Click(object sender, EventArgs e) { DataGridViewRow selectedRow = new DataGridViewRow(); int idToDelete; try { selectedRow = DgvGeneric.SelectedRows[0]; idToDelete = int.Parse(selectedRow.Cells[0].Value.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } switch (activeGrid) { case 0: if (idToDelete == employeeRepo.Get(idToDelete).Id) { employeeRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; case 1: if (idToDelete == departmentRepo.Get(idToDelete).Id) { departmentRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; case 2: if (idToDelete == itemRepo.Get(idToDelete).Id) { itemRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; case 3: if (idToDelete == brandRepo.Get(idToDelete).Id) { brandRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; case 4: if (idToDelete == unitRepo.Get(idToDelete).Id) { unitRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; case 5: if (idToDelete == providerRepo.Get(idToDelete).Id) { providerRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; case 6: // if (idToDelete == requestRepo.Get(idToDelete).Id) // { // requestRepo.Delete(idToDelete); // ShowDeletedMessage(sender, e); // } break; case 7: // if (idToDelete == orderRepo.Get(idToDelete).Id) // { // orderRepo.Delete(idToDelete); // ShowDeletedMessage(sender, e); // } break; case 8: if (idToDelete == userRepo.Get(idToDelete).Id) { userRepo.Delete(idToDelete); ShowDeletedMessage(sender, e); } break; } }
public Provider Id(int id) { return(_repository.Get(id)); }