/// <summary> /// Function to Updating budget data. /// Added By: Rahul Shah on 12/07/2016. /// </summary> /// <param name="BudgetId">Budget Id.</param> /// <param name="BudgetDetailId">Budget Detail Id.</param> /// <param name="ParentId">Parent Budget Detail Id.</param> /// <param name="nValue">new Value.</param> /// <param name="ChildItemIds">Child Budget Detail Ids.</param> /// <param name="ColumnName">Column Name.</param> /// <param name="AllocationType">Allocation Type.</param> /// <param name="Period">Perido (i.e Jan,Feb..etc).</param> /// <summary> /// Function to Updating budget data. /// Added By: Rahul Shah on 12/07/2016. /// </summary> /// <param name="BudgetId">Budget Id.</param> /// <param name="BudgetDetailId">Budget Detail Id.</param> /// <param name="ParentId">Parent Budget Detail Id.</param> /// <param name="nValue">new Value.</param> /// <param name="ChildItemIds">Child Budget Detail Ids.</param> /// <param name="ColumnName">Column Name.</param> /// <param name="AllocationType">Allocation Type.</param> /// <param name="Period">Perido (i.e Jan,Feb..etc).</param> public JsonResult UpdateMarketingBudget(int BudgetId, int BudgetDetailId, int ParentId, string nValue, string ChildItemIds, string ColumnName, string AllocationType, string Period) { //Check budget Id and budget detaild id is valid or not. if (BudgetId <= 0 || BudgetDetailId <= 0) { return(Json(new { IsSuccess = false, ErrorMessage = Common.objCached.InvalidBudgetId }, JsonRequestBehavior.AllowGet)); } else { try { List <string> ListItems = new List <string>(); List <RevenuePlanner.Models.Budget_Columns> objColumns = _MarketingBudget.GetBudgetColumn(Sessions.User.CID); // get budget column of the client. bool isForecast = false; //Check Child budget items are exist or not if (!string.IsNullOrEmpty(ChildItemIds)) { ListItems = ChildItemIds.Split(',').ToList(); } ListItems.Add(Convert.ToString(BudgetDetailId)); if (string.Compare(ColumnName, Enums.DefaultGridColumn.Owner.ToString(), true) == 0) { int OwnerId = 0; int.TryParse(nValue, out OwnerId); if (OwnerId <= 0) { return(Json(new { IsSuccess = false, ErrorMsg = "Owner is not valid" }, JsonRequestBehavior.AllowGet)); } _MarketingBudget.UpdateOwnerName(BudgetDetailId, ListItems, OwnerId, Sessions.User.CID); } else if (string.Compare(ColumnName, Enums.DefaultGridColumn.Name.ToString(), true) == 0) { _MarketingBudget.UpdateTaskName(BudgetId, BudgetDetailId, ParentId, Sessions.User.CID, nValue); } else if (string.Compare(ColumnName, Enums.DefaultGridColumn.Budget.ToString(), true) == 0 || string.Compare(ColumnName, Enums.DefaultGridColumn.Forecast.ToString(), true) == 0 || string.Compare(ColumnName, Enums.DefaultGridColumn.Total_Budget.ToString(), true) == 0 || string.Compare(ColumnName, Enums.DefaultGridColumn.Total_Forecast.ToString(), true) == 0) { _MarketingBudget.UpdateTotalAmount(BudgetDetailId, nValue, ColumnName, Sessions.User.CID, Sessions.PlanExchangeRate); } else if (string.Compare(ColumnName.Split('_')[0], "cust", true) == 0) { if (objColumns != null && objColumns.Count > 0) { //here we get customfield column name Like 'cust_' + 'customfieldId' so we need to split and convert 'cusmfieldid' from string to int. int CustomfieldId = 0; if (ColumnName.Split('_').Length > 1) { int.TryParse(ColumnName.Split('_')[1].ToString(), out CustomfieldId); } RevenuePlanner.Models.Budget_Columns objCustomColumns = objColumns.Where(a => a.IsTimeFrame == false && a.CustomField.CustomFieldId == CustomfieldId).Select(a => a).FirstOrDefault(); if (objCustomColumns != null) { _MarketingBudget.SaveCustomColumnValues(CustomfieldId, objCustomColumns, BudgetDetailId, nValue, Sessions.User.ID, Sessions.User.CID, Sessions.PlanExchangeRate);//Call SaveBudgetorForecast method to save customfield cell value. } } } else { if (objColumns != null && objColumns.Count > 0) { //Get Name of the budget column string BudgetColName = objColumns.Where(a => a.ValueOnEditable == (int)Enums.ValueOnEditable.Budget && a.IsDeleted == false && a.IsTimeFrame == true && a.MapTableName == Enums.MapTableName.Budget_DetailAmount.ToString()).Select(a => a.CustomField.Name).FirstOrDefault(); //Get Name of the Forecast column string ForecastColName = objColumns.Where(a => a.ValueOnEditable == (int)Enums.ValueOnEditable.Forecast && a.IsDeleted == false && a.IsTimeFrame == true && a.MapTableName == Enums.MapTableName.Budget_DetailAmount.ToString()).Select(a => a.CustomField.Name).FirstOrDefault(); //here monthly/quarterly column name with Y1/Q1 prefix so we need to split and check column is forecast or budget then perform the updation logic. if (!string.IsNullOrEmpty(ColumnName)) { if (ColumnName.Split('_').Length > 0) { ColumnName = ColumnName.Split('_')[1]; } if (ColumnName == BudgetColName) { isForecast = false; } else { isForecast = true; } //Call SaveBudgetorForecast method to save budget or forecast cell value. _MarketingBudget.SaveBudgetorForecast(BudgetDetailId, nValue, Sessions.User.CID, isForecast, AllocationType, Period, Sessions.PlanExchangeRate); } } } return(Json(new { IsSuccess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { IsSuccess = false, ErrorMessage = Common.objCached.InvalidBudgetId }, JsonRequestBehavior.AllowGet)); } } }
public void Test_MarketingBudget_GetBudgetColumn() { var res = _marketingBudget.GetBudgetColumn(ClientId); Assert.IsTrue(res.Count > 0); }