예제 #1
0
        public IResponse <NoValue> AddOffer(OfferCreateModel model)
        {
            Logger.Message($"AddOffer({model.Title})");

            var result = new Response <NoValue>();

            try
            {
                var offer = new Offer
                {
                    Title         = model.Title,
                    DateFrom      = model.DateFrom,
                    DateTo        = model.DateTo,
                    UserSegmentID = model.UserSegment,
                    Messages      = model.Messages,
                    Active        = true,
                };

                _uow.Offers.Add(offer);
                _uow.Complete();
                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                result.Message = Message.SomethingWrongError;
                result.Status  = Status.Error;
                Logger.ErrorWithException(ex);
            }

            return(result);
        }
예제 #2
0
        public IResponse <NoValue> AddKeyAccount(KeyAccountCreateModel createModel)
        {
            Logger.Message($"Adduser({createModel.Name}");

            var result = new Response <NoValue>();

            try
            {
                var keyAccount = new KeyAccount
                {
                    Name = createModel.Name,
                    Logo = createModel.Logo,
                };

                _uow.KeyAccounts.Add(keyAccount);
                _uow.Complete();
                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("duplicate key"))
                {
                    result.Message = Message.UniqueName;
                }
                else
                {
                    result.Message = Message.SomethingWrongError;
                }

                result.Status = Status.Error;
                Logger.ErrorWithException(ex);
            }

            return(result);
        }
예제 #3
0
        public IResponse <NoValue> AddVoucherTransaction(VoucherTransactionCreateModel model)
        {
            Logger.Message($"AddVoucherTransaction(KeyAccountID: {model.KeyAccountID}, UserVoucherID: {model.UserVoucherID}");

            var result = new Response <NoValue>();

            try
            {
                var userVoucher = _uow.UserVouchers.Get(model.UserVoucherID);

                var voucherTransaction = new VoucherTransaction
                {
                    UserVoucherID = model.UserVoucherID,
                    VoucherID     = userVoucher.VoucherID,
                    UserID        = userVoucher.UserID,
                    OfferID       = userVoucher.OfferID,
                    KeyAccountID  = model.KeyAccountID,
                    Amount        = userVoucher.Voucher.Amount, // unclear purpose, require further clarification
                    TimeStamp     = DateTime.UtcNow
                };

                _uow.VoucherTransactions.Add(voucherTransaction);
                userVoucher.Valid = false;
                _uow.Complete();
                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                result.Message = Message.SomethingWrongError;
                result.Status  = Status.Error;
                Logger.ErrorWithException(ex);
            }

            return(result);
        }
예제 #4
0
        public IResponse <NoValue> AddUser(UserCreateModel createModel, string userId)
        {
            Logger.Message($"Adduser({createModel.Username}, {userId})");

            var result = new Response <NoValue>();

            try
            {
                var user = new User
                {
                    Username     = createModel.Username,
                    FirstName    = createModel.FirstName,
                    LastName     = createModel.LastName,
                    Email        = createModel.Email,
                    City         = createModel.City,
                    Street       = createModel.Street,
                    StreetNumber = createModel.StreetNumber,
                    AdressInfo   = createModel.AdressInfo,
                    Password     = createModel.Password,
                    ZipCode      = createModel.ZipCode,
                    CreatedDate  = DateTime.UtcNow,
                    DateOfBirth  = createModel.DateOfBirth,
                    Gender       = (int)createModel.Gender,
                    PointBalance = 0
                };

                _uow.Users.Add(user);
                _uow.Complete();
                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("duplicate key"))
                {
                    result.Message = Message.UniqueName;
                }
                else
                {
                    result.Message = Message.SomethingWrongError;
                }

                result.Status = Status.Error;
                Logger.ErrorWithException(ex);
            }

            return(result);
        }
예제 #5
0
        public IResponse <NoValue> AddVoucher(VoucherCreateModel createModel)
        {
            Logger.Message($"AddVoucher({createModel.Name}");

            var result = new Response <NoValue>();

            try
            {
                var voucher = new Voucher
                {
                    Name            = createModel.Name,
                    Amount          = createModel.Amount,
                    CalculationType = (int)createModel.CalculationType,
                    Type            = (int)createModel.Type,
                    Code            = createModel.Code,
                    CreatedDate     = DateTime.UtcNow,
                    Description     = createModel.Description,
                    ExpirationDate  = createModel.ExpirationDate,
                    PointCost       = createModel.PointCost,
                    Images          = createModel.Images,
                    KeyAcountID     = createModel.KeyAcountID,
                    OfferID         = createModel.OfferID
                };

                _uow.Vouchers.Add(voucher);
                _uow.Complete();
                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("duplicate key"))
                {
                    result.Message = Message.UniqueName;
                }
                else
                {
                    result.Message = Message.SomethingWrongError;
                }

                result.Status = Status.Error;
                Logger.ErrorWithException(ex);
            }

            return(result);
        }
예제 #6
0
        public IResponse <NoValue> AddUserSegment(UserSegmentCreateModel createModel)
        {
            Logger.Message($"AddUserSegment({createModel.Name})");

            var result = new Response <NoValue>();

            try
            {
                var userSegment = new UserSegment
                {
                    Name            = createModel.Name,
                    ZipCode         = createModel.ZipCode,
                    DateOfBirthFrom = createModel.DateOfBirthFrom,
                    DateOfBirthTo   = createModel.DateOfBirthTo,
                    Gender          = (int)createModel.Gender
                };

                _uow.UserSegments.Add(userSegment);
                _uow.Complete();
                result.Status = Status.Success;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("duplicate key"))
                {
                    result.Message = Message.UniqueName;
                }
                else
                {
                    result.Message = Message.SomethingWrongError;
                }

                result.Status = Status.Error;
                Logger.ErrorWithException(ex);
            }

            return(result);
        }
예제 #7
0
        public async Task AddBudget(BudgetInput input)
        {
            Guard.AssertNotNull(input);

            var budget = new Budget {
                Name                    = input.Name,
                MonthlyBudget           = input.MonthlyBudget,
                WeeklyBudget            = input.WeeklyBudget,
                MonthlySavingAmount     = input.MonthlySavingAmount,
                MonthlySavingPercentage = input.MonthlySavingPercentage,
                Transactions            = GetTransactionsFromInput(input.Transactions),
                CreatedOn               = _clock.Now
            };

            await _budgetRepository.Add(budget);

            await _uow.Complete();
        }