public async Task Index(int id, int newParentId) { parentchange pc = new parentchange { id = id, newparentid = newParentId }; using (var client = new HttpClient()) { // Update port # in the following line. client.BaseAddress = new Uri(Share.Baseurl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); StringContent content = new StringContent(JsonConvert.SerializeObject(pc), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync( "api/ChangeParent", content); if (response.IsSuccessStatusCode) { Response.Write($"Succeed action!" + response.StatusCode); } else { response.EnsureSuccessStatusCode(); } } }
public void Change_the_parent_node_of_a_given_node() { parentchange pc = new parentchange { id = 2, newparentid = 4 }; CompanyHierarchy companyhierarchytestobj = new CompanyHierarchy(); bool result = companyhierarchytestobj.Change_the_parent_node_of_a_given_node(pc); }
public bool PostChangeCurrentParent([FromBody] parentchange pc) { var container = new WindsorContainer(); container.Register(Component.For <ICompanyHierarchy>().ImplementedBy <CompanyHierarchy>().LifestyleSingleton()); // Resolve an object of type ICompanyHierarchy (ask the container for an instance) // This is analagous to calling new() in a non-IoC application. _CompanyHierarchy = container.Resolve <ICompanyHierarchy>(); bool result = _CompanyHierarchy.Change_the_parent_node_of_a_given_node(pc); return(result); }
//It's supposed if changed the parentid of given node the parent of their children dont changed public bool Change_the_parent_node_of_a_given_node(parentchange pc) { CompanyStructuredSample.Repository.Node given_node = ctx.Node.SingleOrDefault(nc => nc.Id == pc.id); given_node.ParentId = pc.newparentid; ctx.Node.Attach(given_node); ctx.Entry(given_node).State = System.Data.Entity.EntityState.Modified; try { ctx.SaveChanges(); return(true); } catch { return(false); } //IEnumerable<CompanyStructured.Common.Models.Node> nodes = Get_all_children(n); ////it's needed to change parent of the given node either //nodes.ToList().Add(n); //nodes.ToList().ForEach(x => x.parentId = newparent.Id); //using (var ctx = new CompanyStructuredContext()) //{ // foreach (var item in nodes) // { // CompanyStructuredSample.Repository.Node itemmap = new CompanyStructuredSample.Repository.Node // { // Id = n.Id, // Name = n.name, // ParentId = n.parentId // }; // ctx.Node.Attach(itemmap); // ctx.Entry(itemmap).State = System.Data.Entity.EntityState.Modified; // } // try // { // ctx.SaveChanges(); // return true; // } // catch // { // return false; // } //} }