예제 #1
0
        public string addItem(string name, int idc)
        {
            try
            {
                var t = DbApp.Categories.OrderBy(r => r.Id).ToList();

                Categories categories = new Categories();
                categories.Name = name;
                if (idc == -1)
                {
                    categories.ParentId = null;
                }
                else
                {
                    categories.ParentId = idc;
                }

                if (t.Any())
                {
                    categories.Id = t.Last().Id + 1;
                }
                else
                {
                    categories.Id = 1;
                }

                DbApp.Categories.Add(categories);
                DbApp.SaveChanges();
                return("True");
            }
            catch (Exception ex)
            {
                return("False");
            }
        }
예제 #2
0
 public string deleteTreeItem(int id)
 {
     try
     {
         DbApp.Categories.Remove(DbApp.Categories.Where(t => t.Id == id).FirstOrDefault());
         DbApp.SaveChanges();
         return("True");
     }
     catch (Exception ex)
     {
         return("False");
     }
 }
예제 #3
0
        public string edititem(string name, int idc, int?Pid)
        {
            try
            {
                var r = DbApp.Categories.Where(t => t.Id == idc).ToList();
                if (!r.Any())
                {
                    return("False");
                }

                r.First().Name     = name;
                r.First().ParentId = Pid;

                DbApp.SaveChanges();
                return("True");
            }
            catch (Exception ex)
            {
                return("False");
            }
        }