public static IList <DetailProductModel> All()
        {
            var result = HttpContext.Current.Session["DetailProducts"] as IList <DetailProductModel>;

            if (result == null)
            {
                HttpContext.Current.Session["DetailProducts"] = result =
                    new SampleDataContext().DetailProducts.Select(p => new DetailProductModel
                {
                    ProductID    = p.ProductID,
                    ProductName  = p.ProductName,
                    UnitPrice    = (decimal)p.UnitPrice.GetValueOrDefault(),
                    UnitsInStock = p.UnitsInStock.GetValueOrDefault(),
                    Discontinued = p.Discontinued,
                    Category     = new CategoryModel()
                    {
                        CategoryID = p.Category.CategoryID, CategoryName = p.Category.CategoryName
                    },
                    Country = new CountryModel()
                    {
                        CountryID = p.Country.CountryID, CountryNameShort = p.Country.CountryNameShort, CountryNameLong = p.Country.CountryNameLong
                    },
                    CategoryID      = p.CategoryID,
                    CountryID       = p.CountryID,
                    CustomerRating  = p.CustomerRating,
                    LastSupply      = p.LastSupply,
                    QuantityPerUnit = p.QuantityPerUnit,
                    TargetSales     = p.TargetSales,
                    UnitsOnOrder    = p.UnitsOnOrder
                }).ToList();
            }

            return(result);
        }
