Exemple #1
0
        public List <country> GetCountryList()
        {
            SampleDBEntities sd        = new SampleDBEntities();
            List <country>   countries = sd.countries.ToList();

            return(countries);
        }
Exemple #2
0
 public Employee Get(int id)
 {
     using (SampleDBEntities dbEntities = new SampleDBEntities())
     {
         return(dbEntities.Employees.FirstOrDefault(x => x.Id == id));
     }
 }
Exemple #3
0
 public UnitOfWork(SampleDBEntities context)
 {
     _context  = context;
     Products  = new ProductRepository(_context);
     Suppliers = new SupplierRepository(_context);
     Customers = new CustomerRepository(_context);
 }
Exemple #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            SampleDBEntities db = new SampleDBEntities();

            db.Products.Load();
            this.productBindingSource.DataSource = db.Products.Local.ToBindingList();
        }
 public IEnumerable <Employee> Get()
 {
     using (SampleDBEntities entities = new SampleDBEntities())
     {
         return(entities.Employees.ToList());
     }
 }
 public bool IsLoginNameExist(string loginName)
 {
     using (SampleDBEntities db = new SampleDBEntities())
     {
         return(db.SYSUsers.Where(o => o.LoginName.Equals(loginName)).Any());
     }
 }
 public Employee Get(string code)
 {
     using (SampleDBEntities entities = new SampleDBEntities())
     {
         return(entities.Employees.FirstOrDefault(e => e.code == code));
     }
 }
Exemple #8
0
        // GET: Cas
        public ActionResult Index()
        {
            SampleDBEntities sd = new SampleDBEntities();

            ViewBag.countryList = new SelectList(GetCountryList(), "cid", "cname");
            return(View());
        }
Exemple #9
0
        protected void btnNew_Click(object sender, EventArgs e)
        {
            if (btnNew.Text == "New")
            {
                btnNew.CausesValidation = true;
                btnNew.Text             = "Save";
                panel1.Visible          = true;
            }
            else
            {
                btnNew.CausesValidation = false;
                btnNew.Text             = "New";

                using (SampleDBEntities entity = new SampleDBEntities())
                {
                    Customer customer = new Customer();
                    customer.CompanyName  = txtCompanyName.Text.Trim();
                    customer.ContactName  = txtContactName.Text.Trim();
                    customer.ContactTitle = txtContactTitle.Text.Trim();
                    customer.Address      = txtAddress.Text.Trim();
                    entity.Customers.Add(customer);
                    entity.SaveChanges();
                }

                panel1.Visible = false;

                GridView1.DataBind();

                txtAddress.Text      = "";
                txtCompanyName.Text  = "";
                txtContactName.Text  = "";
                txtContactTitle.Text = "";
            }
        }
Exemple #10
0
        public ActionResult uploadjson(HttpPostedFileBase filejson)
        {
            SampleDBEntities sd = new SampleDBEntities();

            {
                if (!filejson.FileName.EndsWith(".json"))
                {
                    ViewBag.errmsg = "Only JSON Type Files Allowed";
                }
                else
                {
                    filejson.SaveAs(Server.MapPath("~/empfolder/" + Path.GetFileName(filejson.FileName)));
                    StreamReader       reader   = new StreamReader(Server.MapPath("~/empfolder/" + Path.GetFileName(filejson.FileName)));
                    string             jsondata = reader.ReadToEnd();
                    List <empjsondata> emplist  = JsonConvert.DeserializeObject <List <empjsondata> >(jsondata);
                    foreach (var item in emplist)
                    {
                        @item.email.ToString();
                        @item.EmpName.ToString();
                        @item.salary.ToString();
                        sd.empjsondatas.Add(item);
                        sd.SaveChanges();
                    }
                    ViewBag.message = "Selected" + Path.GetFileName(filejson.FileName) + "File  Is Saved Successfully !";
                }
            }
            return(View("Index"));
        }
        public ActionResult LoadData()
        {
            var draw     = Request.Form.GetValues("draw").FirstOrDefault();
            var start    = Request.Form.GetValues("start").FirstOrDefault();
            var length   = Request.Form.GetValues("length").FirstOrDefault();
            int pageSize = length != null?Convert.ToInt32(length) : 0;

            int skip = start != null?Convert.ToInt32(start) : 0;

            var sortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
            int totalRecords  = 0;

            using (SampleDBEntities sample = new SampleDBEntities())
            {
                var v = (from a in sample.SampleCustomers select a);
                if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
                {
                    v = v.OrderBy(sortColumn + " " + sortColumnDir);
                }
                totalRecords = v.Count();
                var data = v.Skip(skip).Take(pageSize).ToList();
                return(Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }));
            }
        }
Exemple #12
0
        public ActionResult GetCityList(int Sid)
        {
            SampleDBEntities sd         = new SampleDBEntities();
            List <city>      selectList = sd.cities.Where(x => x.sid == Sid).ToList();

            ViewBag.Citylist = new SelectList(selectList, "Cityid", "Cityname");
            return(PartialView("DisplayCities"));
        }
