private bool Save()
        {
            bool result = false;

            using (var ctx = new EF6.RT2020Entities())
            {
                var sg = ctx.StaffGroup.Find(this.StaffGroupId);

                if (sg == null)
                {
                    sg           = new EF6.StaffGroup();
                    sg.GroupId   = new Guid();
                    sg.GradeCode = txtStaffGroupCode.Text;

                    ctx.StaffGroup.Add(sg);
                }
                sg.GradeName     = txtStaffGroupName.Text;
                sg.GradeName_Chs = txtStaffGroupNameAlt1.Text;
                sg.GradeName_Cht = txtStaffGroupNameAlt2.Text;
                if ((Guid)cboParentGrade.SelectedValue != Guid.Empty)
                {
                    sg.ParentGrade = (Guid)cboParentGrade.SelectedValue;
                }

                sg.CanRead   = chkCanRead.Checked;
                sg.CanWrite  = chkCanWrite.Checked;
                sg.CanDelete = chkCanDelete.Checked;
                sg.CanPost   = chkCanPost.Checked;

                ctx.SaveChanges();
                result = true;
            }

            return(result);
        }
Exemple #2
0
 private static string GetFormatedText(EF6.StaffGroup target, string[] textField, string textFormatString)
 {
     for (int i = 0; i < textField.Length; i++)
     {
         PropertyInfo pi = target.GetType().GetProperty(textField[i]);
         textFormatString = textFormatString.Replace("{" + i.ToString() + "}", pi != null ? pi.GetValue(target, null).ToString() : string.Empty);
     }
     return(textFormatString);
 }
Exemple #3
0
        /// <summary>
        /// Get a EF6.StaffGroup object from the database using the given GroupId
        /// </summary>
        /// <param name="groupId">The primary key value</param>
        /// <returns>A EF6.StaffGroup object</returns>
        public static EF6.StaffGroup Get(Guid groupId)
        {
            EF6.StaffGroup result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                result = ctx.StaffGroup.Where(x => x.GroupId == groupId).AsNoTracking().FirstOrDefault();
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Get a EF6.StaffGroup object from the database using the given QueryString
        /// </summary>
        /// <param name="groupId">The primary key value</param>
        /// <returns>A EF6.StaffGroup object</returns>
        public static EF6.StaffGroup Get(string whereClause)
        {
            EF6.StaffGroup result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                result = ctx.StaffGroup
                         .SqlQuery(string.Format("Select * from StaffGroup Where {0}", whereClause))
                         .AsNoTracking()
                         .FirstOrDefault();
            }

            return(result);
        }
Exemple #5
0
        public static EF6.StaffGroup GetById(Guid id)
        {
            EF6.StaffGroup result = null;

            using (var ctx = new EF6.RT2020Entities())
            {
                var sg = ctx.StaffGroup.Where(x => x.GroupId == id).FirstOrDefault();
                if (sg != null)
                {
                    result = sg;
                }
            }

            return(result);
        }