예제 #1
0
        public override void load(IModelObject mo)
        {
            const int DATAREADER_FLD_RANKID = 0;
            const int DATAREADER_FLD_RANK   = 1;

            EmployeeRank obj = (EmployeeRank)mo;

            obj.IsObjectLoading = true;

            if (!this.reader.IsDBNull(DATAREADER_FLD_RANKID))
            {
                obj.PrRankId = Convert.ToInt64(this.reader.GetInt32(DATAREADER_FLD_RANKID));
            }
            if (!this.reader.IsDBNull(DATAREADER_FLD_RANK))
            {
                obj.PrRank = this.reader.GetString(DATAREADER_FLD_RANK);
            }


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

            return;
        }
예제 #2
0
 public static void saveEmployeeRank(DataTable dt, ref EmployeeRank mo)
 {
     foreach (DataRow dr in dt.Rows)
     {
         saveEmployeeRank(dr, ref mo);
     }
 }
예제 #3
0
        public HttpResponseMessage SaveEmployeeRank(EmployeeRank employeeRank)
        {
            var aEmloyeeRank = new EmployeeRank();

            if (employeeRank == null)
            {
                //ViewBag.Message = "This Employee RankName already Exist";
                //throw new HttpResponseException(HttpStatusCode.c);
                //return msg;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "This is Empty");
                return(response);
            }
            if (aEmloyeeRank.CheckRankNameExistInDb(employeeRank.RankName) == true)
            {
                //ViewBag.Message = "This Employee RankName already Exist";
                //throw new HttpResponseException(HttpStatusCode.c);
                //return msg;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "This RankName already Exist");
                return(response);
            }
            else
            {
                _context.EmployeeRanks.Add((employeeRank));
                _context.SaveChanges();
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "Saved information successfully");
                return(response);
            }
        }
예제 #4
0
        /// <summary>
        /// Reload the EmployeeRank from the database
        /// </summary>
        /// <remarks>
        /// use this method when you want to relad the EmployeeRank
        /// from the database, discarding any changes
        /// </remarks>
        public static void reload(ref EmployeeRank mo)
        {
            if (mo == null)
            {
                throw new System.ArgumentNullException("null object past to reload function");
            }

            mo = (EmployeeRank) new EmployeeRankDBMapper().findByKey(mo.Id);
        }
예제 #5
0
        public static EmployeeRank loadFromDataRow(DataRow r)
        {
            DataRowLoader a  = new DataRowLoader();
            IModelObject  mo = new EmployeeRank();

            a.DataSource = r;
            a.load(mo);
            return((EmployeeRank)mo);
        }
예제 #6
0
 public Employee(int id, string firstName, string secondName, string role,
                 Department department, EmployeeRank rank)
 {
     this.Id         = id;
     this.FirstName  = firstName;
     this.SecondName = secondName;
     this.Role       = role;
     this.department = department;
     this.rank       = rank;
 }
예제 #7
0
        public static void saveEmployeeRank(DataRow dr, ref EmployeeRank mo)
        {
            if (mo == null)
            {
                mo = new EmployeeRank();
            }

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

            saveEmployeeRank(mo);
        }
예제 #8
0
        public ActionResult SaveNewEmployee()
        {
            var departments           = new  Department();
            var employeeRanks         = new EmployeeRank();
            var emloyeeFormViewModels = new EmloyeeFormViewModels
            {
                Employee      = new Employee(),
                Departments   = departments.GetDepartments(),
                EmployeeRanks = employeeRanks.GetEmployeeRanks()
            };



            return(View(emloyeeFormViewModels));
        }
예제 #9
0
        public override IDbCommand getUpdateDBCommand(IModelObject modelObj, string sql)
        {
            EmployeeRank obj  = (EmployeeRank)modelObj;
            IDbCommand   stmt = this.dbConn.getCommand(sql);

            stmt.Parameters.Add(this.dbConn.getParameter(EmployeeRank.STR_FLD_RANK, obj.PrRank));

            if (obj.isNew)
            {
            }
            else
            {
                //only add primary key if we are updating and as the last parameter
                stmt.Parameters.Add(this.dbConn.getParameter(EmployeeRank.STR_FLD_RANKID, obj.PrRankId));
            }

            return(stmt);
        }
예제 #10
0
 public void saveEmployeeRank(EmployeeRank mo)
 {
     base.save(mo);
 }
