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)); }
//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; }
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")); } }
public IActionResult Tournois() { var db = new ContextClass(); var t = db.Tournois; return(View(t.ToList())); }
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); } }
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")); } }
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); }
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)); }
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(); }
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; }
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")); } }
//cstrtor public ClientController(ContextClass context) { ContextC = context; DbContextOptionsBuilder dbContextOptionsBuilder = new DbContextOptionsBuilder(); dbContextOptionsBuilder.EnableSensitiveDataLogging(); }
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")); } }
protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { ContextClass.GetInstance().Dispose(); } } this._disposed = true; }
public EFRepository(ContextClass dbContext) { //if (dbContext == null) //{ // throw new ArgumentNullException("dbcontext can not be null."); //} this._dbContext = dbContext; this._dbSet = dbContext.Set <T>(); }
// 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(); } }
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(); } }
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); }
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); }
// 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")); } }
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()); }
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); } }
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(); }
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(); }
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; }
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 }
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")); } }
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)); }
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)); }
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); }