Beispiel #1
0
        protected void saveLinkButton_Click(object sender, EventArgs e)
        {
            // Add new record
            var oklada = new Core.UIModel.Oklada
            {
                ListicId = ListicId,
                PonudaId = long.Parse(ponudaDropDownList.SelectedValue)
            };

            var ponuda = _ponudaRepository.GetPonuda(oklada.PonudaId);

            oklada.Koeficient = ponuda.Koeficient;

            try
            {
                var oklade         = _okladaRepository.GetOkladas(ListicId);
                var okladePlusNova = oklade.Concat(new Core.UIModel.Oklada[] { oklada }).ToArray();
                var listic         = _listicRepository.GetListic(ListicId);
                var moguciDobitak  = _listicRepository.CalculateMoguciDobitak(ListicId, listic.IznosUplate, okladePlusNova);
                _listicRepository.ValidateMoguciDobitak(ListicId, moguciDobitak, okladePlusNova);

                _okladaRepository.Add(oklada);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed to add oklada to listić. Error: {ex.Message}");
                MessageManager.ShowMessage(this, ex.Message);
            }

            try
            {
                _okladaRepository.Save();
                _listicRepository.UpdateMoguciDobitak(ListicId);
                editPanel.Visible = false;
                Search();
            }
            catch
            {
                MessageManager.ShowMessage(this, "Ta oklada je već dodana na ovaj listić!");
            }
        }
        protected void saveLinkButton_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
            }

            if (IsEditMode)
            {
                var listic = new Core.UIModel.Listic
                {
                    ListicId      = long.Parse(vrijemeUplateTextBox.ToolTip),
                    VrijemeUplate = DateTime.Parse(vrijemeUplateTextBox.Text),
                    IznosUplate   = double.Parse(iznosUplateTextBox.Text),
                    UpdateDate    = DateTime.Parse(iznosUplateTextBox.ToolTip)
                };

                try
                {
                    var okladaRepository = OkladaRepositoryFactory.Create();
                    var oklade           = okladaRepository.GetOkladas(listic.ListicId);
                    var moguciDobitak    = _listicRepository.CalculateMoguciDobitak(listic.ListicId, listic.IznosUplate, oklade);
                    _listicRepository.ValidateMoguciDobitak(listic.ListicId, moguciDobitak, oklade);

                    _listicRepository.Update(listic);
                    _listicRepository.UpdateMoguciDobitak(listic.ListicId);
                    _logger.Info("Succesfully updated listić and mogući dobitak.");
                }
                catch (Exception ex)
                {
                    _logger.Error($"Failed to update listić and/or mogući dobitak. Error: {ex.Message}");
                    MessageManager.ShowMessage(this, ex.Message);
                }
            }
            else
            {
                // Add new record
                var listic = new Core.UIModel.Listic
                {
                    VrijemeUplate = DateTime.Parse(vrijemeUplateTextBox.Text),
                    IznosUplate   = double.Parse(iznosUplateTextBox.Text)
                };

                try
                {
                    _listicRepository.Add(listic);
                    _listicRepository.Save();
                    _logger.Info($"Successfully added new listić to database. Listić: {listic}");
                }
                catch (Exception ex)
                {
                    _logger.Error($"Failed to add new listic to database: Error: {ex.Message}");
                }
            }

            ClearTextBoxes();
            ClearSearchBoxes();
            editPanel.Visible = false;

            Search();
        }