protected void BtnSave_Click(object sender, EventArgs e)
 {
     using (var expenseService = new ExpenseService())
     {
         CurrentExpense = new Expense();
         int expenseId;
         int.TryParse(Request.QueryString["ExpenseId"], out expenseId);
         CurrentExpense.ExpenseId     = expenseId;
         CurrentExpense.Name          = txtName.Value;
         CurrentExpense.Price         = decimal.Parse(txtPrice.Value);
         CurrentExpense.RelateToMonth = DateTime.ParseExact(slcRelatedMonth.Value, "d-M-yyyy", CultureInfo.CurrentCulture);
         CurrentExpense.Description   = txtDescription.Value;
         CurrentExpense.ItemId        = int.Parse(slcItemId.Value);
         CurrentExpense.Payed         = chkPayed.Checked;
         CurrentExpense.ClientId      = int.Parse(Request.Cookies["ClientId"].Value);
         if (CurrentExpense.ExpenseId != 0)
         {
             expenseService.UpdateExpense(CurrentExpense);
         }
         else
         {
             expenseService.AddExpense(CurrentExpense);
         }
     }
     Response.RedirectPermanent(Request, "AllExpenses.aspx");
 }
        protected async Task HandleValidSubmit()
        {
            Expense.EmployeeId = int.Parse(EmployeeId);
            Expense.CurrencyId = int.Parse(CurrencyId);



            Expense.Amount *= Currencies.FirstOrDefault(x => x.CurrencyId == Expense.CurrencyId).USExchange;

            // We can handle certain requests automatically
            Expense.Status = await ExpenseApprovalService.GetExpenseStatus(Expense);

            if (Expense.ExpenseId == 0) // New
            {
                await ExpenseService.AddExpense(Expense);

                NavigationManager.NavigateTo("/expenses");
            }
            else
            {
                await ExpenseService.UpdateExpense(Expense);

                NavigationManager.NavigateTo("/expenses");
            }
        }
        public async Task ExpenseAdd_TryingAddNewObjectToDB_ShouldBeAbleReturnIdEquals8()
        {
            // Arrange
            mockMapper.Setup(x => x.Map <List <Entities.Expense> >(It.IsAny <List <Models.Expense> >()))
            .Returns(It.IsAny <List <Entities.Expense> >());
            mockRepo.Setup(y => y.AddRangeAsync(It.IsAny <IEnumerable <Entities.Expense> >()))
            .Returns(() => Task.Run(() => { return(true); })).Verifiable();
            mockRepo.Setup(y => y.SaveAsync())
            .Returns(() => Task.Run(() => { return(true); })).Verifiable();
            expenseEntityLists = new List <Entities.Expense>
            {
                new Entities.Expense {
                    Id = 8, Comment = "New category Expense was added"
                }
            };
            var sut = new ExpenseService(mockRepo.Object, mockMapper.Object, mockLogger.Object);

            // Act
            var resultOfAddExpense = await sut.AddExpense(expenseModelObj);

            await context.Expenses.AddRangeAsync(expenseEntityLists);

            await context.SaveChangesAsync();

            var isAddedNewObject = queryDBInMemory.GetAsync(8);

            // Assert
            Assert.AreEqual(8, isAddedNewObject.Result.Id, "New object was not added, require id=8");
            Assert.IsTrue(resultOfAddExpense, "Add and Save should return true. Object i added to Database");
            mockRepo.Verify(
                x => x.AddRangeAsync(It.IsAny <IEnumerable <Entities.Expense> >()),
                Times.Once, "AddRangeAsync should run once");
            mockRepo.Verify(
                x => x.SaveAsync(), Times.Once, "SaveAsync should run once");
        }