예제 #11
0
        public void testVBNetCreateRecords()
        {
            ModelContext.Current.config.DoCascadeDeletes = true;
            ModelContext.beginTrans();
            ModelContext.Current.addGlobalModelValidator(typeof(Employee), typeof(CsharpEmployeeValidator));
            DateTime hireDate = new DateTime(DateTime.Now.Year + 10, 1, 1);

            try {
                EmployeeRank er = EmployeeRankFactory.Create();
                er.PrRank = "My New Rank";

                Employee employee = EmployeeFactory.Create();
                NUnit.Framework.Assert.IsTrue(employee is IAuditable, "Empoyee must implement IAuditable");

                employee.PrRank         = er;
                employee.PrEmployeeName = "test employee";
                employee.PrSalary       = 100m;
                employee.PrSSINumber    = "1030045";
                employee.PrTelephone    = "2234455";
                employee.PrHireDate     = hireDate;
                employee.PrIsActive     = true;

                Guid g = Guid.NewGuid();
                employee.PrSampleGuidField = g;
                employee.PrEmployeeProjectAdd(EmployeeProjectFactory.Create());
                EmployeeProject emplProj = employee.PrEmployeeProjectGetAt(0);
                emplProj.PrAssignDate            = new DateTime(DateTime.Now.Year + 10, 3, 1);
                emplProj.PrEndDate               = new DateTime(DateTime.Now.Year + 10, 6, 1);
                emplProj.PrEPProjectId           = 1;
                emplProj.PrProject               = ProjectFactory.Create();
                emplProj.PrProject.PrProjectName = "MyProject";

                NUnit.Framework.Assert.IsTrue(employee.isNew);
                NUnit.Framework.Assert.IsTrue(employee.isDirty);
                NUnit.Framework.Assert.IsTrue(employee.NeedsSave);

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

                NUnit.Framework.Assert.IsTrue(employee.CreateDate == null, "Before save, created date is null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateDate == null, "Before save, UpdateDate is not null");

                ModelContext.Current.saveModelObject(employee);

                NUnit.Framework.Assert.IsTrue(employee.PrSSINumber == "12345XX", "12345XX value in PrSSINumber is Proof that validator was called");
                NUnit.Framework.Assert.IsTrue(employee.CreateDate != null, "Before save, created date is not null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateDate != null, "Before save, UpdateDate is not null");
                NUnit.Framework.Assert.IsTrue(employee.CreateUser != null, "Before save, CreateUser date is not null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateUser != null, "Before save, UpdateUser is not null");
                NUnit.Framework.Assert.IsTrue(employee.UpdateDate.GetValueOrDefault().ToString("dd/MM/yyyy") == employee.CreateDate.GetValueOrDefault().ToString("dd/MM/yyyy"), "update date = create date after saving new");
                NUnit.Framework.Assert.IsTrue(employee.UpdateUser == employee.CreateUser, "update date = create date after saving new");

                long x = (long)employee.Id;
                NUnit.Framework.Assert.IsFalse(employee.isNew, "After save, model object isNew property must return false");
                NUnit.Framework.Assert.IsFalse(employee.isDirty, "After save to db, model object isDirty property must return false");

                employee = EmployeeDataUtils.findByKey(x);

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

                NUnit.Framework.Assert.IsFalse(employee.isNew, "After load from db, model object isNew property returns false");
                NUnit.Framework.Assert.IsFalse(employee.isDirty, "After load from db, model object isDirty property returns false");
                NUnit.Framework.Assert.AreEqual(employee.PrSampleGuidField, g);
                NUnit.Framework.Assert.AreEqual(employee.PrRank.PrRank, "My New Rank");
                NUnit.Framework.Assert.AreEqual(employee.PrSalary, 100m);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeName, "test employee");
                NUnit.Framework.Assert.AreEqual(employee.PrSSINumber, "12345XX");
                NUnit.Framework.Assert.AreEqual(employee.PrHireDate, hireDate);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 1);
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject");

                //change some values on child and parent objects
                employee.PrEmployeeProjectGetAt(0).PrEndDate = new DateTime(DateTime.Now.Year + 10, 6, 1);
                employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName = "MyProject Updated"; // here we are updating parent record of child object of employee!
                NUnit.Framework.Assert.IsTrue(employee.NeedsSave, "After changing parent or child obejcts values, e.NeedsSave must be true");
                NUnit.Framework.Assert.IsFalse(employee.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(employee);

                var lst = EmployeeDataUtils.findList("hiredate between ? and ?", new DateTime(DateTime.Now.Year + 10, 1, 1), new DateTime(DateTime.Now.Year + 10, 12, 1));
                NUnit.Framework.Assert.AreEqual(1, lst.Count);
                employee = EmployeeDataUtils.findByKey(x);

                //NUnit.Framework.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

                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrEndDate, new DateTime(DateTime.Now.Year + 10, 6, 1));
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject Updated", "Expected to have parent record of child updated!");

                employee.PrSSINumber              = "XXXXX";
                employee.PrEmployeeInfo           = EmployeeInfoFactory.Create();
                employee.PrEmployeeInfo.PrAddress = "2 nikoy thefanous street";
                employee.PrEmployeeInfo.PrSalary  = 3000;

                NUnit.Framework.Assert.IsTrue(employee.NeedsSave, "After changing value, e.NeedsSave must be true");
                NUnit.Framework.Assert.IsTrue(employee.isDirty, "After changing value e.isDirty must be true");

                // method 3: call [ModelObject]dbMapper.save
                new EmployeeDBMapper().save(employee);
                employee = EmployeeDataUtils.findByKey(x);
                NUnit.Framework.Assert.AreEqual(employee.PrSSINumber, "XXXXX");
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrEndDate, new DateTime(DateTime.Now.Year + 10, 6, 1));
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjectGetAt(0).PrProject.PrProjectName, "MyProject Updated", "Expected to have parent record of child updated!");

                employee.PrEmployeeProjectsClear();
                NUnit.Framework.Assert.AreEqual(employee.PrEmployeeProjects.ToList().Count, 0, "Expected to have no Projects linked after call to clear");
                EmployeeDataUtils.saveEmployee(employee);

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

                List <Employee> empls = EmployeeDataUtils.findList("EmployeeName={0} and Salary between {1} and {2} and HireDate={3}", "test employee", 0, 100, hireDate);
                NUnit.Framework.Assert.IsTrue(empls.Count > 0, "Employee Count not the expected!");

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

                // now let's test string primary key
                EmployeeType et = EmployeeTypeFactory.Create();
                et.PrEmployeeType     = "A Description";
                et.PrEmployeeTypeCode = "XX";

                EmployeeType et1 = EmployeeTypeFactory.Create();
                et1.PrEmployeeType     = "A Description 1";
                et1.PrEmployeeTypeCode = "XX1";

                EmployeeType et2 = EmployeeTypeFactory.Create();
                et2.PrEmployeeType     = "A Description 2";
                et2.PrEmployeeTypeCode = "XX2";

                EmployeeTypeDataUtils.saveEmployeeType(et, et1, et2);

                et2 = EmployeeTypeDataUtils.findByKey("XX2");
                NUnit.Framework.Assert.IsNotNull(et2, "New employeetype must have been created!");
                et1 = EmployeeTypeDataUtils.findByKey("XX1");
                NUnit.Framework.Assert.IsNotNull(et1, "New employeetype must have been created!");

                Project p = ProjectFactory.Create();
                p.PrIsActive      = true;
                p.PrProjectTypeId = ModelLibVBGenCode.EnumProjectType.EXTERNAL;
                p.PrProjectName   = "Test";
                ProjectDataUtils.saveProject(p);
                long pid = p.PrProjectId;
                p = ProjectDataUtils.findByKey(pid);
                NUnit.Framework.Assert.IsNotNull(p, "New project must have been saved to the db!");
                NUnit.Framework.Assert.AreEqual(p.PrProjectTypeId, ModelLibVBGenCode.EnumProjectType.EXTERNAL);

                p.PrProjectTypeId = null; // test null value to enumaration
                ProjectDataUtils.saveProject(p);
                p = ProjectDataUtils.findByKey(pid);
                NUnit.Framework.Assert.IsNotNull(p, "New project must have been saved to the db!");
                NUnit.Framework.Assert.IsNull(p.PrProjectTypeId, "project type id must be null after saved to the db, instead got value:" + p.PrProjectTypeId);

                List <Employee>    elst = EmployeeDataUtils.findList();
                EmployeeEvaluation ep   = EmployeeEvaluationFactory.Create();
                ep.PrEmployeeId     = elst[0].PrEmployeeId;
                ep.PrEvaluatorId    = elst[1].PrEmployeeId;
                ep.PrEvaluationDate = hireDate;
                EmployeeEvaluationDataUtils.saveEmployeeEvaluation(ep); // insert
                NUnit.Framework.Assert.IsTrue(ep.PrEmployeeEvaluationId > 0);
                long eid = ep.PrEmployeeEvaluationId;

                EmployeeEvaluation ep2 = EmployeeEvaluationDataUtils.findByKey(eid);
                NUnit.Framework.Assert.IsNotNull(ep2);
                NUnit.Framework.Assert.AreEqual(ep, ep2);
                ep2.PrEvaluationDate = new DateTime(hireDate.Year, hireDate.Month + 1, 1);
                EmployeeEvaluationDataUtils.saveEmployeeEvaluation(ep2);   // update

                EmployeeEvaluationDataUtils.deleteEmployeeEvaluation(ep2); //delete
                ep2 = EmployeeEvaluationDataUtils.findByKey(eid);
                NUnit.Framework.Assert.IsNull(ep2);

                Bank alphaBank = BankDataUtils.findOne("bankcode='09'");
                if (alphaBank == null)
                {
                    alphaBank            = BankFactory.Create();
                    alphaBank.PrBankCode = "09";
                    alphaBank.PrBankName = "ALPHA Bank";
                    BankDataUtils.saveBank(alphaBank);
                }

                Account pa = AccountDataUtils.findOne("Account='ALPHA'");
                if ((pa == null))
                {
                    pa                                     = AccountFactory.Create();
                    pa.PrAccount                           = "ALPHA";
                    pa.PrDescription                       = "ALPHA TEST";
                    pa.PrAccountTypeid                     = 1;
                    pa.PrBankaccnumber                     = "000000000004";
                    pa.PrBankAccountInfo                   = AccountBankInfoFactory.Create();
                    pa.PrBankAccountInfo.PrBankId          = alphaBank.PrBANKID;
                    pa.PrBankAccountInfo.PrCompanyName     = "UNIT TESTS LTD";
                    pa.PrBankAccountInfo.PrCompanyBankCode = "111";
                    AccountDataUtils.saveAccount(pa);
                }
            } finally {
                ModelContext.rollbackTrans();
            }
        }
