public void SaveInterChange(InterChangeFormViewModel viewModel, string action)
        {
            try
            {
                CheckSplitAmountsEntry.CheckInterChange(viewModel.TerminalId, viewModel.Id, viewModel.SplitAmount);

                if (viewModel.StartDate > viewModel.StopDate)
                {
                    throw new Exception("Stop Date must be after Start Date. ");
                }

                var interChange = Table.SingleOrDefault(x => x.BankAccountId == viewModel.BankAccountId);
                if (action == "Edit")
                {
                    var interChangeToEdit = Table.SingleOrDefault(x => x.Id == viewModel.Id && !x.Deleted);
                    if (interChangeToEdit == null)
                    {
                        throw new Exception("InterChange not found. ");
                    }



                    if (interChange != null)
                    {
                        if (interChange.Id != interChangeToEdit.Id && !interChange.Deleted)
                        {
                            throw new Exception("This Terminal already has this InterChange account. ");
                        }
                        if (interChange.Deleted)
                        {
                            Table.Remove(interChange);
                        }
                    }


                    Mapper.Map(viewModel, interChangeToEdit);

                    Edit(interChangeToEdit);
                }
                else
                {
                    if (interChange != null)
                    {
                        if (!interChange.Deleted)
                        {
                            throw new Exception("This Terminal already has this InterChange account. ");
                        }
                        Table.Remove(interChange);
                    }


                    var result = Mapper.Map <InterChangeFormViewModel, InterChange>(viewModel);
                    Add(result);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message + " Could not add InterChange split amount, please check the entered values. ");
            }
        }
Exemple #2
0
        public void SaveSurcharge(SurchargeFormViewModel viewModel, string action)
        {
            try
            {
                CheckSplitAmountsEntry.CheckSurcharge(viewModel.TerminalId, viewModel.Id, viewModel.SplitAmount);

                if (viewModel.StartDate > viewModel.StopDate)
                {
                    throw new Exception("Stop Date must be after Start Date. ");
                }

                var surchargeDefault = Table.SingleOrDefault(x => x.BankAccountId == viewModel.BankAccountId);



                if (action == "Edit")
                {
                    var surcharge = Table.SingleOrDefault(x => x.Id == viewModel.Id && !x.Deleted);
                    if (surcharge == null)
                    {
                        throw new Exception("Surcharge not found. ");
                    }



                    if (surchargeDefault != null)
                    {
                        if (surchargeDefault.Id != surcharge.Id && !surcharge.Deleted)
                        {
                            throw new Exception("This Terminal already has this Surcharge account. ");
                        }
                        if (surcharge.Deleted)
                        {
                            Table.Remove(surchargeDefault);
                        }
                    }


                    Mapper.Map(viewModel, surcharge);

                    Edit(surcharge);
                }
                else
                {
                    if (surchargeDefault != null)
                    {
                        if (!surchargeDefault.Deleted)
                        {
                            throw new Exception("This Terminal already has this Surcharge account. ");
                        }
                        Table.Remove(surchargeDefault);
                    }


                    var result = Mapper.Map <SurchargeFormViewModel, Surcharge>(viewModel);
                    Add(result);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "Please check entered values. ");
            }
        }