Example #1
0
        public string Delete(int id)
        {
            string message = "";

            try
            {
                int result = _productRepository.Delete(id);
                message = _messageClass.ShowDeleteMessage(result);
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
            }
            return(message);
        }
Example #2
0
        public async Task <string> DeleteAsync(int id)
        {
            var    con              = _baseInterface.GetConnection();
            var    transaction      = con.BeginTransaction();
            var    activeFiscalYear = (await GetAllActiveFiscalYearAsync()).Where(a => a.FiscalYearId != id);
            string message          = "";

            try
            {
                var fiscalYear = await GetFiscalYearByIdAsync(id);

                if (fiscalYear is null)
                {
                    return(null);
                }

                int result = _fiscalYearRepository.Delete(con, transaction, id);
                if (fiscalYear.IsCurrent)
                {
                    if (activeFiscalYear.Count() > 0)
                    {
                        int?fiscalYearId = activeFiscalYear.OrderByDescending(a => a.StartDateAD).FirstOrDefault().FiscalYearId;
                        if (fiscalYearId > 0)
                        {
                            _fiscalYearRepository.MakeIsCurrentTrueById(Convert.ToInt32(fiscalYearId), con, transaction);
                        }
                    }
                }

                message = _messageClass.ShowDeleteMessage(result);
                transaction.Commit();
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
                transaction.Rollback();
            }
            return(message);
        }