public static TimeoutHydratable Load(IRepository repository) { var message = new CurrentTimeMessage(DateTime.MinValue); var delivery = new Delivery <CurrentTimeMessage>(message, null, 0, false, true); return((TimeoutHydratable)repository.Load(delivery).Single()); }
public HttpResponseMessage Delete(long Id) { var list = _repo.Load(Id); _repo.Delete(list); return(Request.CreateResponse(HttpStatusCode.NoContent)); }
public ScheduleGenerator(IRepository repo, IWebHostEnvironment webHostEnvironment) { repository = repo; _webHostEnvironment = webHostEnvironment; repository.Load(); schedule = new List <ScheduleRow>(); }
public void UpdateTask(UpdateTaskInput input) { //可以直接Logger,它在ApplicationService基类中定义的 Logger.Info("Updating a task for input: " + input); //通过仓储基类的通用方法Get,获取指定Id的Task实体对象 var task = _taskRepository.Get(input.TaskId); //修改task实体的属性值 if (input.State.HasValue) { task.State = input.State.Value; } if (input.AssignedPersonId.HasValue) { task.AssignedPerson = _personRepository.Load(input.AssignedPersonId.Value); } //我们都不需要调用Update方法 //因为应用服务层的方法默认开启了工作单元模式(Unit of Work) //ABP框架会工作单元完成时自动保存对实体的所有更改,除非有异常抛出。有异常时会自动回滚,因为工作单元默认开启数据库事务。 //We even do not call Update method of the repository. //Because an application service method is a 'unit of work' scope as default. //ABP automatically saves all changes when a 'unit of work' scope ends (without any exception). }
public void Handle(CloseExampleCommand message) { var entity = _repository.Load <ExampleEntity>(message.Id); entity.Close(); _repository.Save(entity); }
public void Handle(ApplyForDinnerCommand command) { using (new UnitOfWork()) { var dinner = _dinnerRepository.Load(command.DinnerId); var user = _userRepository.Load(command.UserId); if (dinner == null || user == null) { return; } if (_dinnerApplicantRepository.Find().SingleOrDefault(x => (x.User == user || x.Partner == user) && x.Dinner == dinner) != null) { return; } var application = new DinnerApplicant(user, dinner); if (!string.IsNullOrEmpty(command.PartnerEmail)) { application.VerificationCode = Guid.NewGuid(); application.Partner = _userRepository.Find().Single(x => x.Email == command.PartnerEmail); var email = new Email { Address = application.Partner.Email, Priority = 1, TemplateName = "ConfirmInvitation", Payload = Json.Encode(new { VerificationUrl = command.ConfirmUrl + "?token=" + application.VerificationCode }) }; _emailRepository.Save(email); } dinner.Applicants.Add(application); user.AppliedDinners.Add(application); } }
public BlogPostViewModel Save(BlogPostAddViewModel inModel) { var post = new Post(); if (inModel.Id.IsNotEmpty()) { post = _repository.Load <Post>(new Guid(inModel.Id)); } post.Title = inModel.Title; post.BodyShort = inModel.BodyShort; post.Body = inModel.Body; post.Slug = inModel.Slug; // Looks like oxite is doing this in jQuery so don't need: post.Slug.IsEmpty() ? _slugService.CreateSlugFromText(inModel.Slug.IsEmpty() ? inModel.Title : inModel.Slug) : post.Slug; post.User = inModel.CurrentUser; post.Published = inModel.Published; if (inModel.Tags.IsNotEmpty()) { var tags = inModel.Tags.Split(','); tags.Each(tag => { if (tag.Trim().IsNotEmpty()) { post.AddTag(_tagService.CreateOrGetTagForItem(tag.ToLowerInvariant().Trim())); } }); } //Todo: Validation on input _repository.Save(post); return(new BlogPostViewModel()); }
public async Task UpdatePrice_SuccessfulResponse_ValidDataExistingCommodity() { // Arrange var mediator = _serviceProvider.GetService <IMediator>(); const decimal commodityPriceAfterUpdate = decimal.One; var commodity = _fixture .Build <Commodity>() .With(x => x.Price, decimal.Zero) .Create(); _commodityRepository.Load(Arg.Is(commodity.Id)) .Returns(commodity); _commodityRepository.Save(Arg.Any <Commodity>()) .Returns(true); // Act var getCategoryResponse = await mediator.Send(new UpdatePriceCommand { Price = commodityPriceAfterUpdate, CommodityId = commodity.Id }); // Assert getCategoryResponse.Should().NotBeNull(); getCategoryResponse.Value.Should().BeTrue(); commodity.Price.Should().Be(commodityPriceAfterUpdate); _commodityRepository.Received(1).Load(Arg.Any <long>()); _commodityRepository.Received(1).Save(Arg.Any <Commodity>()); }
private void OnLoginCommand(object obj) { if (_loginWindow != null) { return; } _loginWindow = new LoginWindow(_repo.Auth); _loginWindow.ShowDialog(); if (_loginWindow.DialogResult == true) { var remoteRepo = new RemoteRepository(); _repo = remoteRepo; remoteRepo.UpdateAuth(_loginWindow.Auth); _repo.Load(); App.Repo = _repo; CurrentAuth.UserName = _repo.Auth.UserName; Shortcuts.Clear(); foreach (var item in _repo.ShortcutItems) { Shortcuts.Add(item); } App.EA.GetEvent <ItemChanged>().Publish(new List <ShortcutModel>(App.Repo.ShortcutItems)); } _loginWindow = null; }
public int CreateTask(CreateTaskInput input) { //We can use Logger, it's defined in ApplicationService class. Logger.Info("Creating a task for input: " + input); var task = Mapper.Map <Task>(input); task.CreationTime = Clock.Now; if (input.AssignedPersonId.HasValue) { task.AssignedPerson = _userRepository.Load(input.AssignedPersonId.Value); var message = "You hava been assigned one task into your todo list."; //TODO:需要重新配置QQ邮箱密码 //SmtpEmailSender emailSender = new SmtpEmailSender(_smtpEmialSenderConfig); //emailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message); _notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null, NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() }); } //Saving entity with standard Insert method of repositories. return(_taskRepository.InsertAndGetId(task)); }
public int CreateTask(CreateTaskInput input) { //We can use Logger, it's defined in ApplicationService class. Logger.Info("Creating a task for input: " + input); var task = Mapper.Map <Task>(input); int result = _taskRepository.InsertAndGetId(task); //只有创建成功才发送邮件和通知 if (result > 0) { if (input.AssignedPersonId.HasValue) { var user = _userRepository.Load(input.AssignedPersonId.Value); //task.AssignedPerson = user; //var message = "You hava been assigned one task into your todo list."; //使用领域事件触发发送通知操作 _eventBus.Trigger(new TaskAssignedEventData(task, user)); //TODO:需要重新配置QQ邮箱密码 //_smtpEmailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message); //_notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null, // NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() }); } } return(result); }
public RepositoryTasks(Action <TParams, CancellationToken> taskHandler, IRepository <TParams> repository, int?parallel = null, IEqualityComparer <TParams> comparer = null) : base(taskHandler, parallel, comparer) { _repository = repository; TasksGetter = () => { lock (repository) { if (ReloadAuto) { repository.Save(); repository.Load(); } return(repository.Get()); } }; TaskHandlerContinuation = (prms, token) => { lock (repository) { repository.Remove(prms); if (SaveAuto) { repository.Save(); } } }; ReloadAuto = false; SaveAuto = true; }
public void UpdateModel(ViewModel model) { if (model == null) { return; } if (model.CurrentUser.IsAuthenticated) { return; } if (!_cookieHandler.IsCookieThere) { return; } Guid UserId = new Guid(_cookieHandler.UserId); var user = _repository.Load <User>(UserId); if (user != null) { user.IsAuthenticated = false; model.CurrentUser = user; } }
public async Task <Unit> Handle(DoSomethingCommand request, CancellationToken cancellationToken) { var person = await _people.Load(new PersonId("person2")); person.ChangeName("bla", "bla"); return(new Unit()); }
public IList <Operation> GetOperationsByCustomerID(int customerID) { var customer = _repository.Load <Customer>(customerID); var operations = customer.RelatedAccounts.SelectMany(x => _operationRepository.GetOperationsByAccount(x.Key.Id)); return(operations.ToList()); }
public void Handle(AlterPrivateProfileCommand command) { var user = _userRepository.Load(command.UserId); if (user == null) { throw new EntityNotFoundException(); } using (new UnitOfWork()) { user.FirstName = command.FirstName; user.LastName = command.LastName; user.Description = command.Description; user.Age = command.Age; user.Orientation = command.Orientation; user.Gender = command.Gender; user.Friendship = command.Friendship; user.Romance = command.Romance; var latlng = _locationParsingService.GetLatLong(command.Address, command.Suburb, command.City, command.Country, command.Postcode); user.Location = new Location( command.Address, command.Suburb, command.City, command.Country, command.Postcode, latlng.Latitude, latlng.Longitude); _userRepository.Save(user); } }
public static bool Show(IRepository repository, TREInfoFile treInfoFile) { ViewForm viewForm; if (viewForms.TryGetValue(treInfoFile.Path, out viewForm)) { viewForm.Activate(); return(true); } var data = repository.Load <byte[]>( treInfoFile.TreFileName, treInfoFile.Path, stream => stream.ReadBytes()); if (data == null) { return(false); } viewForm = new ViewForm { Repository = repository, TREInfoFile = treInfoFile, Data = data }; viewForms.Add(treInfoFile.Path, viewForm); viewForm.Show(); return(true); }
public void LoadData() { var _loadedItem = Repo.Load(); Auth _auth = _loadedItem.auth; if (_auth.UserName != "로컬사용자" && _auth.UserName != "") { Repo = new RemoteRepository(); ((RemoteRepository)Repo).UpdateAuth(_auth); try { Repo.Load(); } catch (Exception e) { MessageBox.Show(e.Message, "실패", MessageBoxButton.OK); Repo = new LocalRepository(); Repo.Load(); _auth.UserName = "******"; } } else { _auth.UserName = "******"; } }
public Task <IEnumerable <PersistedGrant> > GetAllAsync(string subjectId) { return(Task.Run(async() => { var result = await DbRepository.Load(i => i.SubjectId == subjectId); return result.Select(x => x as PersistedGrant).AsEnumerable(); })); }
public void Load(IRepository <Book> repository) { try { Books.AddRange(repository.Load()); } catch (Exception ex) { throw new BookListServiceException("Incorrect realization of repository", ex); } }
public CMSResult Delete(int subjectId) { CMSResult result = new CMSResult(); var model = _repository.Load <Subject>(x => x.SubjectId == subjectId); if (model == null) { result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("Subject '{0}' already exists!", model.Name) }); } else { var isExistsChapter = _repository.Project <Chapter, bool>(chapters => ( from c in chapters where c.SubjectId == subjectId select c) .Any()); var isExistsMasterFee = _repository.Project <MasterFee, bool>(masterFees => ( from m in masterFees where m.SubjectId == subjectId select m) .Any()); if (isExistsChapter || isExistsMasterFee) { var selectModel = ""; selectModel += (isExistsChapter) ? "Chapter, " : ""; selectModel += (isExistsMasterFee) ? "MasterFee, " : ""; selectModel = selectModel.Trim().TrimEnd(','); result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("You can not delete Subject '{0}'. Because it belongs to {1}!", model.Name, selectModel) }); } else { _repository.Delete(model); result.Results.Add(new Result { IsSuccessful = true, Message = string.Format("Subject '{0}' deleted successfully!", model.Name) }); } } return(result); }
public async Task <IActionResult> Post(Guid AccountId, OpenAccount openAccount) { var account = new AccountAggregate(AccountId); await _accountRepository.Load(account); account.Issue(openAccount); }
public CMSResult Delete(int branchId) { CMSResult result = new CMSResult(); var model = _repository.Load <Branch>(x => x.BranchId == branchId); if (model == null) { result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("Branch '{0}' does not already exists!", model.Name) }); } else { var isExistsBranchAdmin = _repository.Project <BranchAdmin, bool>(branchAdmins => ( from b in branchAdmins where b.BranchId == branchId select b) .Any()); var isExistsMachine = _repository.Project <Machine, bool>(machines => ( from m in machines where m.BranchId == branchId select m) .Any()); if (isExistsBranchAdmin || isExistsMachine) { var selectModel = ""; selectModel += (isExistsBranchAdmin) ? "Branch Admin, " : ""; selectModel += (isExistsMachine) ? "Machine, " : ""; selectModel = selectModel.Trim().TrimEnd(','); result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("You can not delete Branch '{0}'. Because it belongs to {1}!", model.Name, selectModel) }); } else { _repository.Delete(model); result.Results.Add(new Result { IsSuccessful = true, Message = string.Format("Branch '{0}' deleted successfully!", model.Name) }); } } return(result); }
private void OnPlayerConnected(Client player) { PlayerData data = null; try { data = repository.Load <PlayerData>(player.socialClubName); data.LoggedIn = false; // Always set this to false. } catch (Exception e) { // Could not login. } if (data == null || data.Password == null) { // Not found. data = new PlayerData() { SocialClubName = player.socialClubName, Ip = player.address, Skin = PedHash.Acult02AMY, LoggedIn = false }; player.setSkin(PedHash.Acult02AMY); API.sendChatMessageToPlayer(player, new MessageBuilder("Welcome to the server ").Green(player.name).White(", ") .Gray("please use ").Orange("/register <password>").Gray("to register.").ToString()); } else if (data.Ip == player.address) { // Auto login. API.sendChatMessageToPlayer(player, new MessageBuilder("Welcome back ").Green(player.name).White(".").ToString()); LoginPlayer(player, data); } else { // Not logged in. API.sendChatMessageToPlayer(player, new MessageBuilder("Welcome back ").Green(player.name).White(", ") .Gray("please use ").Orange("/login <password>").Gray("to login.").ToString()); } if (!playerData.ContainsKey(player.socialClubName)) { playerData.Add(player.socialClubName, data); } var players = API.shared.getAllPlayers(); foreach (var p in players) { if (p == player) { continue; } API.sendChatMessageToPlayer(p, "~g~" + player.name + " ~w~joined the server!"); } }
public void UpdateCategory(UpdateCategoryInput input) { var cList = _categoryRepository.Get(input.CategoryId); cList.CategoryName = input.CategoryName; cList.Description = input.Description; cList.ParentId = input.ParentId; cList.PList = _programListRepository.Load(input.ProgramListId); }
public async Task Handle(PersonUpdatedDomainEvent notification, CancellationToken cancellationToken) { var person = await _people.Load(notification.PersonId); foreach (var contact in person.Contacts) { await _emailDispatcherService.Dispatch(contact.Email, $"Dear {person.Name.Full}, your account has been modified"); } }
public Driver Get(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException("Missing required parameter id"); } var driver = _repository.Load(id); if (driver == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(null); } Response.StatusCode = (int)HttpStatusCode.OK; return(driver); }
//private List<PicasaEntry> albums; //private int albumIndex; //private PicasaFeed currentAlbum; //private int photoIndex; public PicasaImageService(IRepository<PicasaImageSettings> settingsRepository, IEventAggregator eventAggregator) { EventAggregator = eventAggregator; settings = settingsRepository.Load(); BeginLoadAlbums(); SubscribeToEvents(); }
public CMSResult Delete(int id) { CMSResult result = new CMSResult(); var model = _repository.Load <School>(x => x.SchoolId == id); if (model == null) { result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("School '{0}' does not already exists!", model.Name) }); } else { var isExistsStudent = _repository.Project <Student, bool>(students => ( from s in students where s.SchoolId == id select s) .Any()); //var isExistsAttendance = _repository.Project<Attendance, bool>(attendances => ( // from a in attendances // where a.BatchId == BatchId // select a) // .Any()); if (isExistsStudent) { var selectModel = ""; selectModel += (isExistsStudent) ? "Student, " : ""; selectModel = selectModel.Trim().TrimEnd(','); result.Results.Add(new Result { IsSuccessful = false, Message = string.Format("You can not delete School '{0}'. Because it belongs to {1}!", model.Name, selectModel) }); } else { _repository.Delete(model); result.Results.Add(new Result { IsSuccessful = true, Message = string.Format("School '{0}' deleted successfully!", model.Name) }); } } return(result); }
public CMSResult Update(Attendance oldAttendance) { CMSResult cmsresult = new CMSResult(); var result = new Result(); var isExists = _repository.Project <Attendance, bool>( attedances => (from a in attedances where a.AttendanceId != oldAttendance.AttendanceId && a.ClassId == oldAttendance.ClassId && a.BatchId == oldAttendance.BatchId && a.Date == oldAttendance.Date && a.BranchId == oldAttendance.BranchId select a).Any()); if (isExists) { result.IsSuccessful = false; result.Message = "Attendance not exists!"; } else { var attendance = _repository.Load <Attendance>(x => x.AttendanceId == oldAttendance.AttendanceId); if (attendance == null) { result.IsSuccessful = false; result.Message = "Attendance not exists!"; } else { attendance.ClassId = oldAttendance.ClassId; attendance.BatchId = oldAttendance.BatchId; attendance.UserId = oldAttendance.UserId; attendance.Activity = oldAttendance.Activity; attendance.Date = oldAttendance.Date; attendance.StudentAttendence = oldAttendance.StudentAttendence; attendance.BranchId = oldAttendance.BranchId; attendance.IsManual = oldAttendance.IsManual; _repository.Update(attendance); result.IsSuccessful = true; result.Message = string.Format("Attendance updated successfully!"); } } cmsresult.Results.Add(result); return(cmsresult); }
public async Task <Unit> Handle(AddPersonToTeamCommand request, CancellationToken cancellationToken) { var person = await _person.Load(request.PersonId); var team = await _team.Load(request.TeamId); await team.AddPerson(person); return(new Unit()); }
public FileSystemImageService(IRepository<FileSystemImageSettings> repository, IEventAggregator eventAggregator) { Repository = repository; EventAggregator = eventAggregator; _fileSystemImageSettings = Repository.Load(); BeginLoadImageFiles(); SubscribeToEvents(); }
public WeatherViewModel(IRepository<WeatherSettings> repository, IWeatherService weatherService, IEventAggregator eventAggregator) { EventAggregator = eventAggregator; _weatherService = weatherService; _weatherService.WeatherRetrieved += (s, e) => WeatherReport = e.Payload; _weatherSettings = repository.Load(); GetLatestWeather(); var timer = new DispatcherTimer { Interval = new TimeSpan(0, 1, 0, 0) }; timer.Tick += OnTimerElapsed; timer.Start(); SubscribeToEvents(); }
public void Load(IRepository<Book> repository) { try { Books.AddRange(repository.Load()); } catch(Exception ex) { throw new BookListServiceException("Incorrect realization of repository", ex); } }
public BookListService(IRepository<Book> repository) { Books = repository.Load(); }
public void Load(string path, IRepository serializator) { try { List<Book> list = serializator.Load(path); for (int i = 0; i < list.Count; i++) _books.Add(list[i]); } catch (ArgumentException e) { _log.Warn("Can't read the file. {0}", e.Message); throw; } }
public BookListService(IRepository<Book> repository) { this.Repository = repository; books = Repository.Load(); }