public ActionResult _EditMessageParameter(int processid, int messagetypeId, string parameter, int edit, string messageName)
        {
             PD_MessageParameter_ViewModel pvm;
             PD_Parameter pc = new PD_Parameter(){ PD_Process_Id = processid};
             if (parameter != null)
             {
                 pc = _db.PD_Parameters.Find(processid, parameter);

                 var cfg = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(pc.Config);


                 pvm = new PD_MessageParameter_ViewModel() { Name = pc.Name, Type = cfg.Type, DefaultValue = cfg.Value.ToString(), Process_Id = processid, Message_Type_Id = messagetypeId, previousName = parameter, messageName = messageName };
             }
             else
             {
                 pvm = new PD_MessageParameter_ViewModel() { Process_Id = processid, Message_Type_Id = messagetypeId, Type = "string" , DefaultValue = "0", messageName = messageName };
             }
             ViewBag.Edit = edit;
             return PartialView(pvm);
        }
        public ActionResult _EditMessageParameter(PD_MessageParameter_ViewModel model)
        {
            var _p = _db.PD_Processes.Find(model.Process_Id);
            if (User.Identity.Name.Equals(_p.LockedBy))
            //_p.MessageTypes[].Parameter.Results View
            {
                PD_Parameter p = _db.PD_Parameters.Find(model.Process_Id, model.Name);
                if (p == null)     
                {
                    if (model.previousName != null)
                    {
                        _DeleteMessageParameter(model.Process_Id, model.Message_Type_Id, model.previousName);
                    }
                    string val = model.DefaultValue;
                    if (model.Type.Equals("string"))
                    {
                        val = "\"" + val + "\"";
                    }
                    string cfg = "{\"Type\":\"" + model.Type + "\",\"Value\":" + val + "}";
                    p = new PD_Parameter() { PD_Process_Id = model.Process_Id, Name = model.Name, Config = cfg };
                    _db.PD_Parameters.Add(p);

                }else          
                {                         
                    try
                    {
                       model.DefaultValue = checkDefaultValue(model.Type, model.DefaultValue);
                    }catch(Exception e)
                    {
                        return RedirectToAction("ViewProcess", new { processid = model.Process_Id, edit = 1 });
                    }
                    string val = model.DefaultValue;
                    if (model.Type.Equals("string"))
                    {
                        val = "\"" + val + "\"";
                    }
                    p.Config = "{\"Type\":\"" + model.Type + "\",\"Value\":" + val + "}";
                }
                var item = _db.PD_MessageTypes.Find(model.Process_Id, model.Message_Type_Id);
                if (item == null)
                {
                    item = new PD_MessageType() { PD_Process_Id = model.Process_Id };
                    item.Name = model.messageName;                    
                    item.Id = IdHelper.getMessageTypeId(_db, model.Process_Id);
                    _db.PD_MessageTypes.Add(item);
                }
                if (!item.Parameters.Contains(model.Name))
                {
                    item.Parameters.Add(model.Name);
                }


                List<PD_Subject> mylist = _db.PD_Subjects.Where(x => x.PD_Process_Id == model.Process_Id).ToList<PD_Subject>();
                foreach (var i in mylist)
                {
                    //i.GlobalParameters.SerializedValue.Replace(parameter,"");
                    i.GlobalParameters.Remove(model.previousName);
                    if(model.Name!=null)i.GlobalParameters.Add(model.Name);
                }
                _db.SaveChanges();
                //need via AJAX or rewrite this all
                return RedirectToAction("ViewProcess", new { processid = model.Process_Id, edit = 1 });    //original, working

                //return View(model);
                //return RedirectToAction("_EditMessageType", new { processid = model.Process_Id, id = item.Id, edit = 1 });      //first way, not working, 
                
                //var model2 = new PD_MessageTypeDTO_ViewModel() { Id = model.Process_Id, PD_Process_Id = item.Id, Name = item.Name, Parameters = new List<PD_Parameter_ViewModel>() }; //second way, not working
                //model2.Parameters = listofStringParametersToViewModel(model.Process_Id, item.Parameters);
                //return View(_EditMessageType(model.Process_Id,item.Id,1));

                //var model2  = new PD_MessageParameter_ViewModel() { Name = pc.Name, Type = cfg.Type, DefaultValue = cfg.Value.ToString(), Process_Id = processid, Message_Type_Id = messagetypeId, previousName = parameter, messageName = messageName };
                //var model2 = new PD_MessageParameter_ViewModel() {};
                //return PartialView(model2);

                //return RedirectToAction("_EditMessageParameter", new { processid = model.Process_Id, messagetypeId = item.Id,  edit = 1 }); 

            }
            else
            {
                return null;
            }
        }