public bool DeleteStudentDetail(int id) { try { if (id > 0) { SampleDatabaseContext db = new SampleDatabaseContext(); Student studentObj = db.Students.Where(a => a.StudentID == id).FirstOrDefault(); if (studentObj != null) { db.Entry <Student>(studentObj).State = EntityState.Deleted; db.SaveChanges(); return(true); } return(false); } else { return(false); } } catch (Exception ex) { throw ex; } }
protected override void Up(MigrationBuilder migrationBuilder) { using (var databaseContext = SampleDatabaseContext.CreateContext()) { databaseContext.LookupTypes.AddRange( new List <LookupType>() { new LookupType() { Name = "ProductTypes", LookupValues = new List <LookupValue>() { new LookupValue() { Value = "Laptop" }, new LookupValue() { Value = "Monitor" }, new LookupValue() { Value = "Mouse" }, new LookupValue() { Value = "Keyboard" } } } }); databaseContext.SaveChanges(); } }
public MainWindow() { this.InitializeComponent(); this.context = new SampleDatabaseContext(this.dataServiceUri); this.employees = new ObservableCollection <Employee>(); this.EmployeeList.ItemsSource = this.employees; }
protected override void Down(MigrationBuilder migrationBuilder) { using (var databaseContext = SampleDatabaseContext.CreateContext()) { databaseContext.LookupTypes.Remove(databaseContext.LookupTypes.SingleOrDefault(t => t.Name == "ProductTypes")); databaseContext.SaveChanges(); } }
public List <Student> GetAllStudentDetail() { List <Student> lstStudent = null; SampleDatabaseContext db = new SampleDatabaseContext(); lstStudent = db.Students.ToList(); return(lstStudent); }
public Student GetStudentDetail(int id) { Student studentObj = null; if (id > 0) { SampleDatabaseContext db = new SampleDatabaseContext(); studentObj = db.Students.Where(a => a.StudentID == id).FirstOrDefault(); } return(studentObj); }
public JsonResult UpdatePageField(string id, string val, string pname) { if (Session["login"] == null || Session["login"] as LoginUser == null) { return(Json(new MyJsonResult <string>(true, "Unauthorize access."))); } LoginUser user = Session["login"] as LoginUser; //// You can add RoleName prop to LoginUser class and use it. //if (user.RoleName != "editor" && (user.RoleName != "*")) //{ // return Json(new MyJsonResult<string>(true, "Unauthorize access.")); //} SampleDatabaseContext db = new SampleDatabaseContext(); BasicPageField field = db.BasicPageFields.FirstOrDefault(x => x.Id == id); if (field == null) { field = new BasicPageField(); field.Id = id; field.PageName = pname; db.BasicPageFields.Add(field); } field.LastModifiedDate = DateTime.Now; field.LastModifiedUser = user.Username; field.Text = val; if (db.SaveChanges() > 0) { return(Json(new MyJsonResult <string>(false, "Update successful."))); } else { return(Json(new MyJsonResult <string>(false, "Update fail."))); } }
public Student SaveStudentDetail(int?id, Student student) { SampleDatabaseContext db = new SampleDatabaseContext(); try { if (id != null && id.Value > 0) { db.Entry <Student>(student).State = EntityState.Modified; } else { db.Entry <Student>(student).State = EntityState.Added; } db.SaveChanges(); } catch (Exception ex) { throw ex; } return(student); }
public LoginUnitOfWork(SampleDatabaseContext dbContext) { _dbContext = dbContext; }
public CarRepository(SampleDatabaseContext context) { this._context = context; }
public WebsitesController(SampleDatabaseContext context) { _context = context; }
public CarService() { this._context = new SampleDatabaseContext(); this._repository = new CarRepository(this._context); }
public BlogsController(SampleDatabaseContext context) { _context = context; }
public ProductsCountModel(ILogger <ProductsCountModel> logger, SampleDatabaseContext dbContext) { _logger = logger; _dbContext = dbContext; }
public void LoadPageFields() { SampleDatabaseContext db = new SampleDatabaseContext(); this.PageFields = db.BasicPageFields.Where(x => x.PageName == this.PageName).ToList(); }