Example #1
0
        /// <summary>
        /// Get InvoiceDetail by id
        /// </summary>
        /// <param name="id">ID of InvoiceDetail</param>
        /// <returns></returns>
        public ApiResponseViewModel GetById(int id)
        {
            var result   = new InvoiceDetailViewModel();
            var response = new ApiResponseViewModel
            {
                Code    = CommonConstants.ApiResponseSuccessCode,
                Message = null,
                Result  = null
            };

            try
            {
                var exists = _InvoiceDetailRepository.CheckContains(m => m.ID == id);
                if (exists)
                {
                    var tempResult = _InvoiceDetailRepository.GetSingleById(id);
                    result.ID           = tempResult.ID;
                    result.InvoiceID    = tempResult.InvoiceID;
                    result.Value        = decimal.Parse(tempResult.Value.ToString()).ToString("###,##");
                    result.IsActive     = tempResult.IsActive ?? false;
                    result.DepartmentID = tempResult.DepartmentID;
                    result.Department   = tempResult.Department.DepartmentName;
                    result.CategoryID   = tempResult.CategoryID;
                    result.Category     = tempResult.Category.CategoryName;
                    result.TaxValueID   = tempResult.TaxValueID;
                    result.TaxValue     = tempResult.TaxValue.Value.ToString();
                    response.Result     = result;
                }
                else
                {
                    response.Code    = CommonConstants.ApiResponseNotFoundCode;
                    response.Message = CommonConstants.NotFoundMessage;
                }
            }
            catch (Exception ex)
            {
                response.Code    = CommonConstants.ApiResponseExceptionCode;
                response.Message = CommonConstants.ErrorMessage + " " + ex.Message;
            }

            return(response);
        }