예제 #12
0
 public void saveEmployeeRank(EmployeeRank mo)
 {
     base.save(mo);
 }
예제 #13
0
 public static EmployeeRank loadFromDataRow(DataRow r)
 {
     DataRowLoader a = new DataRowLoader();
     IModelObject mo = new EmployeeRank();
     a.DataSource = r;
     a.load(mo);
     return (EmployeeRank)mo;
 }
예제 #14
0
 public EmployeeDecorator(EmployeeRank rank, Employee employee) : base(employee.Type)
 {
     this.employee = employee;
     this.rank     = rank;
 }
예제 #15
0
        public static void deleteEmployeeRank(EmployeeRank EmployeeRankObj)
        {
            EmployeeRankDBMapper dbm = new EmployeeRankDBMapper();

            dbm.delete(EmployeeRankObj);
        }
예제 #16
0
        /// <summary>
        /// Reload the EmployeeRank from the database
        /// </summary>
        /// <remarks>
        /// use this method when you want to relad the EmployeeRank 
        /// from the database, discarding any changes
        /// </remarks>
        public static void reload(ref EmployeeRank mo)
        {
            if (mo == null) {
                throw new System.ArgumentNullException("null object past to reload function");
            }

            mo = (EmployeeRank)new EmployeeRankDBMapper().findByKey(mo.Id);
        }
