public void Update(UIModel.Listic listic)
        {
            var record = Find(listic.ListicId);

            if (listic.UpdateDate.ToString() != record.UpdateDate.ToString())
            {
                throw new Exception("Netko je u međuvremenu već napravio promjene na tom zapisu!");
            }

            if (record != null)
            {
                record.VrijemeUplate = listic.VrijemeUplate;
                record.IznosUplate   = listic.IznosUplate;
                record.MoguciDobitak = listic.MoguciDobitak;
                record.UpdateDate    = DateTime.Now;
            }
        }
        public void Add(UIModel.Listic listic)
        {
            var record = ListicFactory.CreateRecord(listic);

            _dataContext.Listics.Add(record);
        }
Example #3
0
        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();
        }