コード例 #1
0
 public ActionResult Update(CategoryModel category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (var Context = new ContextClass())
             {
                 var cat = Context.Categories.SingleOrDefault(c => c.CategoryId == category.CategoryId);
                 if (cat == null)
                 {
                     throw new Exception("No record found for the given id : " + category.CategoryId);
                 }
                 cat.CategoryName = category.CategoryName;
                 Context.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         catch (Exception er)
         {
             ViewData["ErrorMessage"] = er.Message;
             return(View("Error"));
         }
     }
     return(View(category));
 }
コード例 #2
0
 //ContextImportTypes segManager;
 //public ZTypeFinder Finder { get;private set; }
 public TypeArgParser(ContextClass classContext)//(ContextImportTypes segManager)
 {
     //this.segManager = segManager;
     // Finder = new ZTypeFinder(segManager);
     this.ClassContext = classContext;
     ImportUseContext  = classContext.FileContext.ImportUseContext;
 }
コード例 #3
0
        public ActionResult DeletePost(int id)
        {
            try
            {
                ProductModel product = null;

                if (id < 1)
                {
                    throw new Exception("No record found for the given id : " + id);
                }

                using (var Context = new ContextClass())
                {
                    product = Context.Products.SingleOrDefault(c => c.ProductId == id);
                    if (product == null)
                    {
                        throw new Exception("No record found for the given id : " + id);
                    }
                    Context.Products.Remove(product);
                    Context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception er)
            {
                ViewData["ErrorMessage"] = er.Message;
                return(View("Error"));
            }
        }
コード例 #4
0
        public IActionResult Tournois()
        {
            var db = new ContextClass();
            var t  = db.Tournois;

            return(View(t.ToList()));
        }
コード例 #5
0
        public void Interpret(ContextClass context)
        {
            if (context.Input.Length == 0)
            {
                return;
            }

            if (context.Input.StartsWith(Nine()))
            {
                context.Output += (9 * Multiplier());
                context.Input   = context.Input.Substring(2);
            }
            else if (context.Input.StartsWith(Four()))
            {
                context.Output += (4 * Multiplier());
                context.Input   = context.Input.Substring(2);
            }
            else if (context.Input.StartsWith(Five()))
            {
                context.Output += (5 * Multiplier());
                context.Input   = context.Input.Substring(1);
            }
            else if (context.Input.StartsWith(One()))
            {
                context.Output += (1 * Multiplier());
                context.Input   = context.Input.Substring(1);
            }

            while (context.Input.StartsWith(One()))
            {
                context.Output += (1 * Multiplier());
                context.Input   = context.Input.Substring(1);
            }
        }
コード例 #6
0
 public ActionResult Update(int id)
 {
     try
     {
         ProductModel product = null;
         if (id < 1)
         {
             throw new Exception("No record found for the given id : " + id);
         }
         using (var Context = new ContextClass())
         {
             product = Context.Products.SingleOrDefault(c => id == c.ProductId);
         }
         if (product == null)
         {
             throw new Exception("No record found for the given id : " + id);
         }
         return(View(product));
     }
     catch (Exception er)
     {
         ViewData["ErrorMessage"] = er.Message;
         return(View("Error"));
     }
 }
コード例 #7
0
        private void DemoStrategy()
        {
            List <String> data = new List <string>()
            {
                "peter",
                "jakob",
                "vibeke",
                "mohammed"
            };

            // close to Pattern
            ContextClass context1 = new ContextClass();

            context1.InsertStrategyMethod(data, new StrategyClass());
            Console.WriteLine("Strategy #1 ::");
            Console.WriteLine(context1);


            // Close to the C# way of doing
            ContextClassMoreCSharpLike context2 = new ContextClassMoreCSharpLike();

            context2.StrategyMethod = (s) => { return("hej " + s.ToUpper()); };
            context2.InsertStrategyMethod(data);
            Console.WriteLine("Strategy #2 ::");
            Console.WriteLine(context2);
        }
コード例 #8
0
 public ActionResult Update(ProductModel product)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (var Context = new ContextClass())
             {
                 var pro = Context.Products.SingleOrDefault(c => c.ProductId == product.ProductId);
                 if (pro == null)
                 {
                     throw new Exception("No record found for the given id : " + product.ProductId);
                 }
                 pro.ProductName = product.ProductName;
                 Context.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         catch (Exception er)
         {
             ViewData["ErrorMessage"] = er.Message;
             return(View("Error"));
         }
     }
     return(View(product));
 }
