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

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

            //set database
            var newObj = data.ToDatabaseFormat();

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

            try {
                obj.type = (PackageType)(int.Parse(ori.Type));
            } catch {
                return(obj, false);
            }

            return(obj, true);
        }