public void AddAsync_NullCheck() { InstrumentModel instr = new InstrumentModel(); _dataRepositoryMock.Setup(x => x.AddAsync((instr))); Assert.ThrowsAsync <ArgumentException>(() => _adminRepo.AddAsync(instr)); }
public async Task <IActionResult> Register(RegisterModel model, int ownerId) { if (ModelState.IsValid) { var admin = await _adminRepository.GetByEmailAsync(model.Email); if (admin == null) { var pwdslt = Hash.Create(model.Password); await _adminRepository.AddAsync(new DomainLayer.Entities.Admin { Email = model.Email, PwdSalt = pwdslt, CreatedAt = DateTime.UtcNow, OwnerId = ownerId }); await Authenticate(model.Email); // аутентификация return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Некорректные логин и(или) пароль"); } return(View(model)); }
public async Task <IActionResult> CreateAdmin(Admin admin) { admin.Password = BCrypt.Net.BCrypt.HashPassword(admin.Password); await _repo.AddAsync(admin); return(CreatedAtAction("GetAdmin", new { id = admin.Id }, admin)); }
public async Task <IActionResult> CreateAdmin(CreateAdminModel model) { if (ModelState.IsValid) { var name = User.Identity.Name; var loggedUser = await _adminRepository.GetByEmailAsync(name); var user = await _adminRepository.GetByEmailAsync(model.Email); if (user == null) { var pwdslt = Hash.Create(model.Password); await _adminRepository.AddAsync(new DomainLayer.Entities.Admin { Email = model.Email, PwdSalt = pwdslt, CreatedAt = DateTime.UtcNow, OwnerId = loggedUser?.Id }); return(RedirectToAction("Index", "Home")); } } return(View(model)); }
public async Task <BaseResponse <Admin> > Handle(CreateAdminCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Admin> { ReponseName = nameof(CreateAdminCommand), Content = new List <Admin> () { } }; var entity = _mapper.Map <Admin> (request); var newentity = await _adminRepository.AddAsync(entity); if (newentity == null) { response.Status = ResponseType.Warning; response.Message = $"{nameof(Admin)} could not be created."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Admin)} created successfully."; response.Content.Add(newentity); } return(response); }