コード例 #9
0
        static void Main(string[] args)
        {
            //create the context
            var roman   = "MMXV";
            var context = new ContextClass(roman);

            //Building the parse tree
            var expressionTree = new List <ExpressionClass>
            {
                new ThousandExpression(),
                new HundredExpression(),
                new TenExpression(),
                new OneExpression(),
            };

            //Interpret
            foreach (var expression in expressionTree)
            {
                expression.Interpret(context);
            }

            Console.WriteLine($"The decimal number is {context.Output}");

            Console.ReadKey();
        }
コード例 #10
0
ファイル: FileClass.cs プロジェクト: xonoer/ZCompileCore2
        public void AnalyTypeName()
        {
            ClassContext = new ContextClass(this.FileContext);

            if (ImporteSection != null)
            {
                ImporteSection.FileContext = this.FileContext;
            }
            if (UseSection != null)
            {
                UseSection.FileContext = this.FileContext;
            }


            if (ClassSection != null)
            {
                ClassSection.FileContext = this.FileContext;
            }

            string fileName = this.FileContext.FileModel.GetFileNameNoEx();

            if (DimSection != null)
            {
                DimSection.FileContext = this.FileContext;
                DimSection.IsInClass   = true;
                DimSection.AnalyName(fileName);
            }

            ClassSection.Analy(this.FileModel.GetFileNameNoEx(), this.ClassContext);
            ClassContext.IsStaticClass = ClassSection.IsStatic;
        }
コード例 #11
0
        public ActionResult Update(int id)
        {
            try
            {
                CategoryModel category = null;

                if (id < 1)
                {
                    throw new Exception("No record found for the given id : " + id);
                }

                using (var Context = new ContextClass())
                {
                    category = Context.Categories.SingleOrDefault(c => id == c.CategoryId);
                }

                if (category == null)
                {
                    throw new Exception("No record found for the given id : " + id);
                }

                return(View(category));
            }
            catch (Exception er)
            {
                ViewData["ErrorMessage"] = er.Message;
                return(View("Error"));
            }
        }
コード例 #12
0
        //cstrtor
        public ClientController(ContextClass context)
        {
            ContextC = context;
            DbContextOptionsBuilder dbContextOptionsBuilder = new DbContextOptionsBuilder();

            dbContextOptionsBuilder.EnableSensitiveDataLogging();
        }
コード例 #13
0
        public ActionResult Index(int page = 1)
        {
            try
            {
                int pagesize = 5;
                List <ProductModel> listofProd;
                int count;

                using (var Context = new ContextClass())
                {
                    listofProd = Context.Products.Include("Category").OrderBy(p => p.ProductId).Skip((page - 1) * pagesize).Take(pagesize).ToList();
                    count      = Context.Products.Count();
                }

                var productVM = new productViewModel
                {
                    listofProducts    = listofProd,
                    TotalRecordsCount = count,
                    PageNumber        = page,
                    pagesize          = pagesize
                };
                return(View(productVM));
            }
            catch (Exception)
            {
                return(View("Error"));
            }
        }
コード例 #14
0
 protected virtual void Dispose(bool disposing)
 {
     if (!this._disposed)
     {
         if (disposing)
         {
             ContextClass.GetInstance().Dispose();
         }
     }
     this._disposed = true;
 }
コード例 #15
0
ファイル: EFRepository.cs プロジェクト: seraykskn/TakeOff
        public EFRepository(ContextClass dbContext)
        {
            //if (dbContext == null)
            //{
            //    throw new ArgumentNullException("dbcontext can not be null.");


            //}

            this._dbContext = dbContext;
            this._dbSet     = dbContext.Set <T>();
        }
