public bool UpdateTaxType(TaxTypeVM taxTypeVM)
        {
            using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction())
            {
                try
                {
                    tblTaxType taxType = unitOfWork.TblTaxTypeRepository.GetByID(taxTypeVM.TaxTypeID);
                    taxType.TaxTypeCode  = taxTypeVM.TaxTypeCode;
                    taxType.Description  = taxTypeVM.Description;
                    taxType.Percentage   = taxTypeVM.Percentage;
                    taxType.ExpiryDate   = !string.IsNullOrEmpty(taxTypeVM.ExpiryDate) ? DateTime.ParseExact(taxTypeVM.ExpiryDate, "MM/dd/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null;
                    taxType.IsActive     = taxTypeVM.IsActive;
                    taxType.ModifiedDate = DateTime.Now;
                    taxType.ModifiedBy   = taxTypeVM.ModifiedBy;
                    unitOfWork.TblTaxTypeRepository.Update(taxType);
                    unitOfWork.Save();

                    //Complete the Transaction
                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Roll back the Transaction
                    dbTransaction.Rollback();
                    return(false);
                }
            }
        }
        public TaxTypeVM GetTaxTypeByID(int taxTypeID)
        {
            try
            {
                var taxTypeData = unitOfWork.TblTaxTypeRepository.GetByID(taxTypeID);

                TaxTypeVM taxTypeVM = new TaxTypeVM();
                taxTypeVM.TaxTypeID   = taxTypeData.TaxTypeID;
                taxTypeVM.TaxTypeCode = taxTypeData.TaxTypeCode;
                taxTypeVM.Description = taxTypeData.Description;
                taxTypeVM.Percentage  = taxTypeData.Percentage != null?Convert.ToDouble(taxTypeData.Percentage) : 0;

                taxTypeVM.ExpiryDate = taxTypeData.ExpiryDate != null?taxTypeData.ExpiryDate.ToString() : string.Empty;

                taxTypeVM.IsActive  = taxTypeData.IsActive;
                taxTypeVM.CreatedBy = taxTypeData.CreatedBy != null?Convert.ToInt32(taxTypeData.CreatedBy) : 0;

                taxTypeVM.CreatedDate = taxTypeData.CreatedDate != null?taxTypeData.CreatedDate.ToString() : string.Empty;

                taxTypeVM.ModifiedBy = taxTypeData.ModifiedBy != null?Convert.ToInt32(taxTypeData.ModifiedBy) : 0;

                taxTypeVM.ModifiedDate = taxTypeData.ModifiedDate != null?taxTypeData.ModifiedDate.ToString() : string.Empty;

                return(taxTypeVM);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public IHttpActionResult UpdateTaxType([FromBody] JObject data)
        {
            try
            {
                int    taxTypeID   = !string.IsNullOrEmpty(data.SelectToken("TaxTypeID").Value <string>()) ? Convert.ToInt32(data.SelectToken("TaxTypeID").Value <string>()) : 0;
                string taxTypeCode = !string.IsNullOrEmpty(data.SelectToken("TaxTypeCode").Value <string>()) ? data.SelectToken("TaxTypeCode").Value <string>() : string.Empty;
                string description = !string.IsNullOrEmpty(data.SelectToken("Description").Value <string>()) ? data.SelectToken("Description").Value <string>() : string.Empty;
                double percentage  = !string.IsNullOrEmpty(data.SelectToken("Percentage").Value <string>()) ? Convert.ToDouble(data.SelectToken("Percentage").Value <string>()) : 0;
                string expiryDate  = !string.IsNullOrEmpty(data.SelectToken("ExpiryDate").Value <string>()) ? data.SelectToken("ExpiryDate").Value <string>() : string.Empty;
                bool   isActive    = !string.IsNullOrEmpty(data.SelectToken("IsActive").Value <string>()) ? Convert.ToBoolean(data.SelectToken("IsActive").Value <string>()) : false;
                int    userID      = !string.IsNullOrEmpty(data.SelectToken("UserID").Value <string>()) ? Convert.ToInt32(data.SelectToken("UserID").Value <string>()) : 0;

                if (!manageTax.IsTaxTypeAvailable(taxTypeID, taxTypeCode))
                {
                    TaxTypeVM taxTypeVM = new TaxTypeVM();
                    taxTypeVM.TaxTypeID   = taxTypeID;
                    taxTypeVM.TaxTypeCode = taxTypeCode;
                    taxTypeVM.Description = description;
                    taxTypeVM.Percentage  = percentage;
                    taxTypeVM.ExpiryDate  = expiryDate;
                    taxTypeVM.IsActive    = isActive;
                    taxTypeVM.ModifiedBy  = userID;

                    bool status = manageTax.UpdateTaxType(taxTypeVM);

                    if (status)
                    {
                        return(Json(new { status = true, message = "Successfully Updated" }));
                    }
                    else
                    {
                        return(Json(new { status = false, message = "Update Failed" }));
                    }
                }
                else
                {
                    return(Json(new { status = false, message = "Tax Type already exists" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { status = false, message = "Unknown error occurred" }));
            }
        }
        public List <TaxTypeVM> GetAllTaxTypes()
        {
            try
            {
                var taxTypeData = unitOfWork.TblTaxTypeRepository.Get().ToList();

                List <TaxTypeVM> taxTypeList = new List <TaxTypeVM>();

                foreach (var taxType in taxTypeData)
                {
                    TaxTypeVM taxTypeVM = new TaxTypeVM();
                    taxTypeVM.TaxTypeID   = taxType.TaxTypeID;
                    taxTypeVM.TaxTypeCode = taxType.TaxTypeCode;
                    taxTypeVM.Description = taxType.Description;
                    taxTypeVM.Percentage  = taxType.Percentage != null?Convert.ToDouble(taxType.Percentage) : 0;

                    taxTypeVM.ExpiryDate = taxType.ExpiryDate != null?taxType.ExpiryDate.ToString() : string.Empty;

                    taxTypeVM.IsActive  = taxType.IsActive;
                    taxTypeVM.CreatedBy = taxType.CreatedBy != null?Convert.ToInt32(taxType.CreatedBy) : 0;

                    taxTypeVM.CreatedDate = taxType.CreatedDate != null?taxType.CreatedDate.ToString() : string.Empty;

                    taxTypeVM.ModifiedBy = taxType.ModifiedBy != null?Convert.ToInt32(taxType.ModifiedBy) : 0;

                    taxTypeVM.ModifiedDate = taxType.ModifiedDate != null?taxType.ModifiedDate.ToString() : string.Empty;

                    taxTypeList.Add(taxTypeVM);
                }

                return(taxTypeList);
            }
            catch (Exception ex)
            {
                throw;
            }
        }