Exemplo n.º 2
0
        private void GetComboboxList()
        {
            using (SampleDataContext db = new SampleDataContext())
            {
                var List = from ds in db.DetailSchedules
                           join hs in db.HeaderSchedules
                           on ds.ScheduleId equals hs.ScheduleId
                           join s in db.Subjects
                           on ds.SubjectId equals s.SubjectId
                           where ds.TeacherId == teacher.TeacherId && hs.Finalize == 1
                           select new
                {
                    s.SubjectId,
                    s.Name,
                    hs.ClassName,
                };

                foreach (var l in List)
                {
                    string subject = string.Format("{0} - {1}", l.SubjectId, l.Name);
                    string kelas   = l.ClassName;

                    CbxSubject.Items.Add(subject);
                    CbxClass.Items.Add(kelas);
                }
            }
        }
        private void RefreshDGV()
        {
            using (SampleDataContext db = new SampleDataContext())
            {
                DGVStudents.DataSource = from dsc in db.DetailScores
                                         join ds in db.DetailSchedules
                                         on dsc.DetailId equals ds.DetailId
                                         join s in db.Subjects
                                         on ds.SubjectId equals s.SubjectId
                                         join st in db.Students
                                         on dsc.StudentId equals st.StudentId
                                         where st.StudentId == this.student.StudentId
                                         select new
                {
                    s.SubjectId,
                    Subject = s.Name,
                    dsc.Assignment,
                    dsc.MidExam,
                    dsc.FinalExam
                };
                //foreach (DataGridViewRow row in DGVStudents.Rows)
                //{
                //    int assignment = Convert.ToInt32(row.Cells["Assignment"].Value.ToString());
                //    int mid = Convert.ToInt32(row.Cells["MidExam"].Value.ToString());
                //    int final = Convert.ToInt32(row.Cells["FinalExam"].Value.ToString());

                //    int? finalscore = ((assignment * subject.Assignment) / 100) + ((mid * subject.MidExam) / 100) + ((final * subject.FinalExam) / 100);
                //    row.Cells["Final"].Value = finalscore;
                //}
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SampleDataContext context = new SampleDataContext();
            List <Employee>   l       = new List <Employee>();
            var qry = from a in context.tbl_employees where a.Gender == "Female"
                      orderby a.Salary ascending
                      select new Employee()
            {
                ID           = a.Id,
                Fname        = a.FName,
                Lname        = a.Lname,
                Gender       = a.Gender,
                Salary       = a.Salary,
                DepartmentId = a.DeparmentId
            };

            l = qry.ToList();
            var e1 = from emp in context.tbl_employees
                     where emp.Gender == "Male"
                     orderby emp.Salary descending
                     select emp;

            GridView1.DataSource = l;
            GridView1.DataBind();
        }
Exemplo n.º 5
0
 public SampleService(SampleDataContext dbContext, IHttpContextAccessor httpContextAccessor, IOptions <AppSettings> appSettings, IMapper mapper)
 {
     _dbContext   = dbContext;
     _httpContext = httpContextAccessor.HttpContext;
     _appSettings = appSettings.Value;
     _mapper      = mapper;
 }
Exemplo n.º 6
0
        public async Task <IHttpActionResult> Filter([FromUri(Name = "")] QuerySamplesRequest request)
        {
            if (request == null)
            {
                request = new QuerySamplesRequest();
            }

            if (request.Name == "badrequest")
            {
                return(InvalidRequest("Dude, that's a bad request.", "ValidationError"));
            }

            QuerySamplesResponse response;

            using (var context = new SampleDataContext())
            {
                IQueryable <Sample> query = context.Samples;

                if (!String.IsNullOrEmpty(request.Name))
                {
                    query = query.Where(s => s.Name == request.Name);
                }

                var page = await query.WithNoLock(q => q.Select(request.Fields).ToPageAsync(request));

                return(Page(page));
            }

            return(Ok(response));
        }
Exemplo n.º 7
0
        public EmployeeFakeRepository(SampleDataContext context) : base(context)
        {
#if DEBUG
            //Valid if file exists for generated locally before committed
            if (!Record.Exists <Employee>())
            {
                //Load test data
                //NOTE: Remember to filter only the data that you need to test
                this.FakeData = context.Employees.Select(y => new Employee
                {
                    Id                 = y.Id,
                    EmployeeTypeId     = y.EmployeeTypeId,
                    FirstName          = y.FirstName,
                    LastName           = y.LastName,
                    OfficialDocumentId = y.OfficialDocumentId,
                    EmployeeType       = new EmployeeType
                    {
                        Id   = y.EmployeeType.Id,
                        Name = y.EmployeeType.Name
                    }
                }).ToList();

                //Record the data
                Record.RecordData(this.FakeData);
            }
#endif

            if (!this.FakeData.Any())
            {
                this.FakeData = Record.LoadData <Employee>().ToList();
            }
        }
 private List <Student> GetStudentList()
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         return(db.Students.ToList());
     }
 }
 private void BtnInclude_Click(object sender, EventArgs e)
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         if (DGVStudent.SelectedRows.Count > 0)
         {
             DetailClass detail = db.DetailClasses.Where(dc => dc.StudentId == selectedstudent.StudentId)
                                  .FirstOrDefault();
             if (detail == null)
             {
                 db.DetailClasses.InsertOnSubmit(new DetailClass {
                     ClassName = CbxClass.SelectedItem.ToString(), StudentId = selectedstudent.StudentId
                 });
                 db.SubmitChanges();
                 RefreshDGVStudent();
                 RefreshDGVParticipate();
             }
             else if (detail != null)
             {
                 db.DetailClasses.DeleteOnSubmit(detail);
                 db.DetailClasses.InsertOnSubmit(new DetailClass {
                     ClassName = CbxClass.SelectedItem.ToString(), StudentId = selectedstudent.StudentId
                 });
                 db.SubmitChanges();
                 RefreshDGVStudent();
                 RefreshDGVParticipate();
             }
         }
     }
 }
Exemplo n.º 10
0
 private void GetEntry()
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         if (student != null)
         {
             TbxID.Text      = student.StudentId;
             TbxName.Text    = student.Name;
             TbxPhone.Text   = student.PhoneNumber;
             TbxAddress.Text = student.Address;
             if (student.Photo != null)
             {
                 PbxPicture.Image = Image.FromFile(Application.StartupPath + "\\Images\\" + student.Photo);
                 Oldfilename      = student.Photo;
             }
         }
         else if (teacher != null)
         {
             TbxID.Text      = teacher.TeacherId;
             TbxName.Text    = teacher.Name;
             TbxPhone.Text   = teacher.PhoneNumber;
             TbxAddress.Text = teacher.Address;
             if (teacher.Photo != null)
             {
                 PbxPicture.Image = Image.FromFile(Application.StartupPath + "\\Images\\" + teacher.Photo);
                 Oldfilename      = teacher.Photo;
             }
         }
     }
 }