コード例 #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            var context = new ContextClass();
            {
                User u = new User();
                u.id       = 1;
                u.UserName = "******";

                context.Users.Add(u);
                context.SaveChanges();
            }
        }
コード例 #17
0
ファイル: ToDoController.cs プロジェクト: roshni1310/toDo_API
        public TodoController(ContextClass context)
        {
            _context = context;

            if (_context.TodoItems.Count() == 0)
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                _context.TodoItems.Add(new ItemClass {
                    Name = "Item1"
                });
                _context.SaveChanges();
            }
        }
コード例 #18
0
 public void Analy(string fileName, ContextClass context)
 {
     if (NameToken == null)
     {
         ClassName = fileName;
     }
     else
     {
         ClassName = NameToken.GetText();
         if (ClassName != fileName)
         {
             this.FileContext.Errorf(BaseTypeToken.Position, "类名称 '" + ClassName + "'和文件名称'" + fileName + "'不一致");
         }
     }
     AnalyBase(context);
 }
コード例 #19
0
ファイル: Generator.cs プロジェクト: vain0x/playground
        public void Generate()
        {
            var style        = new CSharpStyle(Argument.Namespace, Argument.ContextName);
            var provider     = Provider();
            var schema       = provider.GetSchema();
            var contextClass = new ContextClass(schema, style);
            var collection   = new EntityClassCollection(style, provider.TypeNameMapper, schema);

            var outputDirectory = new DirectoryInfo(Argument.OutputDirectoryPath);

            Clear(outputDirectory);
            contextClass.WriteToFile(
                new FileInfo(Path.Combine(outputDirectory.FullName, style.ContextName + ".cs"))
                );
            collection.WriteToDirectory(outputDirectory);
        }
コード例 #20
0
 // GET: List of Categories
 public ActionResult Index()
 {
     try
     {
         List <CategoryModel> listofCateogories = null;
         using (var Context = new ContextClass())
         {
             listofCateogories = Context.Categories.ToList();
         }
         return(View(listofCateogories));
     }
     catch (Exception)
     {
         return(View("Error"));
     }
 }
コード例 #21
0
        public string GetMethodName()
        {
            ContextClass context   = this.ProcContext.ClassContext;
            ZClassType   baseZType = context.BaseZType;

            if (baseZType != null)
            {
                ZCallDesc callDesc = ToZCallDesc(ProcDesc);
                var       zmethod  = baseZType.SearchZMethod(callDesc);
                if (zmethod != null)
                {
                    return(zmethod.SharpMethod.Name);
                }
            }
            return(this.ProcDesc.ToMethodName());
        }
コード例 #22
0
ファイル: ClassAST.cs プロジェクト: pyzh/ZLanguage3
        public ClassAST(FileAST astFile, SectionNameRaw nameSection, SectionExtendsRaw extendsSection
                        , SectionPropertiesRaw propertiesSection)
            : base(astFile)
        {
            this.ClassContext = new ContextClass(this.FileContext);
            ClassNameSection  = new SectionClassName(nameSection);
            Constructors      = new List <ProcConstructorBase>();
            Methods           = new List <ProcMethod>();


            Extends = new SectionExtendsClass(this, extendsSection);

            if (propertiesSection != null)
            {
                Properties = new SectionPropertiesClass(this, propertiesSection);
            }
        }
コード例 #23
0
        private void CreateContext()
        {
            NestedClassContext           = new ContextClass(this.ExpContext.FileContext);
            NestedClassContext.ClassName = this.ExpContext.ProcContext.CreateNestedClassName();

            NestedProcContext                    = new ContextProc(NestedClassContext);
            NestedProcContext.ProcName           = NestedClassContext.ClassName + "$CALL";
            NestedProcContext.ProcManagerContext = NestedClassContext.ProcManagerContext;
            NestedProcContext.ProcManagerContext.Add(NestedProcContext);

            NestedStmt             = new StmtCall();
            NestedStmt.ProcContext = NestedProcContext;

            NestedExpContext = new ContextExp(NestedProcContext, NestedStmt);
            BodyExp.SetContext(NestedExpContext);
            CreateEmitContext();
        }
