private void Update(UpdateInput requestDto, ErrorCodeEnum exitedEmail) { dynamic dataInput = requestDto.DataUpdate; if (!(dataInput is ManagerUpdateInput || dataInput is StaffUpdateInput || dataInput is EmployeeUpdateInput)) { throw new BadData(); } User user = _userRepository.GetById((Guid)dataInput.Id); if (user != null) { if (ExisedEmail(email: (string)dataInput.AddressInfo.Email, idUpdate: (Guid)dataInput.Id)) { Log.Information("Email {Email} existed!", (string)dataInput.AddressInfo.Email); throw new DefinedException(exitedEmail); } #region handle variable bool dataStatus = (user.ExpiredDate.Value - DateTime.Now).TotalDays < 0 ? false : (bool)dataInput.Status; StatusEnum valueType = dataStatus ? dataInput is EmployeeUpdateInput ? StatusEnum.Available : StatusEnum.Active : dataInput is EmployeeUpdateInput ? StatusEnum.Unavailable : StatusEnum.Inactive; if (!AllowUnselectGroups((string)dataInput.CountryId, dataInput is ManagerUpdateInput ? (string)dataInput.Groups : (string)dataInput.Group, (string)dataInput.Users, user)) { Log.Information("Cannot unselect the group from the list!", ErrorCodeEnum.CannotUnSelectGroup); throw new DefinedException(ErrorCodeEnum.CannotUnSelectGroup); } #endregion #region update user user.Status = valueType; user.CountryId = (string)dataInput.CountryId; user.FullName = (string)dataInput.FullName; user.Groups = dataInput is ManagerUpdateInput ? (string)dataInput.Groups : (string)dataInput.Group; user.Users = dataInput is EmployeeUpdateInput ? null : user.CountryId.Equals((string)dataInput.CountryId) ? (string)dataInput.Users : string.Empty; user.Address = (string)dataInput.AddressInfo.Address; user.Phone = (string)dataInput.AddressInfo.PhoneNo; user.Email = (string)dataInput.AddressInfo.Email; user.ExpiredDate = (DateTime?)dataInput.ExpiredDate; user.LastUpdatedBy = requestDto.CurrentUser; user.LastUpdateDate = DateTime.Now; #endregion try { _unitOfWork.Update(user); _unitOfWork.Commit(); } catch { Log.Information("Cannot Update " + user.UserTypeStr + ": {Username}.", user.Username); throw new DefinedException(ErrorCodeEnum.CannotUpdateUsers); } } else { Log.Information("Not Found User: {Username}.", (string)dataInput.Username); throw new DefinedException(ErrorCodeEnum.UserNotFound); } }
/// <summary> /// editing encrypted data by id /// </summary> /// <param name="input"></param> /// <returns></returns> public virtual async Task ReplaceEncryptDataAsync(UpdateInput input) { var entity = await sensitiveRepository.GetByIdAsync(Int64.Parse(input.Id)); if (entity == null) { throw new NotFoundException( $"Could not find data with ID {input.Id}."); } var encryptionKey = config.GetCurrentKey(); if (string.IsNullOrWhiteSpace(encryptionKey)) { throw new MissingEncryptionKeyException($"Could not retrieve {entity.EncryptionKeyName}."); } var newData = new SensitiveDataEntity { Id = Int64.Parse(input.Id), Data = dataProtector.Encrypt(encryptionKey, input.ClearText), EncryptionKeyName = config.CurrentKeyName }; sensitiveRepository.Update(newData); }
public void ProductExists_ShouldUpdateTheProduct() { // Arrange var repository = GetEmptyProductRepository(); var sut = new UpdateUseCase(repository); var createUseCase = new CreateUseCase(repository); var getByIdUseCase = new GetByIdUseCase(repository); var id = Guid.NewGuid(); var createInput = new CreateInput { Id = id, Name = "Name", Description = "Description" }; var UpdateInput = new UpdateInput { Id = id, Name = "Name", Description = "Description" }; createUseCase.Execute(createInput); // Act sut.Execute(UpdateInput); var actual = getByIdUseCase.Execute(id); // Assert actual.Id .Should() .Be(id); }
public UpdateOutput <LocationDto, long> Update(UpdateInput <LocationDto, long> input) { Location newLocationEntity = input.Entity.MapTo <Location>(); if (newLocationEntity == null) { throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"Location\""); } if (!LocationPolicy.CanUpdateEntity(newLocationEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"Location\""); } LocationRepository.Includes.Add(r => r.LastModifierUser); LocationRepository.Includes.Add(r => r.CreatorUser); LocationRepository.Update(newLocationEntity); LocationDto newLocationDto = (LocationRepository.Get(newLocationEntity.Id)).MapTo <LocationDto>(); LocationRepository.Includes.Clear(); return(new UpdateOutput <LocationDto, long>() { UpdatedEntity = newLocationDto }); }
public UpdateOutput <GameTaskTypeDto, long> Update(UpdateInput <GameTaskTypeDto, long> input) { throw new NotSupportedException("This method is implemented but it is not safely to use it."); GameTaskType newGameTaskTypeEntity = input.Entity.MapTo <GameTaskType>(); if (newGameTaskTypeEntity == null) { throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"GameTaskType\""); } if (!GameTaskTypePolicy.CanUpdateEntity(newGameTaskTypeEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"GameTaskType\""); } GameTaskTypeRepository.Includes.Add(r => r.LastModifierUser); GameTaskTypeRepository.Includes.Add(r => r.CreatorUser); GameTaskTypeRepository.Update(newGameTaskTypeEntity); GameTaskTypeDto newGameTaskTypeDto = (GameTaskTypeRepository.Get(newGameTaskTypeEntity.Id)).MapTo <GameTaskTypeDto>(); GameTaskTypeRepository.Includes.Clear(); return(new UpdateOutput <GameTaskTypeDto, long>() { UpdatedEntity = newGameTaskTypeDto }); }
public Guid Execute(UpdateInput input) { var product = new Product(input.Id, input.Name, input.Description); _repository.Update(product); return(input.Id); }
public void get_the_list_of_nugets_to_update_with_the_nuget_flag() { var input = new UpdateInput{ NugetFlag = "Nug1" }; input.GetAllNugetNames(theSolution).ShouldHaveTheSameElementsAs("Nug1"); }
public void SetUp() { theSolution = new Solution(); theSolution.AddDependency(new Dependency("FubuCore")); theSolution.AddDependency(new Dependency("Bottles")); theSolution.AddDependency(new Dependency("FubuLocalization")); theInput = new UpdateInput(); }
public void get_the_list_of_nugets_returns_the_specified_nuget_even_if_it_is_locked() { var input = new UpdateInput { NugetFlag = "Nug6" }; input.GetAllNugetNames(theSolution).ShouldHaveTheSameElementsAs("Nug6"); }
/// <summary> /// 新建跟进信息 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task AddUpdateTitle(UpdateInput input) { var title = new UpdateHouse() { Id = GuidGenerator.Create(), HomeListId = input.HouseListId, Comment = input.Comment, //UpdatePerson = input.UpdatePerson }; await _updateHouses.InsertAsync(title); }
public UpdateOutput <UserDto, long> Update(UpdateInput <UserDto, long> input) { User userEntityForUpdate = UserRepository.Get(input.Entity.Id); if (userEntityForUpdate == null) { throw new UserFriendlyException("Inaccessible action!", String.Format("There are no User for update.")); } #region Updating fields for entity User UserRoleRepository.RemoveRange(userEntityForUpdate.Roles); userEntityForUpdate.Roles.Clear(); userEntityForUpdate.Name = String.IsNullOrEmpty(input.Entity.Name) ? userEntityForUpdate.Name : input.Entity.Name; userEntityForUpdate.Surname = String.IsNullOrEmpty(input.Entity.Surname) ? userEntityForUpdate.Surname : input.Entity.Surname; if (!String.IsNullOrEmpty(input.Entity.EmailAddress) && userEntityForUpdate.EmailAddress != input.Entity.EmailAddress) { userEntityForUpdate.EmailAddress = input.Entity.EmailAddress; userEntityForUpdate.IsEmailConfirmed = true; } userEntityForUpdate.PhoneNumber = String.IsNullOrEmpty(input.Entity.PhoneNumber) ? userEntityForUpdate.PhoneNumber : input.Entity.PhoneNumber; IList <long> usingRoleIds = input.Entity.Roles.Select(r => r.Id).ToList(); IList <Role> usingRoles = RoleRepository.GetAll().Where(r => usingRoleIds.Contains(r.Id)).ToList(); foreach (var item in input.Entity.Roles) { Role currentRole = usingRoles.FirstOrDefault(r => r.Id == item.Id); userEntityForUpdate.Roles.Add(new UserRole() { Role = currentRole, RoleId = currentRole.Id, User = userEntityForUpdate, UserId = userEntityForUpdate.Id }); } #endregion UserDto userEntityDto = (UserRepository.Update(userEntityForUpdate)).MapTo <UserDto>(); return(new UpdateOutput <UserDto, long>() { UpdatedEntity = userEntityDto }); }
public void ToggleUseKeyboard() { useKeyboard = !useKeyboard; if (useKeyboard) { autoFire = false; OnUpdateInput = UpdateInputKeyboard; } else { autoFire = true; OnUpdateInput = UpdateInputTouch; } }
void Start() { Init(); if (!useKeyboard) { autoFire = true; OnUpdateInput = UpdateInputTouch; } else { OnUpdateInput = UpdateInputKeyboard; } mainCamera = Camera.main; }
public void TheProductDoesNotExist_ShouldThrowException() { // Arrange var repository = GetEmptyProductRepository(); var sut = new UpdateUseCase(repository); var id = Guid.NewGuid(); var updateInput = new UpdateInput { Id = id, Name = "Name", Description = "Description" }; // Act Action action = () => sut.Execute(updateInput); // Assert action .Should() .Throw <ProductNotFoundException>(); }
// [Authorize] public IActionResult Update(Guid id, UpdateProductRequest request) { try { var input = new UpdateInput { Id = id, Name = request.Name, Description = request.Description }; var productId = _updateUseCase.Execute(input); return(Ok(productId)); } catch (ProductNotFoundException) { return(NotFound()); } }
/// <summary> /// Called when the scene should process input. /// </summary> /// <param name="input"></param> protected virtual void OnUpdateInput(IInputState input) { UpdateInput?.Invoke(this, input); }
public UpdateOutput <TeamRequestDto, long> Update(UpdateInput <TeamRequestDto, long> input) { throw new NotImplementedException(); }
public void Update(UpdateInput updateInput) => Update(updateInput, updateInput.DataUpdate is ManagerUpdateInput ? ErrorCodeEnum.EmailManagerExisted : updateInput.DataUpdate is StaffUpdateInput ? ErrorCodeEnum.EmailStaffExisted : ErrorCodeEnum.EmailEmployeeExisted);
public void SetInputUpdater(UpdateInput function) { updateInput = function; }