Exemple #13
0
        public ActionResult GetStateList(int Cid)
        {
            SampleDBEntities sd         = new SampleDBEntities();
            List <state>     selectList = sd.states.Where(x => x.cid == Cid).ToList();

            ViewBag.Slist = new SelectList(selectList, "Sid", "Sname");
            return(PartialView("DisplayStatess"));
        }
 /// <summary>
 /// Get Employee With Id
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public JsonResult GetCustomers(string Id)
 {
     using (SampleDBEntities Obj = new SampleDBEntities())
     {
         int EmpId = int.Parse(Id);
         return(Json(Obj.Customers.Find(EmpId), JsonRequestBehavior.AllowGet));
     }
 }
 /// <summary>
 ///
 /// Get All Employee
 /// </summary>
 /// <returns></returns>
 public JsonResult GetAllCustomers()
 {
     using (SampleDBEntities Obj = new SampleDBEntities())
     {
         List <Customer> Emp = Obj.Customers.ToList();
         return(Json(Emp, JsonRequestBehavior.AllowGet));
     }
 }
 public JsonResult getAll()
 {
     using (SampleDBEntities dataContext = new SampleDBEntities())
     {
         var employeeList = dataContext.AngmvcModels.ToList();
         return(Json(employeeList, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #17
0
 public void delete(int id)
 {
     using (var ctx = new SampleDBEntities())
     {
         var emp = ctx.Employees.Where(s => s.ID == id).FirstOrDefault();
         ctx.Entry(emp).State = System.Data.Entity.EntityState.Deleted;
         ctx.SaveChanges();
     }
 }
 public JsonResult getEmployeeByNo(string EmpNo)
 {
     using (SampleDBEntities dataContext = new SampleDBEntities())
     {
         int no           = Convert.ToInt32(EmpNo);
         var employeeList = dataContext.AngmvcModels.Find(no);
         return(Json(employeeList, JsonRequestBehavior.AllowGet));
     }
 }
 private void EmpAdd(SampleDBEntities ctx, EmployeeModel emp)
 {
     ctx.Employees.Add(new Employee()
     {
         Name       = emp.name,
         Department = emp.department,
         Salary     = emp.salary
     });
     ctx.SaveChanges();
 }
        private void EmpEdit(SampleDBEntities ctx, EmployeeModel emp)
        {
            var existingEmp = ctx.Employees.Where(s => s.ID == emp.id).FirstOrDefault <Employee>();

            if (existingEmp != null)
            {
                existingEmp.Name       = emp.name;
                existingEmp.Department = emp.department;
                existingEmp.Salary     = emp.salary;

                ctx.SaveChanges();
            }
        }
 public void AddOrEdit(EmployeeModel emp)
 {
     using (var ctx = new SampleDBEntities())
     {
         if (emp.id.ToString() != "0")
         {
             EmpEdit(ctx, emp);
         }
         else
         {
             EmpAdd(ctx, emp);
         }
     }
 }
Exemple #22
0
 public IList <EmployeeModel> getAllEmployees()
 {
     using (var ctx = new SampleDBEntities())
     {
         emp = ctx.Employees.Select(s => new EmployeeModel()
         {
             id         = s.ID,
             name       = s.Name,
             department = s.Department,
             salary     = s.Salary
         }).ToList <EmployeeModel>();
     }
     return(emp);
 }
 public string GetUserPassword(string loginName)
 {
     using (SampleDBEntities db = new SampleDBEntities())
     {
         var user = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName));
         if (user.Any())
         {
             return(user.FirstOrDefault().PasswordEncryptedText);
         }
         else
         {
             return(string.Empty);
         }
     }
 }
 public string AddEmployee(Employee Emp)
 {
     if (Emp != null)
     {
         using (SampleDBEntities dataContext = new SampleDBEntities())
         {
             dataContext.Employees.Add(Emp);
             dataContext.SaveChanges();
             return("Employee Updated");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
 /// <summary>
 /// Insert New Employee
 /// </summary>
 /// <param name="Employe"></param>
 /// <returns></returns>
 public string InsertCustomers(Customer Customer)
 {
     if (Customer != null)
     {
         using (SampleDBEntities Obj = new SampleDBEntities())
         {
             Obj.Customers.Add(Customer);
             Obj.SaveChanges();
             return("Employee Added Successfully");
         }
     }
     else
     {
         return("Employee Not Inserted! Try Again");
     }
 }
Exemple #26
0
        public IList <EmployeeModel> getEmployeeById(int id)
        {
            IList <EmployeeModel> emp = null;

            using (var ctx = new SampleDBEntities())
            {
                emp = ctx.Employees.Where(x => x.ID == id).Select(s => new EmployeeModel()
                {
                    id         = s.ID,
                    name       = s.Name,
                    department = s.Department,
                    salary     = s.Salary
                }).ToList <EmployeeModel>();
            }
            return(emp);
        }
        public void AddUserAccount(UserSignUpView user)
        {
            using (SampleDBEntities db = new SampleDBEntities())
            {
                SYSUser SU = new SYSUser();
                SU.LoginName             = user.LoginName;
                SU.PasswordEncryptedText = user.Password;
                SU.RowCreatedSYSUserID   = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SU.RowModifiedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1;;
                SU.RowCreatedDateTime    = DateTime.Now;
                SU.RowMOdifiedDateTime   = DateTime.Now;

                db.SYSUsers.Add(SU);
                db.SaveChanges();

                SYSUserProfile SUP = new SYSUserProfile();
                SUP.SYSUserID            = SU.SYSUserID;
                SUP.FirstName            = user.FirstName;
                SUP.LastName             = user.LastName;
                SUP.Gender               = user.Gender;
                SUP.RowCreatedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SUP.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SUP.RowCreatedDateTime   = DateTime.Now;
                SUP.RowModifiedDateTime  = DateTime.Now;

                db.SYSUserProfiles.Add(SUP);
                db.SaveChanges();


                if (user.LOOKUPRoleID > 0)
                {
                    SYSUserRole SUR = new SYSUserRole();
                    SUR.LOOKUPRoleID         = user.LOOKUPRoleID;
                    SUR.SYSUserID            = user.SYSUserID;
                    SUR.IsActive             = true;
                    SUR.RowCreatedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1;
                    SUR.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                    SUR.RowCreatedDateTime   = DateTime.Now;
                    SUR.RowModifiedDateTime  = DateTime.Now;

                    db.SYSUserRoles.Add(SUR);
                    db.SaveChanges();
                }
            }
        }
Exemple #28
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool authorize = false;

            using (SampleDBEntities db = new SampleDBEntities())
            {
                UserManager UM = new UserManager();
                foreach (var roles in userAssignedRoles)
                {
                    authorize = UM.IsUserInRole(httpContext.User.Identity.Name, roles);
                    if (authorize)
                    {
                        return(authorize);
                    }
                }
            }
            return(authorize);
        }
        public ActionResult Login(User user, string ReturnUrl)
        {
            SampleDBEntities DbContext = new SampleDBEntities();
            User             data      = DbContext.Users.FirstOrDefault(x => x.userName == user.userName && x.password == user.password);

            if (data != null)
            {
                FormsAuthentication.SetAuthCookie(user.userName, true);
                return(RedirectToAction("Index", "Home"));

                // return Redirect(ReturnUrl);
            }
            else
            {
                ModelState.AddModelError("password", "please enter correct user name or password");
                return(View(user));
            }
        }
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     //Validations code here
     //...............
     //To save in database
     using (var context = new SampleDBEntities()){
         context.PlaceInfoes.Add(new PlaceInfo()
         {
             Name        = txtName.Text,
             Address     = txtAddress.Text,
             City        = txtCity.Text,
             State       = txtState.Text,
             CountryId   = Convert.ToInt32(ddlCountry.SelectedValue),
             Geolocation = DbGeography.FromText("POINT( " + hdnLocation.Value + ")")
         });
         context.SaveChanges();
     }
 }
    /// <summary>
    /// To add random data in database for testing
    /// </summary>
    void GenerateData()
    {
        Random random = new Random();
        double lat = 25.3294781, lng = 55.373236899999995;
        using (var context = new SampleDBEntities())
        {

            for (int i = 1; i < 100; i++)
            {
                context.PlaceInfoes.Add(new PlaceInfo()
                {
                    Name = "Sample" + i,
                    Address = "address" + i,
                    City = "test city",
                    State = "test state",
                    CountryId = Convert.ToInt32(ddlCountry.SelectedValue),
                    Geolocation = DbGeography.FromText("POINT( " + (lng + random.NextDouble() * 1.55).ToString() + " " + (lat + random.NextDouble()).ToString() + ")")
                });
            }
            context.SaveChanges();
        }
    }
 public override string[] GetRolesForUser(string username)
 {
     using (SampleDBEntities objContext = new SampleDBEntities())
     {
         var objUser = objContext.Users.FirstOrDefault(x => x.AppUserName == username);
         if (objUser == null)
         {
             return null;
         }
         else
         {
             string[] ret = objUser.Roles.Select(x => x.RoleName).ToArray();
             return ret;
         }
     }
 }
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     //Validations code here
     //...............
     //To save in database
     using ( var context = new SampleDBEntities()){
         context.PlaceInfoes.Add (new PlaceInfo() {
         Name = txtName.Text,
         Address = txtAddress.Text,
         City = txtCity.Text,
         State = txtState.Text,
         CountryId = Convert.ToInt32 (ddlCountry.SelectedValue),
         Geolocation = DbGeography.FromText("POINT( " + hdnLocation.Value + ")")
         });
         context.SaveChanges();
     }
 }