Пример #4
0
        protected async Task HandleValidSubmit()
        {
            Expense.EmployeeId = int.Parse(EmployeeId);
            Expense.CurrencyId = int.Parse(CurrencyId);


            Expense.Amount *= Currencies.FirstOrDefault(x => x.CurrencyId == Expense.CurrencyId).USExchange;

            Expense.Status = await ExpenseApprovalService.GetExpenseStatus(Expense);

            if (Expense.ExpenseType == ExpenseType.Food && Expense.Amount > 100)
            {
                Expense.Status = ExpenseStatus.Pending;
            }

            if (Expense.Amount > 5000)
            {
                Expense.Status = ExpenseStatus.Pending;
            }

            if (Expense.ExpenseId == 0) // New
            {
                await ExpenseService.AddExpense(Expense);

                NavigationManager.NavigateTo("/expenses");
            }
            else
            {
                await ExpenseService.UpdateExpense(Expense);

                NavigationManager.NavigateTo("/expenses");
            }
        }
Пример #5
0
        public IActionResult AddExpenseDetails(Expense expense)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            expenseService.AddExpense(expense);
            return(NoContent());
        }
Пример #6
0
        /// <summary>
        /// Sends the entered expense to the mobile service when the sibmit button is pressed
        /// </summary>
        private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            // Disable Submit to prevent multiple entries
            SubmitButton.IsEnabled = false;

            if (CategoryBox.SelectedIndex < 0)
            {
                await new MessageDialog("Category must be specified").ShowAsync();
            }
            else if (String.IsNullOrWhiteSpace(PriceBox.Text))
            {
                await new MessageDialog("Price must be specified").ShowAsync();
            }
            else
            {
                // Set the selected priority to the default for the category if not selected
                if (PriorityBox.SelectedIndex < 0)
                {
                    PriorityBox.SelectedIndex = (CategoryBox.SelectedItem as Category).DefaultPriority - 1;
                }
                // Create the expense data to save
                Expense ExpenseData = new Expense(CategoryBox.SelectedValue.ToString(), Decimal.Parse(PriceBox.Text), DateBox.Date, new DateTime(TimeBox.Time.Ticks), (byte?)(PriorityBox.SelectedIndex + 1), MoreInfoBox.Text);

                // Display the progress wheel when getting data
                ProgressRing LoginProgress = new ProgressRing();
                LoginProgress.HorizontalAlignment = HorizontalAlignment.Center;
                LoginProgress.VerticalAlignment   = VerticalAlignment.Center;
                ContentRoot.Children.Add(LoginProgress);
                LoginProgress.IsActive = true;

                // Send the data to the mobile service
                if (await ExpenseService.AddExpense(ExpenseData))
                {
                    // Clear input data
                    CategoryBox.SelectedIndex = -1;
                    PriceBox.Text             = "";
                    DateBox.Date = DateTime.Now;
                    TimeBox.Time = DateTime.Now.TimeOfDay;
                    PriorityBox.SelectedIndex   = -1;
                    PriorityBox.PlaceholderText = "Priority";
                    MoreInfoBox.Text            = "";

                    // Refresh the chart with the new data
                    await RefreshExpenseChart();
                }

                // Disable the progress wheel
                LoginProgress.IsActive = false;
                ContentRoot.Children.Remove(LoginProgress);
            }
            // Reenable when finished
            SubmitButton.IsEnabled = true;
        }
Пример #7
0
        public ActionResult AddEdit(ExpenseModel model)
        {
            bool status = ExpenseService.AddExpense(model);

            if (status)
            {
                TempData["Success"] = "Expense Added Successfully.";
            }
            else
            {
                TempData["Error"] = "Error, Please Try Again.";
            }

            return(RedirectToAction("Index"));
        }
 public IActionResult Create(ExpenseReport newExpense)
 {
     if (ModelState.IsValid)
     {
         if (newExpense.ItemId > 0)
         {
             _ES.UpdateExpense(newExpense);
         }
         else
         {
             _ES.AddExpense(newExpense);
         }
     }
     return(RedirectToAction("Index"));
 }
        public async Task AddExpense_ShouldRunAddRangeAsyncOnlyOnce()
        {
            // Arrange
            mockMapper.Setup(x => x.Map <List <Entities.Expense> >(It.IsAny <List <Models.Expense> >()))
            .Returns(It.IsAny <List <Entities.Expense> >());
            mockRepo.Setup(y => y.AddRangeAsync(It.IsAny <IEnumerable <Entities.Expense> >()))
            .Returns(() => Task.Run(() => { })).Verifiable();

            var sut = new ExpenseService(mockRepo.Object, mockMapper.Object, mockLogger.Object);

            // Act
            await sut.AddExpense(expenseModelObj);

            // Assert
            mockRepo.Verify(
                x => x.AddRangeAsync(It.IsAny <IEnumerable <Entities.Expense> >()),
                Times.Once, "AddRangeAsync should run once");
        }
