public async Task <IHttpActionResult> Put(ChangeShopMarketerCommand command) { command.UserInfo = new UserInfoCommandItem(UserId, FirstName, LastName); var response = await Bus.Send <ChangeShopMarketerCommand, MarketerCommandResponse>(command); return(Ok(response)); }
public async Task <MarketerCommandResponse> Handle(ChangeShopMarketerCommand command) { var shop = await _shopRepository.FindAsync(command.ShopId); if (shop == null) { throw new DomainException("فروشگاه یافت نشد"); } var marketer = await _repository.FindAsync(shop.MarketerId); if (marketer == null) { throw new DomainException("بازاریاب یافت نشد"); } var newMarketer = await _repository.FindAsync(command.NewMarketerId); if (newMarketer == null) { throw new DomainException("بازاریاب جدید یافت نشد"); } shop.MarketerId = newMarketer.Id; if (newMarketer.Equals(marketer)) { throw new DomainException("بازایاب انتخابی شما با بازاریاب کنونی یکی است"); } DomainEventDispatcher.Raise(new DetachedShopMarketersHistoryEvent(shop, marketer, new UserInfo(command.UserInfo.UserId, command.UserInfo.FirstName, command.UserInfo.LastName))); DomainEventDispatcher.Raise(new AssignmentShopMarketersHistoryEvent(shop, marketer, new UserInfo(command.UserInfo.UserId, command.UserInfo.FirstName, command.UserInfo.LastName))); return(new MarketerCommandResponse()); }