public void Save_Deploye_Improvement_TacticType() { var routes = new RouteCollection(); Console.WriteLine("Save Deployed Status for Improvement Tactic Type.\n"); MRPEntities db = new MRPEntities(); HttpContext.Current = DataHelper.SetUserAndPermission(); BoostController objBoostController = new BoostController(); objBoostController.ControllerContext = new ControllerContext(MockHelpers.FakeUrlHelper.FakeHttpContext(), new RouteData(), objBoostController); objBoostController.Url = MockHelpers.FakeUrlHelper.UrlHelper(); int ModelId = DataHelper.GetModelId(); Sessions.User.CID = DataHelper.GetClientId(0, ModelId); ImprovementTacticType ImprovementTacticTypeData = DataHelper.GetImprovementTacticType(Sessions.User.CID); if (ImprovementTacticTypeData != null) { Sessions.User.ID = ImprovementTacticTypeData.CreatedBy; int improvementId = ImprovementTacticTypeData.ImprovementTacticTypeId; bool deploye = ImprovementTacticTypeData.IsDeployed; int UserId = ImprovementTacticTypeData.CreatedBy; var result = objBoostController.SaveDeployedToIntegrationStatus(improvementId, deploye, UserId) as JsonResult; var serializedData = new RouteValueDictionary(result.Data); var resultvalue = serializedData["message"]; Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name + "\n The Assert Value result.data: " + result.Data); Assert.IsNotNull(result.Data); Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name + "\n The Assert Value resultvalue : " + resultvalue.ToString()); Assert.IsNotNull(resultvalue.ToString()); } }
public void Save_Improvement_TacticType_Old() { var routes = new RouteCollection(); Console.WriteLine("Save Improvement Tactic Type Details for Existing Tactic Type.\n"); MRPEntities db = new MRPEntities(); HttpContext.Current = DataHelper.SetUserAndPermission(); BoostController objBoostController = new BoostController(); objBoostController.ControllerContext = new ControllerContext(MockHelpers.FakeUrlHelper.FakeHttpContext(), new RouteData(), objBoostController); objBoostController.Url = MockHelpers.FakeUrlHelper.UrlHelper(); int ModelId = DataHelper.GetModelId(); Sessions.User.CID = DataHelper.GetClientId(0, ModelId); ImprovementTacticType ImprovementTacticTypeData = DataHelper.GetImprovementTacticType(Sessions.User.CID); if (ImprovementTacticTypeData != null) { int improvementId = ImprovementTacticTypeData.ImprovementTacticTypeId; string improvementDetails = "[{\"StageId\":\"106\",\"StageType\":\"SV\",\"Value\":\"5\"}]"; bool status = ImprovementTacticTypeData.IsDeleted; double cost = ImprovementTacticTypeData.Cost; string desc = ImprovementTacticTypeData.Description; string title = ImprovementTacticTypeData.Title; bool deployToIntegrationStatus = ImprovementTacticTypeData.IsDeployedToIntegration; int UserId = ImprovementTacticTypeData.CreatedBy; var result = objBoostController.saveImprovementTacticData(improvementId, improvementDetails, status, cost, desc, title, deployToIntegrationStatus, UserId) as JsonResult; Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name + "\n The Assert Value result.Data: " + result.Data); Assert.IsNotNull(result.Data); } }
[AuthorizeUser(Enums.ApplicationActivity.BoostImprovementTacticCreateEdit)] // Added by Sohel Pathan on 19/06/2014 for PL ticket #537 to implement user permission Logic public JsonResult deleteImprovementTactic(int improvementId) { // Added by Sohel Pathan on 25/06/2014 for PL ticket #537 to implement user permission Logic ViewBag.IsBoostBestInClassNumberEditAuthorized = AuthorizeUserAttribute.IsAuthorized(Enums.ApplicationActivity.BoostBestInClassNumberEdit); ViewBag.IsBoostImprovementTacticCreateEditAuthorized = AuthorizeUserAttribute.IsAuthorized(Enums.ApplicationActivity.BoostImprovementTacticCreateEdit); string successMessage = string.Empty; string ErrorMessage = string.Empty; try { if (improvementId != 0) { using (var scope = new TransactionScope()) { var isDependent = db.Plan_Improvement_Campaign_Program_Tactic.Where(_tac => _tac.IsDeleted.Equals(false) && _tac.ImprovementTacticTypeId == improvementId).Count(); //// if Improvement Tactic does not dependent to other field then delete it. if (isDependent <= 0) { ImprovementTacticType objIt = GetImprovementTacticTypeRecordbyId(improvementId); if (objIt != null) { objIt.IsDeleted = true; objIt.ModifiedBy = Sessions.User.ID; objIt.ModifiedDate = DateTime.Now; db.Entry(objIt).State = EntityState.Modified; db.SaveChanges(); successMessage = string.Format(Common.objCached.DeleteImprovementTacticSaveSucess, objIt.Title.ToString()); TempData["SuccessMessage"] = successMessage; } scope.Complete(); return(Json(new { status = 0, succMsg = successMessage, redirect = Url.Action("Index") }, JsonRequestBehavior.AllowGet)); } else { TempData["SuccessMessage"] = string.Empty; return(Json(new { status = 1, errormsg = Common.objCached.ImprovementTacticReferencesPlanError.ToString() }, JsonRequestBehavior.AllowGet)); } } } else { TempData["SuccessMessage"] = string.Empty; return(Json(new { status = 1, errormsg = Common.objCached.NoRecordFound }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); TempData["SuccessMessage"] = string.Empty; return(Json(new { status = 1, errormsg = e.InnerException.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Added By: Viral Kadiya. /// Get Stage list by ClientId. /// </summary> /// <param name="clientId"></param> public ImprovementTacticType GetImprovementTacticTypeRecordbyId(int improvementTacticTypeId) { ImprovementTacticType objImprvmentTacticType; try { objImprvmentTacticType = db.ImprovementTacticTypes.Where(_imprvTacticType => _imprvTacticType.IsDeleted == false && _imprvTacticType.ImprovementTacticTypeId == improvementTacticTypeId).FirstOrDefault(); if (objImprvmentTacticType == null) { objImprvmentTacticType = new ImprovementTacticType(); } } catch (Exception ex) { throw ex; } return(objImprvmentTacticType); }
[AuthorizeUser(Enums.ApplicationActivity.BoostImprovementTacticCreateEdit)] // Added by Sohel Pathan on 19/06/2014 for PL ticket #537 to implement user permission Logic public ActionResult saveImprovementTacticData(int improvementId, string improvementDetails, bool status, double cost, string desc, string title, bool deployToIntegrationStatus, int UserId = 0) { string successMessage = string.Empty; string ErrorMessage = string.Empty; string[] value = improvementDetails.Split(','); PlanExchangeRate = Sessions.PlanExchangeRate; try { /* if id !=0 then its update into db other wise add new record in db*/ if (improvementId != 0) { ImprovementTacticType objIt = GetImprovementTacticTypeRecordbyId(improvementId); //// Modified by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. var existTactic = db.ImprovementTacticTypes.Where(_imprvTac => _imprvTac.ClientId == Sessions.User.CID && _imprvTac.Title.ToLower() == title.ToLower() && _imprvTac.ImprovementTacticTypeId != improvementId && _imprvTac.IsDeleted.Equals(false)).ToList(); //// Modified by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. if (existTactic.Count == 0) { /*edit new improvementTactic record*/ objIt.ImprovementTacticTypeId = improvementId; objIt.Title = title; objIt.Description = desc; objIt.Cost = objCurrency.SetValueByExchangeRate(cost, PlanExchangeRate); //Modified by Rahul Shah for PL #2501 to apply multi currency on boost screen objIt.IsDeployed = status; objIt.IsDeployedToIntegration = deployToIntegrationStatus; db.Entry(objIt).State = EntityState.Modified; int result = db.SaveChanges(); while (db.ImprovementTacticType_Metric.Where(itm => itm.ImprovementTacticTypeId == improvementId).Count() != 0) { /*remove old data based on improvementTacticId*/ ImprovementTacticType_Metric Itm = db.ImprovementTacticType_Metric.Where(itm => itm.ImprovementTacticTypeId == improvementId).FirstOrDefault(); db.Entry(Itm).State = EntityState.Deleted; result = db.SaveChanges(); } successMessage = string.Format(Common.objCached.EditImprovementTacticSaveSucess); } else { ErrorMessage = string.Format(Common.objCached.DuplicateImprovementTacticExits); return(Json(new { errormsg = ErrorMessage }, JsonRequestBehavior.AllowGet)); } } else { /*Add new improvementTactic record*/ ImprovementTacticType objIt = new ImprovementTacticType(); var existTactic = db.ImprovementTacticTypes.Where(_imprvTac => _imprvTac.ClientId == Sessions.User.CID && _imprvTac.Title.ToLower() == title.ToLower() && _imprvTac.IsDeleted.Equals(false)).ToList(); //// Modified by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. if (existTactic.Count == 0) { objIt.Title = title; objIt.Description = desc; objIt.Cost = objCurrency.SetValueByExchangeRate(cost, PlanExchangeRate); //Modified by Rahul Shah for PL #2501 to apply multi currency on boost screen objIt.IsDeployed = status; objIt.ClientId = Sessions.User.CID; objIt.CreatedBy = Sessions.User.ID; objIt.IsDeleted = false; objIt.CreatedDate = System.DateTime.Now; int intRandomColorNumber = rnd.Next(Common.ColorcodeList.Count); objIt.ColorCode = Convert.ToString(Common.ColorcodeList[intRandomColorNumber]); objIt.IsDeployedToIntegration = deployToIntegrationStatus; // db.ImprovementTacticTypes.Attach(objIt); db.Entry(objIt).State = EntityState.Added; db.ImprovementTacticTypes.Add(objIt); int result = db.SaveChanges(); improvementId = objIt.ImprovementTacticTypeId; successMessage = string.Format(Common.objCached.NewImprovementTacticSaveSucess); } else { ErrorMessage = string.Format(Common.objCached.DuplicateImprovementTacticExits); return(Json(new { errormsg = ErrorMessage }, JsonRequestBehavior.AllowGet)); } } //Modified by Mitesh Vaishnav on 03/06/2014 for Customized Target stage - Boost Improvement Tactic /*add into improvementType_metric table based on improvementId*/ improvementDetails = improvementDetails.Replace(@"\", ""); var stageValueList = JsonConvert.DeserializeObject <List <StageDetails> >(improvementDetails); ImprovementTacticType_Metric objItm = null; int MetricId = 0; double Weight = 0.0; MRPEntities dbAdd = null; foreach (var item in stageValueList) { objItm = new ImprovementTacticType_Metric(); Weight = 0.0; MetricId = 0; int.TryParse(item.StageId, out MetricId); objItm.StageId = MetricId; double.TryParse(item.Value, out Weight); objItm.Weight = Weight; objItm.ImprovementTacticTypeId = improvementId; objItm.CreatedDate = System.DateTime.Now; objItm.CreatedBy = Sessions.User.ID; objItm.StageType = item.StageType; dbAdd = new MRPEntities(); dbAdd.ImprovementTacticType_Metric.Attach(objItm); dbAdd.Entry(objItm).State = EntityState.Added; dbAdd.SaveChanges(); dbAdd.Dispose(); } TempData["SuccessMessage"] = successMessage; } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); TempData["SuccessMessage"] = string.Empty; TempData["ErrorMessage"] = e.InnerException.Message; return(Json(new { errormsg = e.InnerException.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { redirect = Url.Action("Index") })); }
/// <summary> /// Added By: Nirav Shah. /// Action to show Improvement Tactics Detail. /// </summary> /// <param name="id">ImprovementTacticTypeId</param> /// <returns>Return _InspectPopupImprovementTacticType PartialView</returns> public PartialViewResult DetailImprovementTacticData(int id = 0) { BoostImprovementTacticModel bittobj = new BoostImprovementTacticModel(); PlanExchangeRate = Sessions.PlanExchangeRate; string StageType_CR = Enums.StageType.CR.ToString(); string StageType_SV = Enums.StageType.SV.ToString(); string StageType_Size = Enums.MetricType.Size.ToString(); string StageTypeCW = Enums.Stage.CW.ToString(); double weight = 0; /* check the mode if id has value 0 then its create mode other wise edit mode */ if (id != 0) { ImprovementTacticType ittobj = GetImprovementTacticTypeRecordbyId(id); bittobj.Title = System.Web.HttpUtility.HtmlDecode(ittobj.Title); ////Modified by Mitesh Vaishnav on 07/07/2014 for PL ticket #584 bittobj.Description = System.Web.HttpUtility.HtmlDecode(ittobj.Description); ////Modified by Mitesh Vaishnav on 07/07/2014 for PL ticket #584 bittobj.Cost = objCurrency.GetValueByExchangeRate(ittobj.Cost, PlanExchangeRate); //Modified by Rahul Shah for PL #2501 to apply multi currency on boost screen bittobj.IsDeployed = ittobj.IsDeployed; bittobj.ImprovementTacticTypeId = id; bittobj.ColorCode = ittobj.ColorCode; bittobj.IsDeployedToIntegration = ittobj.IsDeployedToIntegration; ViewBag.Title = "Tactic Detail"; ViewBag.CanDelete = true; //// Added by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. ViewBag.IsCreated = false; //// Added by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. } else { bittobj.ImprovementTacticTypeId = 0; bittobj.Cost = 0; bittobj.IsDeployed = false; bittobj.IsDeployedToIntegration = false; ViewBag.Title = "New Tactic"; ViewBag.CanDelete = false; //// Added by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. ViewBag.IsCreated = true; //// Added by :- Sohel Pathan on 20/05/2014 for PL #457 to delete a boost tactic. } /*get the metrics related to improvement Tactic and display in view*/ List <MetricModel> listMetrics = new List <MetricModel>(); List <MetricModel> listMetricssize = new List <MetricModel>(); // Modified by Mitesh Vaishnav on 03/06/2014 for Customized Target stage - Boost Improvement Tactic List <Stage> lstStages = GetStageListbyClientId(Sessions.User.CID); var stageFilterCR = lstStages; //modified by Mitesh Vaishnav on 13/06/2014 to address #500 Customized Target stage - Boost Improvement Tactic var stageFilterSV = lstStages; //modified by Mitesh Vaishnav on 13/06/2014 to address #500 Customized Target stage - Boost Improvement Tactic //// Add MetricModel data to list except CW Stage Type data. MetricModel Metricsobj = null; foreach (var itemCR in stageFilterCR.Where(stage => stage.Level != null && stage.Code != StageTypeCW).OrderBy(stage => stage.Level).ToList()) { foreach (var itemSV in stageFilterSV.Where(stage => stage.Level != null && stage.Code != StageTypeCW).OrderBy(stage => stage.Level).ToList()) { if (itemCR.Level == itemSV.Level) { Metricsobj = new MetricModel(); Metricsobj.MetricType = StageType_CR; Metricsobj.MetricName = Common.GetReplacedString(itemCR.ConversionTitle); weight = db.ImprovementTacticType_Metric.Where(itm => itm.StageId == itemCR.StageId && itm.ImprovementTacticTypeId == id && itm.StageType == StageType_CR).Select(v => v.Weight).FirstOrDefault(); Metricsobj.ConversionValue = weight; weight = db.ImprovementTacticType_Metric.Where(itm => itm.StageId == itemSV.StageId && itm.ImprovementTacticTypeId == id && itm.StageType == StageType_SV).Select(v => v.Weight).FirstOrDefault(); Metricsobj.VelocityValue = weight; Metricsobj.MetricID_CR = itemCR.StageId; Metricsobj.MetricID_SV = itemSV.StageId; listMetrics.Add(Metricsobj); } } } //// Add null Stage Type MetricModel data to list. foreach (var item in lstStages.Where(stage => stage.Level == null)) { Metricsobj = new MetricModel(); Metricsobj.MetricID_Size = item.StageId; //start: Modified by Mitesh Vaishnav on 21/07/2014 for functional review point 73 var stageTypeList = item.ImprovementTacticType_Metric.Where(ittm => ittm.StageId == item.StageId).FirstOrDefault(); if (stageTypeList != null) { Metricsobj.MetricType = stageTypeList.StageType; } else { Metricsobj.MetricType = Enums.MetricType.Size.ToString(); } //End : Modified by Mitesh Vaishnav on 21/07/2014 for functional review point 73 Metricsobj.MetricName = item.Title; weight = db.ImprovementTacticType_Metric.Where(itm => itm.StageId == item.StageId && itm.ImprovementTacticTypeId == id).Select(v => v.Weight).FirstOrDefault(); Metricsobj.ConversionValue = weight; listMetricssize.Add(Metricsobj); } bittobj.listMetrics = listMetrics; bittobj.listMetricssize = listMetricssize; return(PartialView("_InspectPopupImprovementTacticType", bittobj)); }