Пример #10
0
        public void AddExpense_Success_Test()
        {
            // Arrange
            ExpenseDTO dto = SampleExpenseDTO(1);

            // create mock for repository
            var mock = new Mock <IExpenseRepository>();

            mock.Setup(s => s.AddExpense(Moq.It.IsAny <R_Expense>())).Returns(1);

            // service
            ExpenseService expenseService = new ExpenseService();

            ExpenseService.Repository = mock.Object;

            // Act
            int id = expenseService.AddExpense(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.ExpenseId);
        }
        public async Task AddExpense_ShouldNotBeAbleToAddExpense()
        {
            // Arrange
            mockMapper.Setup(x => x.Map <List <Entities.Expense> >(It.IsAny <List <Models.Expense> >()))
            .Returns(It.IsAny <List <Entities.Expense> >());
            mockRepo.Setup(y => y.AddRangeAsync(It.IsAny <IEnumerable <Entities.Expense> >()))
            .Returns(() => Task.Run(() => { return(true); })).Verifiable();
            mockRepo.Setup(y => y.SaveAsync())
            .Returns(() => Task.Run(() => { return(false); })).Verifiable();

            var sut = new ExpenseService(mockRepo.Object, mockMapper.Object, mockLogger.Object);

            // Act
            var resultOfAddExpense = await sut.AddExpense(expenseModelObj);

            // Assert
            Assert.IsFalse(resultOfAddExpense, "Save should return false");
            mockRepo.Verify(
                x => x.AddRangeAsync(It.IsAny <IEnumerable <Entities.Expense> >()), Times.Once, "AddRangeAsync should run once");
            mockRepo.Verify(
                x => x.SaveAsync(), Times.Once, "SaveAsync should run once");
        }
Пример #12
0
        protected async Task HandleValidSubmit()
        {
            Expense.EmployeeId = int.Parse(EmployeeId);
            Expense.CurrencyId = int.Parse(CurrencyId);

            var employee = await EmployeeDataService.GetEmployeeDetails(Expense.EmployeeId);

            Expense.Amount *= Currencies.FirstOrDefault(x => x.CurrencyId == Expense.CurrencyId).USExchange;

            // We can handle certain requests automatically
            if (employee.IsOPEX)
            {
                switch (Expense.ExpenseType)
                {
                case ExpenseType.Conference:
                    Expense.Status = ExpenseStatus.Denied;
                    break;

                case ExpenseType.Transportation:
                    Expense.Status = ExpenseStatus.Denied;
                    break;

                case ExpenseType.Hotel:
                    Expense.Status = ExpenseStatus.Denied;
                    break;
                }

                if (Expense.Status != ExpenseStatus.Denied)
                {
                    Expense.CoveredAmount = Expense.Amount / 2;
                }
            }

            if (!employee.IsFTE)
            {
                if (Expense.ExpenseType != ExpenseType.Training)
                {
                    Expense.Status = ExpenseStatus.Denied;
                }
            }

            if (Expense.ExpenseType == ExpenseType.Food && Expense.Amount > 100)
            {
                Expense.Status = ExpenseStatus.Pending;
            }

            if (Expense.Amount > 5000)
            {
                Expense.Status = ExpenseStatus.Pending;
            }

            if (Expense.ExpenseId == 0) // New
            {
                await ExpenseService.AddExpense(Expense);

                NavigationManager.NavigateTo("/expensesoverview");
            }
            else
            {
                await ExpenseService.UpdateExpense(Expense);

                NavigationManager.NavigateTo("/expensesoverview");
            }
        }