Exemplo n.º 11
0
 private void UpdateProfile()
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         if (this.student != null)
         {
             Student student = db.Students.Where(s => s.StudentId == this.student.StudentId)
                               .FirstOrDefault();
             student.Name        = TbxName.Text;
             student.PhoneNumber = TbxPhone.Text;
             student.Address     = TbxAddress.Text;
             if (newpath != null)
             {
                 student.Photo = filename;
             }
             this.student = student;
             db.SubmitChanges();
         }
         else if (this.teacher != null)
         {
             Teacher teacher = db.Teachers.Where(t => t.TeacherId == this.teacher.TeacherId)
                               .FirstOrDefault();
             teacher.Name        = TbxName.Text;
             teacher.PhoneNumber = TbxPhone.Text;
             teacher.Address     = TbxAddress.Text;
             if (newpath != null)
             {
                 teacher.Photo = filename;
             }
             this.teacher = teacher;
             db.SubmitChanges();
         }
     }
 }
Exemplo n.º 12
0
        public IHttpActionResult Filter([FromUri(Name = "")] QuerySamplesRequest request)
        {
            Logger.Trace("Fetching samples.");

            if (request == null)
            {
                request = new QuerySamplesRequest();
            }

            if (request.Name == "badrequest")
            {
                return(InvalidRequest("Dude, that's a bad request.", "ValidationError"));
            }

            QuerySamplesResponse response;

            using (var context = new SampleDataContext())
            {
                IQueryable <Sample> query = context.Samples;

                if (!String.IsNullOrEmpty(request.Name))
                {
                    query = query.Where(s => s.Name == request.Name);
                }

                response = new QuerySamplesResponse(query.WithNoLock(q => q.Select(request.Fields).ToPage(request)));
            }

            return(Ok(response));
        }
Exemplo n.º 13
0
    protected void btn_Select_OnClick(object sender, EventArgs e)
    {
        SampleDataContext ctxt = new SampleDataContext();

        div_EnterCriteria.Visible = true;
        div_DisplayData.Visible   = false;
    }
Exemplo n.º 14
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            SampleDataContext dbContext = new SampleDataContext();

            dbContext.DeleteEmployee();
            GetData();
        }
Exemplo n.º 15
0
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            SampleDataContext dbContext = new SampleDataContext();

            dbContext.InsertEmployee();
            GetData();
        }
Exemplo n.º 16
0
        static async Task Main(string[] args)
        {
            //This is for demo porpouses, use dependecy injection in a real project...
            SampleDataContext context = new SampleDataContext();

            //**************************************************************************************
            //Here you see how the same generic repo can be used for distinct entities...
            GenericRepo <Customer> customersRepo = new GenericRepo <Customer>(context);
            GenericRepo <Order>    ordersRepo    = new GenericRepo <Order>(context);
            GenericRepo <Invoice>  invoicesRepo  = new GenericRepo <Invoice>(context);
            //**************************************************************************************

            Customer customer = new Customer()
            {
                FirstName = "Jhon"
            };

            await customersRepo.AddAsync(customer);

            await customersRepo.SaveAsync();

            List <Customer> customers = new List <Customer>();

            customers = await customersRepo.GetAllAsync();

            foreach (var cust in customers)
            {
                Console.WriteLine($"Customer name: {cust.FirstName}");
            }

            Console.ReadLine();
        }