예제 #17
0
        public static void saveEmployeeRank(DataRow dr, ref EmployeeRank mo)
        {
            if (mo == null) {
                mo = new EmployeeRank();
            }

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

            saveEmployeeRank(mo);
        }
예제 #18
0
 public static void saveEmployeeRank(DataTable dt, ref EmployeeRank mo)
 {
     foreach (DataRow dr in dt.Rows) {
         saveEmployeeRank(dr, ref mo);
     }
 }
예제 #19
0
 public ActionResult SaveEmployeeRank(EmployeeRank employeeRank)
 {
     return(View());
 }
예제 #20
0
 public static void deleteEmployeeRank(EmployeeRank EmployeeRankObj)
 {
     EmployeeRankDBMapper dbm = new EmployeeRankDBMapper();
     dbm.delete(EmployeeRankObj);
 }
    [TestMethod()] public void TestLoadAndSaveEmployeeRank()
    {
        ModelContext.beginTrans();
        try {
            CsModelMappers.EmployeeRankDBMapper pdb = new CsModelMappers.EmployeeRankDBMapper();

            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 EmployeeRank in database, table is empty");
            }
            else
            {
                /**
                 * using (DataContext ctx = DBUtils.Current().dbContext()) {
                 *
                 *      var query = ctx.ExecuteQuery<EmployeeRank>(@"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);

                EmployeeRank p  = pdb.findByKey(pid);
                EmployeeRank p2 = (EmployeeRank)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.PrRankId == p2.PrRankId, "Expected Field RankId to be equal");
                Assert.IsTrue(p.PrRank == p2.PrRank, "Expected Field Rank to be equal");

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

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

                string json = JsonConvert.SerializeObject(p, Formatting.Indented,
                                                          new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                System.IO.FileInfo jf = new System.IO.FileInfo(".\\EmployeeRank.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!
        }
    }