public static void saveEmployeeTrainingHistory(DataTable dt, ref EmployeeTrainingHistory mo)
 {
     foreach (DataRow dr in dt.Rows)
     {
         saveEmployeeTrainingHistory(dr, ref mo);
     }
 }
        public override IDbCommand getUpdateDBCommand(IModelObject modelObj, string sql)
        {
            EmployeeTrainingHistory obj = (EmployeeTrainingHistory)modelObj;
            IDbCommand stmt             = this.dbConn.getCommand(sql);

            stmt.Parameters.Add(this.dbConn.getParameter(EmployeeTrainingHistory.STR_FLD_EMPLOYEE_ID, obj.PrEmployeeId));
            stmt.Parameters.Add(this.dbConn.getParameter(EmployeeTrainingHistory.STR_FLD_DATE_FROM, obj.PrDateFrom));
            stmt.Parameters.Add(this.dbConn.getParameter(EmployeeTrainingHistory.STR_FLD_DATE_TO, obj.PrDateTo));
            stmt.Parameters.Add(this.dbConn.getParameter(EmployeeTrainingHistory.STR_FLD_TRAINING_COURSE_CODE, obj.PrTrainingCourseCode));

            if (obj.isNew)
            {
                IDataParameter prm = this.dbConn.getParameterInOut(EmployeeTrainingHistory.STR_FLD_EMPLOYEE_TRAINING_HISTORY_ID);
                prm.DbType    = DbType.Int64;
                prm.Direction = ParameterDirection.Output;
                stmt.Parameters.Add(prm);
            }
            else
            {
                //only add primary key if we are updating and as the last parameter
                stmt.Parameters.Add(this.dbConn.getParameter(EmployeeTrainingHistory.STR_FLD_EMPLOYEE_TRAINING_HISTORY_ID, obj.PrEmployeeTrainingHistoryId));
            }

            return(stmt);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeTrainingHistory employeetraininghistory = db.EmployeeTrainingHistories.Find(id);

            db.EmployeeTrainingHistories.Remove(employeetraininghistory);
            db.SaveChanges();
            return(RedirectToAction("ViewTrainingHistory"));
        }
        /// <summary>
        /// Reload the EmployeeTrainingHistory from the database
        /// </summary>
        /// <remarks>
        /// use this method when you want to relad the EmployeeTrainingHistory
        /// from the database, discarding any changes
        /// </remarks>
        public static void reload(ref EmployeeTrainingHistory mo)
        {
            if (mo == null)
            {
                throw new System.ArgumentNullException("null object past to reload function");
            }

            mo = (EmployeeTrainingHistory) new EmployeeTrainingHistoryDBMapper().findByKey(mo.Id);
        }
        public static EmployeeTrainingHistory loadFromDataRow(DataRow r)
        {
            DataRowLoader a  = new DataRowLoader();
            IModelObject  mo = new EmployeeTrainingHistory();

            a.DataSource = r;
            a.load(mo);
            return((EmployeeTrainingHistory)mo);
        }
 public ActionResult EditTrainingHistory([Bind(Include = "Id,EmployeeId,TrainingTitle,TrainingTopic,TrainingInstitute,IstituteLocation,InstituteCountry,TrainingYear,TrainingDuration")] EmployeeTrainingHistory employeetraininghistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeetraininghistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("ViewTrainingHistory"));
     }
     ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeetraininghistory.EmployeeId);
     return(View(employeetraininghistory));
 }
        public override void saveParents(IModelObject mo)
        {
            EmployeeTrainingHistory thisMo = ( EmployeeTrainingHistory)mo;

            //**** Parent Association:trainingcourse
            if ((thisMo.PrTrainingCourse != null) && (thisMo.PrTrainingCourse.NeedsSave))
            {
                OracleMappers.TrainingCourseDBMapper mappervar = new OracleMappers.TrainingCourseDBMapper(this.dbConn);
                mappervar.save(thisMo.PrTrainingCourse);
                thisMo.PrTrainingCourseCode = thisMo.PrTrainingCourse.PrCODE;
            }
        }
        public static void saveEmployeeTrainingHistory(DataRow dr, ref EmployeeTrainingHistory mo)
        {
            if (mo == null)
            {
                mo = new EmployeeTrainingHistory();
            }

            foreach (DataColumn dc in dr.Table.Columns)
            {
                mo.setAttribute(dc.ColumnName, dr[dc.ColumnName]);
            }

            saveEmployeeTrainingHistory(mo);
        }
        // GET: /EmployeeTrainingHistory/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeTrainingHistory employeetraininghistory = db.EmployeeTrainingHistories.Find(id);

            if (employeetraininghistory == null)
            {
                return(HttpNotFound());
            }
            return(View(employeetraininghistory));
        }
        // GET: /EmployeeTrainingHistory/Edit/5
        public ActionResult EditTrainingHistory(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeTrainingHistory employeetraininghistory = db.EmployeeTrainingHistories.Find(id);

            if (employeetraininghistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeetraininghistory.EmployeeId);
            return(View(employeetraininghistory));
        }
        public override void load(IModelObject mo)
        {
            const int DATAREADER_FLD_EMPLOYEE_TRAINING_HISTORY_ID = 0;
            const int DATAREADER_FLD_EMPLOYEE_ID          = 1;
            const int DATAREADER_FLD_DATE_FROM            = 2;
            const int DATAREADER_FLD_DATE_TO              = 3;
            const int DATAREADER_FLD_TRAINING_COURSE_CODE = 4;

            EmployeeTrainingHistory obj = (EmployeeTrainingHistory)mo;

            obj.IsObjectLoading = true;

            if (!this.reader.IsDBNull(DATAREADER_FLD_EMPLOYEE_TRAINING_HISTORY_ID))
            {
                obj.PrEmployeeTrainingHistoryId = Convert.ToInt64(this.reader.GetDecimal(DATAREADER_FLD_EMPLOYEE_TRAINING_HISTORY_ID));
            }
            if (!this.reader.IsDBNull(DATAREADER_FLD_EMPLOYEE_ID))
            {
                obj.PrEmployeeId = Convert.ToInt64(this.reader.GetDecimal(DATAREADER_FLD_EMPLOYEE_ID));
            }
            if (!this.reader.IsDBNull(DATAREADER_FLD_DATE_FROM))
            {
                obj.PrDateFrom = this.reader.GetDateTime(DATAREADER_FLD_DATE_FROM);
            }
            if (!this.reader.IsDBNull(DATAREADER_FLD_DATE_TO))
            {
                obj.PrDateTo = this.reader.GetDateTime(DATAREADER_FLD_DATE_TO);
            }
            if (!this.reader.IsDBNull(DATAREADER_FLD_TRAINING_COURSE_CODE))
            {
                obj.PrTrainingCourseCode = this.reader.GetString(DATAREADER_FLD_TRAINING_COURSE_CODE);
            }


            obj.isNew = false;
            // since we've just loaded from database, we mark as "old"
            obj.isDirty         = false;
            obj.IsObjectLoading = false;
            obj.afterLoad();

            return;
        }
        public void createOracletestRecords()
        {
            ModelContext.Current.config.DoCascadeDeletes = true;
            ModelContext.beginTrans();
            ModelContext.Current.addGlobalModelValidator(typeof(Employee), typeof(EmployeeValidator));

            try {
                Employee e = EmployeeFactory.Create();
                e.PrDepartment = DepartmentFactory.Create();
                e.PrDepartment.PrDepartmentName = "My New Dept";
                e.PrDepartment.PrLocationId     = LocationDataUtils.findList()[0].PrLocationId;

                e.PrFirstName   = "test";
                e.PrLastName    = "Lastname";
                e.PrSALARY      = 100m;
                e.PrEMAIL       = "*****@*****.**";
                e.PrPhoneNumber = "1030045";
                e.PrHireDate    = new DateTime(DateTime.Now.Year, 1, 1);
                e.PrJobId       = JobDataUtils.findList()[0].PrJobId;

                e.PrTrainingHistoryAdd(EmployeeTrainingHistoryFactory.Create());
                EmployeeTrainingHistory emplProj = e.PrTrainingHistoryGetAt(0);
                emplProj.PrDateFrom = new DateTime(DateTime.Now.Year, 3, 1);
                emplProj.PrDateTo   = new DateTime(DateTime.Now.Year, 6, 1);

                emplProj.PrTrainingCourse           = TrainingCourseFactory.Create();
                emplProj.PrTrainingCourse.PrCODE    = "X1";
                emplProj.PrTrainingCourse.PrDescrEn = "New Course";
                emplProj.PrTrainingCourse.PrDescrGr = "Νέο";
                Assert.IsTrue(e.isNew);
                Assert.IsTrue(e.isDirty);
                Assert.IsTrue(e.NeedsSave);

                // 3 ways to persist to database
                // method 1: use ModelContext.Current().save

                Assert.IsTrue(e.CreateDate == null, "Before save, created date is null");
                Assert.IsTrue(e.UpdateDate == null, "Before save, UpdateDate is not null");
                ModelContext.Current.saveModelObject(e);
                Assert.IsTrue(e.PrPhoneNumber == "12345XX", "12345XX value in PrPhoneNumber is Proof that validator was called");
                Assert.IsTrue(e.CreateDate != null, "Before save, created date is not null");
                Assert.IsTrue(e.UpdateDate != null, "Before save, UpdateDate is not null");
                Assert.IsTrue(e.CreateUser != null, "Before save, CreateUser date is not null");
                Assert.IsTrue(e.UpdateUser != null, "Before save, UpdateUser is not null");
                //Assert.IsTrue(e.UpdateDate.Value.Ticks == e.CreateDate.Value.Ticks, "update date = create date after saving new");
                Assert.IsTrue(e.UpdateUser == e.CreateUser, "update date = create date after saving new");

                long x = e.PrEmployeeId;
                Assert.IsFalse(e.isNew, "After save, model object isNew property must return false");
                Assert.IsFalse(e.isDirty, "After save to db, model object isDirty property must return false");

                e = EmployeeDataUtils.findByKey(x);

                Assert.IsNotNull(e, "New employee not found");

                Assert.IsFalse(e.isNew, "After load from db, model object isNew property returns false");
                Assert.IsFalse(e.isDirty, "After load from db, model object isDirty property returns false");

                Assert.AreEqual(e.PrDepartment.PrDepartmentName, "My New Dept");
                Assert.AreEqual(e.PrSALARY, 100m);
                Assert.AreEqual(e.PrLastName, "Lastname");
                Assert.AreEqual(e.PrPhoneNumber, "12345XX");
                Assert.AreEqual(e.PrHireDate, new DateTime(2015, 1, 1));
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 1);
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course");

                //change some values on child and parent objects
                e.PrTrainingHistoryGetAt(0).PrDateTo = new DateTime(DateTime.Now.Year, 6, 1);
                e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn = "New Course Updated"; // here we are updating parent record of child object of employee!
                Assert.IsTrue(e.NeedsSave, "After changing parent or child obejcts values, e.NeedsSave must be true");
                Assert.IsFalse(e.isDirty, "After changing parent or child obejcts values, e.isDirty must be false since we did not change anything on the Model Object");

                // method 2: call [ModelObject]DataUtils.save
                EmployeeDataUtils.saveEmployee(e);
                //Assert.IsTrue(e.UpdateDate > e.CreateDate, "after update of record, update must be date > create date ");
                // note that above test cannot be sucess since save is happening too fast

                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrDateTo, new DateTime(DateTime.Now.Year, 6, 1));
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course Updated", "Expected to have parent record of child updated!");

                e.PrPhoneNumber = "XXXXX";
                Assert.IsTrue(e.NeedsSave, "After changing value, e.NeedsSave must be true");
                Assert.IsTrue(e.isDirty, "After changing value e.isDirty must be true");

                // method 3: call [ModelObject]dbMapper.save
                new EmployeeDBMapper().saveEmployee(e);
                e = EmployeeDataUtils.findByKey(x);
                Assert.AreEqual(e.PrPhoneNumber, "XXXXX");
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrDateTo, new DateTime(DateTime.Now.Year, 6, 1));
                Assert.AreEqual(e.PrTrainingHistoryGetAt(0).PrTrainingCourse.PrDescrEn, "New Course Updated", "Expected to have parent record of child updated!");

                e.PrTrainingHistoryClear();
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 0, "Expected to have no Projects linked after call to clear");
                EmployeeDataUtils.saveEmployee(e);

                e = EmployeeDataUtils.findByKey(x);
                Assert.AreEqual(e.PrTrainingHistory.ToList().Count, 0, "Expected to have no Projects linked, after reloading from db");

                EmployeeDataUtils.deleteEmployee(e);
                e = EmployeeDataUtils.findByKey(x);
                Assert.IsNull(e, "New employee must have been deleted!");

                // now let's test string primary key
                Country et = CountryFactory.Create();
                et.PrCountryName = "A Description";
                et.PrCountryId   = "XX";

                Country et1 = CountryFactory.Create();
                et1.PrCountryName = "A Description 1";
                et1.PrCountryId   = "Y7";

                Country et2 = CountryFactory.Create();
                et2.PrCountryName = "A Description 2";
                et2.PrCountryId   = "H8";

                CountryDataUtils.saveCountry(et, et1, et2);

                et2 = CountryDataUtils.findByKey("H8");
                Assert.IsNotNull(et2, "New Country must have been created!");
                et1 = CountryDataUtils.findByKey("Y7");
                Assert.IsNotNull(et1, "New Country must have been created!");
            } finally {
                ModelContext.rollbackTrans();
            }
        }
 public static EmployeeTrainingHistory loadFromDataRow(DataRow r)
 {
     DataRowLoader a = new DataRowLoader();
     IModelObject mo = new EmployeeTrainingHistory();
     a.DataSource = r;
     a.load(mo);
     return (EmployeeTrainingHistory)mo;
 }