Exemplo n.º 17
0
 private void CbxClass_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (CbxClass.SelectedItem != null)
     {
         using (SampleDataContext db = new SampleDataContext())
         {
             schedule = db.HeaderSchedules.Where(s => s.ClassName == CbxClass.SelectedItem.ToString()).FirstOrDefault();
             kelas    = db.Classes.Where(c => c.ClassName == CbxClass.SelectedItem.ToString()).FirstOrDefault();
             CbxSubject.Items.Clear();
             GetSubject();
         }
         if (schedule.Finalize == 1)
         {
             va.DisableAllControls();
             CbxClass.Enabled    = true;
             CbxDay.Enabled      = true;
             DGVSchedule.Enabled = true;
         }
         else if (schedule.Finalize == 0)
         {
             va.EnableAllControls();
             BtnSave.Visible    = false;
             BtnCancel.Visible  = false;
             CbxShift.Enabled   = false;
             CbxTeacher.Enabled = false;
             CbxSubject.Enabled = false;
         }
     }
 }
 private void GetClass()
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         detail = db.DetailClasses.Where(dc => dc.StudentId == student.StudentId).FirstOrDefault();
     }
 }
 private void RefreshDGV()
 {
     if (CbxClass.SelectedItem != null)
     {
         using (SampleDataContext db = new SampleDataContext())
         {
             if (schedule != null)
             {
                 DGVSchedule.DataSource = from ds in db.DetailSchedules
                                          join hs in db.HeaderSchedules
                                          on ds.ScheduleId equals hs.ScheduleId
                                          join s in db.Subjects
                                          on ds.SubjectId equals s.SubjectId
                                          join t in db.Teachers
                                          on ds.TeacherId equals t.TeacherId
                                          where (ds.ScheduleId == schedule.ScheduleId)
                                          select new
                 {
                     s.SubjectId,
                     Subject = s.Name,
                     t.TeacherId,
                     Teacher_Name = t.Name,
                     ds.ShiftId,
                     ds.DetailId
                 };
                 DGVSchedule.Columns["DetailId"].Visible = false;
             }
         }
     }
 }
Exemplo n.º 20
0
 public ICollection <Product> GetAll()
 {
     using (var db = new SampleDataContext(_configuration))
     {
         var t = new ProductRepo(db);
         return(t.GetProduts());
     }
 }
Exemplo n.º 21
0
 private void CbxClass_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         kelas = db.Classes.Where(c => c.ClassName == CbxClass.SelectedItem.ToString()).FirstOrDefault();
         RefreshDGV();
     }
 }
Exemplo n.º 22
0
        private static void deleteItem(SampleDataContext context, int updateInput)
        {
            EntityList <SampleItem> samples = context.GetList <SampleItem>("Sample");
            var itemToDelete = (from r in context.Sample where r.Id == updateInput select r).First();

            samples.DeleteOnSubmit(itemToDelete);
            context.SubmitChanges();
        }
Exemplo n.º 23
0
        private void GetData()
        {
            SampleDataContext dbContex = new SampleDataContext();

            dbContex.Log         = Response.Output;
            GridView1.DataSource = dbContex.GetEmployee();
            GridView1.DataBind();
        }
Exemplo n.º 24
0
 private void CbxSubject_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         string subject = GlobalUse.GetFirstString(CbxSubject.SelectedItem.ToString());
         this.subject = db.Subjects.Where(s => s.SubjectId == subject).FirstOrDefault();
         ShowPercentage();
     }
 }
Exemplo n.º 25
0
 private void DeleteFromDatabase()
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         Database.Message message = db.Messages.Where(m => m.MessageId == selectedMessage.MessageId).FirstOrDefault();
         db.Messages.DeleteOnSubmit(message);
         db.SubmitChanges();
     }
 }
Exemplo n.º 26
0
 public static List <Course> FindCourseAPI(SampleDataContext context, string keyword)
 {
     return((from c in context.Courses
             where
             c.Name.Contains(keyword) ||
             c.Teacher.FirstName.Contains(keyword) ||
             c.Teacher.LastName.Contains(keyword)
             select c).ToList());
 }
