예제 #1
0
        public CurrencyCRUDStatus Add(EditCurrencyData model)
        {
            if (_queries.GetCurrencies().Any(c => c.Code == model.Code))
            {
                return(new CurrencyCRUDStatus {
                    IsSuccess = false, Message = "codeUnique"
                });
            }

            if (_queries.GetCurrencies().Any(c => c.Name == model.Name))
            {
                return(new CurrencyCRUDStatus {
                    IsSuccess = false, Message = "nameUnique"
                });
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var username = _actorInfoProvider.Actor.UserName;
                var currency = new Currency
                {
                    Code        = model.Code,
                    CreatedBy   = username,
                    DateCreated = DateTimeOffset.UtcNow,
                    Name        = model.Name,
                    Remarks     = model.Remarks
                };

                _paymentRepository.Currencies.Add(currency);
                _paymentRepository.SaveChanges();

                var currencyCreated = new CurrencyCreated
                {
                    Code    = currency.Code,
                    Name    = currency.Name,
                    Remarks = currency.Remarks,
                    Status  = currency.Status
                };

                _eventBus.Publish(currencyCreated);

                scope.Complete();
            }

            return(new CurrencyCRUDStatus {
                IsSuccess = true, Message = "created"
            });
        }
예제 #2
0
        public IHttpActionResult List([FromUri] SearchPackage searchPackage)
        {
            var dataBuilder = new SearchPackageDataBuilder <Currency>(searchPackage,
                                                                      _paymentQueries.GetCurrencies());

            dataBuilder.Map(
                c => c.Code,
                c => new object[]
            {
                c.Code,
                c.Name,
                c.Status.ToString(),
                c.CreatedBy,
                Format.FormatDate(c.DateCreated, false),
                c.UpdatedBy,
                Format.FormatDate(c.DateUpdated, false),
                c.ActivatedBy,
                Format.FormatDate(c.DateActivated, false),
                c.DeactivatedBy,
                Format.FormatDate(c.DateDeactivated, false),
                c.Remarks
            });

            return(Ok(dataBuilder.GetPageData(c => c.Code)));
        }