/// <summary>
        /// Updates the Depreciation previously set for selected Purchased Asset ID on particular date
        /// </summary>
        /// <param name="sdfvm"></param>
        /// <returns>Rollback Flag 1 or 0</returns>
        public int UpdateSetDepreciationForIndividual(SetDepreciationFirstViewModel sdfvm)
        {
            var rollbackFlag = 0;

            using (SqlConnection con = new SqlConnection(TableConstant.CONNECTION_STRING))
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_UpdateSetDepreciationForIndividual"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = con;

                    cmd.Parameters.AddWithValue("@AssetPurchaseId", sdfvm.AssetPurchaseId);
                    cmd.Parameters.AddWithValue("@DepreciationType", sdfvm.DepreciationType);
                    cmd.Parameters.AddWithValue("@CurrentYear", sdfvm.CurrentYear);
                    cmd.Parameters.AddWithValue("@DepreciationRate", sdfvm.DepreciationRate);
                    cmd.Parameters.AddWithValue("@RateStatus", sdfvm.RateStatus);

                    var returnParameter = cmd.Parameters.Add("@RollBackFlag", SqlDbType.Int);
                    returnParameter.Direction = ParameterDirection.ReturnValue;

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    rollbackFlag = (int)returnParameter.Value;
                }
            }

            return(rollbackFlag);
        }
        public ActionResult SetDepreciationRate(long id, FormCollection fc) //id => AssetPurchaseId
        {
            //Check if Depreciation Rate exists for Purchase ID (edit purpose)
            var     depnRateObj      = _repDepreciation.GetDepreciationRate(id);
            decimal existingDepnRate = (depnRateObj != null) ? depnRateObj.Rate : 0;
            string  existingDepnType = (depnRateObj != null) ? depnRateObj.DepreciationType : "";

            var purchaseNo = _repPurchaseAsset.GetAssetPurchaseDetails()
                             .Where(x => x.Id == id)
                             .SingleOrDefault().PurchaseNo;

            ViewBag.Title = String.Concat(Constant.SET_DEPRECIATION_RATE, " for ", purchaseNo);

            var sdfvm = new SetDepreciationFirstViewModel()
            {
                DepreciationRate      = Decimal.Parse(fc["formValue[DepreciationRate]"]),
                AssetPurchaseId       = id,
                DepreciationType      = fc["formValue[DepreciationType]"],
                CurrentYear           = DateTime.Now.Year.ToString(),
                RateStatus            = 1,
                DepreciationEntryDate = DateTime.Now
            };

            int isDepreciated = 0;

            if (depnRateObj == null)
            {
                //Creates/Sets Depreciation rate for individual purchase Id
                isDepreciated = _repDepreciation.SetDepreciationForIndividual(sdfvm);
            }
            else
            {
                //Updates/Sets Depreciation rate for individual purchase Id
                isDepreciated = _repDepreciation.UpdateSetDepreciationForIndividual(sdfvm);
            }

            var json = JsonConvert.SerializeObject(sdfvm);

            return(Json(json));
        }