Exemplo n.º 27
0
        private static void showListItems(SampleDataContext context)
        {
            //context is the site (in this case this would be the subsite, Raymond)
            var res = from r in context.Sample select r;

            foreach (var r in res)
            {
                Console.WriteLine(r.Id + ":" + r.FirstName + ":" + r.LastName);
            }
        }
Exemplo n.º 28
0
 static partial void PerformPreDeleteLogic(SampleDataContext context, Course obj)
 {
     if (obj.Enrollments != null)
     {
         foreach (DataAccess.Enrollment enrollment in obj.Enrollments)
         {
             EnrollmentLogic.DeleteEnrollment(context, enrollment.ID);
         }
     }
 }
Exemplo n.º 29
0
 public void WorksheetNameAttribute()
 {
     using (var db = new SampleDataContext())
     {
         var data    = db.Orders.OrderBy(x => x.Date).GroupBy(x => x.Date.Month);
         var package = Spreadsheet.CreatePackage(data);
         Assert.IsTrue(package.Workbook.Worksheets.Count > 1);
         Assert.IsTrue(package.Workbook.Worksheets[package.Workbook.Worksheets.Count].Name == DateTime.Now.AddDays(-1).ToString("MMMM"));
     }
 }
Exemplo n.º 30
0
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         int id = int.Parse(TextBox1.Text);
         Employee employee = dbContext.Employees.SingleOrDefault(x => x.ID == id);
         dbContext.Employees.DeleteOnSubmit(employee);
         dbContext.SubmitChanges();
     }
     GetData();
 }
Exemplo n.º 31
0
        protected void btnGetEmployeesByDepartment_Click(object sender, EventArgs e)
        {
            using (SampleDataContext dbContext = new SampleDataContext())
            {
                string deptName = string.Empty;
                GridView1.DataSource = dbContext.GetEmployeesByDepartment(DropDownList1.SelectedIndex+1, ref deptName);
                GridView1.DataBind();

                lblDept.Text = "Department Name = "  + deptName;
            }
        }
Exemplo n.º 32
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         int id = int.Parse(TextBox2.Text);
         Employee employee = dbContext.Employees.SingleOrDefault(x => x.ID == id);
         employee.Salary += employee.Salary*10/100;
         dbContext.SubmitChanges();
     }
     GetData();
 }
 private void UpdateToDatabase()
 {
     using (SampleDataContext db = new SampleDataContext())
     {
         DetailScore detail = db.DetailScores.Where(ds => ds.ScoreDetailId == score.ScoreDetailId).FirstOrDefault();
         detail.Assignment = Convert.ToInt32(TbxAssignment.Text);
         detail.MidExam    = Convert.ToInt32(TbxMidExam.Text);
         detail.FinalExam  = Convert.ToInt32(TbxFinalExam.Text);
         db.SubmitChanges();
     }
 }
Exemplo n.º 34
0
 protected void btnAddDept_Click(object sender, EventArgs e)
 {
     using (SampleDataContext dbContext = new SampleDataContext())
     {
         Department newDepartment = new Department
         {
             Name = txtDeptName.Text,
             Location = txtDeptLoc.Text
         };
         dbContext.Departments.InsertOnSubmit(newDepartment);
         dbContext.SubmitChanges();
     }
     Response.Redirect("WebForm3.aspx");
 }
Exemplo n.º 35
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            using (SampleDataContext dbContext = new SampleDataContext())
            {
                Employee newEmployee = new Employee
                {
                    FirstName = txtFirstName.Text,
                    LastName = txtLastName.Text,
                    Gender = txtGender.Text,
                    Salary = int.Parse(txtSalary.Text),
                    DepartmentId = int.Parse(txtDeptId.Text)

                };
                dbContext.Employees.InsertOnSubmit(newEmployee);
                dbContext.SubmitChanges();
            }
            Response.Redirect("WebForm2.aspx");
        }
Exemplo n.º 36
0
 private void GetData()
 {
     SampleDataContext dbContext = new SampleDataContext();
     GridView1.DataSource = dbContext.GetEmployees();
     GridView1.DataBind();
 }