public static UpdateTrackTarget CreateUpdateTrackTarget(TrackTarget trackTarget)
 {
     var updateTrackTarget = new UpdateTrackTarget();
     updateTrackTarget.ID = trackTarget.ID;
     updateTrackTarget.NiceName = trackTarget.NiceName;
     updateTrackTarget.PlanId = trackTarget.PlanId;
     return updateTrackTarget;
 }
        private void Add(UpdateTrackTarget updateTrackTarget)
        {
            using (var defaultContext = new DefaultContext())
            {
                defaultContext.TrackTargets.Add(updateTrackTarget.Create());
                defaultContext.SaveChanges();
            }

            Flag = true;
        }
 public void Update(UpdateTrackTarget updateTrackTarget)
 {
     if (updateTrackTarget.ID.Null())
     {
         Add(updateTrackTarget);
     }
     else
     {
         Edit(updateTrackTarget);
     }
 }
 // GET: Architecture/TrackTarget/Create
 public ActionResult Create(Guid? id)
 {
     var trackTargetServices = ServiceLocator.Instance.GetService<ITrackTargetServices>();
     var updateTrackTarget = new UpdateTrackTarget();
     if (id.HasValue)
     {
         updateTrackTarget = trackTargetServices.Get(id.GetValueOrDefault());
     }
     var trackPlanServices = ServiceLocator.Instance.GetService<ITrackPlanServices>();
     var trackPlan = trackPlanServices.Get();
     ViewBag.TrackPlans = new HtmlString(trackPlan.ToJson());
     ViewBag.UpdateTrackTarget = new HtmlString(updateTrackTarget.ToJson());
     return PartialView();
 }
 private void Edit(UpdateTrackTarget updateTrackPlan)
 {
     using (var defaultContext = new DefaultContext())
     {
         var trackPlan = defaultContext.TrackPlans.SingleOrDefault(x => x.ID == updateTrackPlan.ID);
         if (trackPlan.Null())
         {
             return;
         }
         defaultContext.TrackTargets.Add(updateTrackPlan.Create());
         defaultContext.SaveChanges();
     }
     Flag = true;
 }
 public ActionResult Edit(UpdateTrackTarget updateTrackTarget)
 {
     try
     {
         var trackTargetServices = ServiceLocator.Instance.GetService<ITrackTargetServices>();
         if (updateTrackTarget.Null())
         {
             var failure = trackTargetServices.GetResult();
             return Json(failure);
         }
         trackTargetServices.Update(updateTrackTarget);
         var result = trackTargetServices.GetResult();
         return Json(result);
     }
     catch
     {
         return Json(1);
     }
 }