Beispiel #14
0
    [TestMethod()] public void TestLoadAndSaveEmployeeTrainingHistory()
    {
        ModelContext.beginTrans();
        try {
            OracleMappers.EmployeeTrainingHistoryDBMapper pdb = new OracleMappers.EmployeeTrainingHistoryDBMapper();

            long count = pdb.RecordCount();

            if (pdb.SelectFromObjectName != pdb.ManagedTableName)
            {
                long countFromSelectObject = pdb.dbConn.getLngValue("select count(*) from " + pdb.SelectFromObjectName);
                Assert.AreEqual(count, countFromSelectObject,
                                "Count of records in managedTableName {0} and SelectFromObjectName {1} should be equal, as there needs to be exactly 1 to 1 match between records in managed table and selectFromObject.",
                                pdb.ManagedTableName, pdb.SelectFromObjectName);
            }

            if (count == 0)
            {
                Assert.Inconclusive("No EmployeeTrainingHistory in database, table is empty");
            }
            else
            {
                /**
                 * using (DataContext ctx = DBUtils.Current().dbContext()) {
                 *
                 *      var query = ctx.ExecuteQuery<EmployeeTrainingHistory>(@"SELECT * FROM " + pdb.SelectFromObjectName ).Skip(1).Take(1);
                 *      var lst = query.ToList();
                 *
                 *      Assert.AreEqual(lst.Count, 1, "Expected to receive 1 record, got: " + lst.Count);
                 *
                 * }
                 * todo: fix boolean fields by generating properties of original fields
                 **/
                object pid = ModelContext.CurrentDBUtils.getObjectValue("select top 1 " + pdb.pkFieldName + " from " + pdb.ManagedTableName);

                EmployeeTrainingHistory p  = pdb.findByKey(pid);
                EmployeeTrainingHistory p2 = (EmployeeTrainingHistory)p.copy();

                //Test equality and hash codes
                Assert.AreEqual(p.GetHashCode(), p2.GetHashCode());
                Assert.AreEqual(p, p2);

                p.isDirty = true;                  // force save
                pdb.save(p);

                // now reload object from database
                p = null;
                p = pdb.findByKey(pid);

                //test fields to be equal before and after save
                Assert.IsTrue(p.PrEmployeeTrainingHistoryId == p2.PrEmployeeTrainingHistoryId, "Expected Field EmployeeTrainingHistoryId to be equal");
                Assert.IsTrue(p.PrEmployeeId.GetValueOrDefault() == p2.PrEmployeeId.GetValueOrDefault(), "Expected Field EmployeeId to be equal");
                Assert.IsTrue(p.PrDateFrom.GetValueOrDefault() == p2.PrDateFrom.GetValueOrDefault(), "Expected Field DateFrom to be equal");
                Assert.IsTrue(p.PrDateTo.GetValueOrDefault() == p2.PrDateTo.GetValueOrDefault(), "Expected Field DateTo to be equal");
                Assert.IsTrue(p.PrTrainingCourseCode == p2.PrTrainingCourseCode, "Expected Field TrainingCourseCode to be equal");



                p.isDirty = true;                 //to force save
                ModelContext.Current.saveModelObject(p);

                p = ModelContext.Current.loadModelObject <EmployeeTrainingHistory>(p.Id);
                p.loadObjectHierarchy();

                string json = JsonConvert.SerializeObject(p, Formatting.Indented,
                                                          new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                System.IO.FileInfo jf = new System.IO.FileInfo(".\\EmployeeTrainingHistory.json");
                System.IO.File.WriteAllText(jf.FullName, json);

                if (pdb.isPrimaryKeyAutogenerated)
                {
                    p.isNew   = true;
                    p.isDirty = true;

                    try {
                        pdb.save(p);
                    } catch (System.Exception e) {
                        Assert.IsTrue(e.Message.ToUpper().Contains("UNIQUE INDEX") || e.Message.Contains("Violation of UNIQUE KEY constraint"),
                                      "Insert statement produced error other than violation of unique key:" + e.Message);
                    }
                }
            }
        } finally {
            ModelContext.rollbackTrans(); // 'Nothing should be saved to the database!
        }
    }
 public void saveEmployeeTrainingHistory(EmployeeTrainingHistory mo)
 {
     base.save(mo);
 }
        /// <summary>
        /// Reload the EmployeeTrainingHistory from the database
        /// </summary>
        /// <remarks>
        /// use this method when you want to relad the EmployeeTrainingHistory 
        /// from the database, discarding any changes
        /// </remarks>
        public static void reload(ref EmployeeTrainingHistory mo)
        {
            if (mo == null) {
                throw new System.ArgumentNullException("null object past to reload function");
            }

            mo = (EmployeeTrainingHistory)new EmployeeTrainingHistoryDBMapper().findByKey(mo.Id);
        }
        public static void saveEmployeeTrainingHistory(DataRow dr, ref EmployeeTrainingHistory mo)
        {
            if (mo == null) {
                mo = new EmployeeTrainingHistory();
            }

            foreach (DataColumn dc in dr.Table.Columns) {
                mo.setAttribute(dc.ColumnName, dr[dc.ColumnName]);
            }

            saveEmployeeTrainingHistory(mo);
        }
 public static void saveEmployeeTrainingHistory(DataTable dt, ref EmployeeTrainingHistory mo)
 {
     foreach (DataRow dr in dt.Rows) {
         saveEmployeeTrainingHistory(dr, ref mo);
     }
 }
 public void saveEmployeeTrainingHistory(EmployeeTrainingHistory mo)
 {
     base.save(mo);
 }
        public static void deleteEmployeeTrainingHistory(EmployeeTrainingHistory EmployeeTrainingHistoryObj)
        {
            EmployeeTrainingHistoryDBMapper dbm = new EmployeeTrainingHistoryDBMapper();

            dbm.delete(EmployeeTrainingHistoryObj);
        }
 public static void deleteEmployeeTrainingHistory(EmployeeTrainingHistory EmployeeTrainingHistoryObj)
 {
     EmployeeTrainingHistoryDBMapper dbm = new EmployeeTrainingHistoryDBMapper();
     dbm.delete(EmployeeTrainingHistoryObj);
 }