예제 #1
0
 //  Method Name: Create
 //      Purpose: Add an Employee document to the employees collection
 //      Accepts: An employee object
 //      Returns: A string
 public string Create(Employee emp)
 {
     string newid = "";
     try
     {
         DbContext ctx = new DbContext();
         ctx.Save(emp, "employees");
         newid = emp._id.ToString();
     }
     catch(Exception e)
     {
         DALUtils.ErrorRoutine(e, "EmployeeDAO", "Create");
     }
     return newid;
 }
 public void Create()
 {
     try
     {
         Employee emp = new Employee();
         emp.DepartmentId = new ObjectId(DepartmentId);
         emp.Title = Title;
         emp.Firstname = Firstname;
         emp.Lastname = Lastname;
         emp.Phoneno = Phoneno;
         emp.Email = Email;
         Id = _dao.Create(emp);
     } catch (Exception ex)
     {
         ErrorRoutine(ex, "EmployeeViewModel", "Create");
     }
 }
예제 #3
0
        public void EmployeeDAOCreateAndDeleteShouldReturnTrue()
        {
            bool deleteOK = false;
            Employee emp = new Employee();
            EmployeeDAO dao = new EmployeeDAO();

            emp.DepartmentId = new ObjectId("56201441f748f20bb0a36148"); // Sales ID
            emp.Email = "*****@*****.**";
            emp.Firstname = "Some";
            emp.Lastname = "Employee";
            emp.Phoneno = "(555)555-5555";
            emp.Title = "Mr.";
            string newid = dao.Create(emp);

            if (newid.Length == 24)
                deleteOK = dao.Delete(newid);

            Assert.IsTrue(deleteOK);
        }
예제 #4
0
        public int Update(Employee emp)
        {
            int update = -1;
            try
            {
                DbContext ctx = new DbContext();
                ctx.Save<Employee>(emp, "employees");
                update = 1;
            }
            catch (MongoConcurrencyException ex)
            {
                update = -2;
            }
            catch (Exception ex)
            {
                DALUtils.ErrorRoutine(ex, "EmployeeDAO", "Update:Error");
            }

            return update;
        }
예제 #5
0
 //  Method Name: Update
 //      Purpose: Updates an Employee in the MongoDatabase, and checks for concurrency
 //      Accepts: An Employee Object
 //      Returns: An int
 public int Update(Employee emp)
 {
     int updateOk = -1;
     try
     {
         DbContext ctx = new DbContext();
         ctx.Save<Employee>(emp, "employees");
         updateOk = 1;
     }
     catch(MongoConcurrencyException e)
     {
         updateOk = -2;
         // DALUtils.ErrorRoutine(e, "EmployeeDAO", "Update");
         Console.WriteLine(e.Message);
     }
     catch(Exception e)
     {
         DALUtils.ErrorRoutine(e, "EmployeeDAO", "Update");
     }
     return updateOk;
 }
예제 #6
0
 private void InsertEmployee(string title,
                            string first,
                            string last,
                            string phone,
                            string email,
                            string dept)
 {
     Employee emp = new Employee();
     emp.Title = title;
     emp.Firstname = first;
     emp.Lastname = last;
     emp.Phoneno = phone;
     emp.Email = email;
     Department dep = ctx.Departments.AsQueryable<Department>().FirstOrDefault(d => d.DepartmentName == dept);
     emp.DepartmentId = dep._id;
     ctx.Save<Employee>(emp, "employees");
 }