コード例 #24
0
        static void Main(string[] args)
        {
            var dept = new ContextClass();

            Console.WriteLine("ADD DEPARTMENT");
            var deptObj = new CodeFirstDeptClass {
                Id = 1, Name = "IT", Location = "Pune"
            };

            dept.Departments.Add(deptObj);
            dept.SaveChanges();
            Console.WriteLine("Record Added");



            Console.ReadLine();
        }
コード例 #25
0
 private void AnalyBase(ContextClass context)
 {
     SuperTable = null;
     if (BaseTypeToken == null)
     {
         IsStatic   = false;
         BaseZType  = ZTypeManager.ZOBJECT;
         SuperTable = new SuperSymbolTable("SUPER-唯一", ZTypeManager.ZOBJECT);
     }
     else
     {
         BaseTypeName = BaseTypeToken.GetText();
         if (BaseTypeName == "唯一")
         {
             IsStatic   = true;
             SuperTable = new SuperSymbolTable("SUPER-唯一", null);
         }
         else
         {
             IsStatic = false;
             var ztypes = ZTypeManager.GetByMarkName(BaseTypeName);
             if (ztypes.Length == 0)
             {
                 errorf(BaseTypeToken.Position, "类型'{0}'不存在", BaseTypeName);
             }
             else if (ztypes.Length == 1)
             {
                 BaseZType  = ztypes[0] as ZClassType;
                 SuperTable = new SuperSymbolTable("SUPER-" + BaseZType.ZName, BaseZType);
             }
             else if (ztypes.Length == 0)
             {
                 errorf(BaseTypeToken.Position, "'{0}'存在{1}个同名类型", BaseTypeName, ztypes.Length);
                 SuperTable = new SuperSymbolTable("SUPER", null);
             }
         }
     }
     if (SuperTable == null)
     {
         SuperTable = new SuperSymbolTable("SUPER-STATIC", null);
     }
     SuperTable.ParentTable = FileContext.UseContext.SymbolTable;
     context.SetSuperTable(SuperTable);
     context.BaseZType = BaseZType;
 }
コード例 #26
0
        public static string GetDeviceId() // IMEI: International Mobile Equipment Identity
        {
#if UNITY_EDITOR
            return("123456789012345");
#else
            string            KEY = ContextClass.GetStatic <string>("TELEPHONY_SERVICE");
            AndroidJavaObject telephonyService = CurrentActivity.Call <AndroidJavaObject>("getSystemService", KEY);
            try
            {
                return(telephonyService.Call <string>("getDeviceId"));
            }
            catch (Exception e)
            {
                Debug.LogError("GetDeviceId failed! " + e.Message);
                return(GetAndoidId());
            }
#endif
        }
コード例 #27
0
 public ActionResult Create()
 {
     try
     {
         List <CategoryModel> listofCatagories;
         using (var Context = new ContextClass())
         {
             listofCatagories = Context.Categories.ToList();
         }
         SelectList sl = new SelectList(listofCatagories, "CategoryId", "CategoryName");
         ViewData["listofCatagories"] = sl;
         return(View());
     }
     catch (Exception)
     {
         return(View("Error"));
     }
 }
コード例 #28
0
 public ActionResult Create(ProductModel product)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (var Context = new ContextClass())
             {
                 Context.Products.Add(product);
                 Context.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         catch (Exception)
         {
             return(View("Error"));
         }
     }
     return(View(product));
 }
コード例 #29
0
 public ActionResult Create(CategoryModel category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (var Context = new ContextClass())
             {
                 Context.Categories.Add(category);
                 Context.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         catch (Exception)
         {
             return(View("Error"));
         }
     }
     return(View(category));
 }
コード例 #30
0
    public void ContextTest()
    {
        var contextClass = new ContextClass();
        var serializer   = new BinarySerializer();

        var context = new Context {
            SerializeCondtion = false
        };

        var stream = new MemoryStream();

        serializer.Serialize(stream, contextClass, context);

        context = new Context {
            SerializeCondtion = true
        };

        stream = new MemoryStream();
        serializer.Serialize(stream, contextClass, context);

        Assert.AreEqual(sizeof(int), stream.Length);
    }