Ejemplo n.º 1
0
        public static void EditPackage(PackageDatabase packageDbConn, Command.EditpkgOption data)
        {
            var reader = from item in packageDbConn.CoreDbContext.package
                         where item.name == data.Name
                         select item;

            if (!reader.Any())
            {
                ConsoleAssistance.WriteLine("Lost package.", ConsoleColor.Red);
                return;
            }

            var got    = reader.First();
            var newObj = data.ToDatabaseFormat(got);

            if (newObj.status)
            {
                packageDbConn.CoreDbContext.package.Remove(got);
                packageDbConn.CoreDbContext.package.Add(newObj.res);
                ConsoleAssistance.WriteLine("Operation done.", ConsoleColor.Yellow);
            }
            else
            {
                ConsoleAssistance.WriteLine("Illegal parameter", ConsoleColor.Red);
            }
        }
Ejemplo n.º 2
0
        public static (PackageDatabaseTablePackageItem res, bool status) ToDatabaseFormat(this Command.EditpkgOption ori, PackageDatabaseTablePackageItem item)
        {
            var obj = new PackageDatabaseTablePackageItem()
            {
                name = ori.Name == "~" ? item.name : ori.Name,
                aka  = ori.Aka == "~" ? item.aka : ori.Aka,
                desc = ori.Desc == "~" ? item.desc : ori.Desc
            };

            try {
                obj.type = ori.Type == "~" ? item.type : (PackageType)(int.Parse(ori.Type));
            } catch {
                return(obj, false);
            }

            return(obj, true);
        }