public bool UpdateTermAndCondition(TBL_MP_Master_TnC model)
        {
            bool result = false;

            try
            {
                TBL_MP_Master_TnC objTerm = _dbContext.TBL_MP_Master_TnC.Where(x => x.PK_TermID == model.PK_TermID).FirstOrDefault();
                if (objTerm != null)
                {
                    objTerm.Term_CategoryID  = model.Term_CategoryID;
                    objTerm.Term_Description = model.Term_Description;
                    objTerm.Term_TitleID     = model.Term_TitleID;
                    objTerm.IsActive         = model.IsActive;
                    _dbContext.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceTermsAndConditions::UpdateTermAndCondition", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }
        public bool ActivateTermAndCondition(int termID)
        {
            bool result = false;

            try
            {
                TBL_MP_Master_TnC model = _dbContext.TBL_MP_Master_TnC.Where(x => x.PK_TermID == termID).FirstOrDefault();
                if (model != null)
                {
                    model.IsActive = true;
                    _dbContext.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceTermsAndConditions::ActivateTermAndCondition", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }
        public int AddNewTermAndCondition(TBL_MP_Master_TnC model)
        {
            int newID = 0;

            try
            {
                TBL_MP_Master_TnC newTerm = new TBL_MP_Master_TnC();
                newTerm.Term_CategoryID  = model.Term_CategoryID;
                newTerm.Term_Description = model.Term_Description;
                newTerm.Term_TitleID     = model.Term_TitleID;
                newTerm.IsActive         = model.IsActive;
                _dbContext.TBL_MP_Master_TnC.Add(newTerm);
                _dbContext.SaveChanges();
                newID = newTerm.PK_TermID;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceTermsAndConditions::AddNewTermAndCondition", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(newID);
        }
Exemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            TBL_MP_Master_TnC dbModel = null;

            try
            {
                errorProvider1.Clear();

                if (this.ValidateChildren())
                {
                    if (this.TermID == 0)
                    {
                        dbModel = new TBL_MP_Master_TnC()
                        {
                            Term_Description = txtDescription.Text.Trim(),
                            Term_TitleID     = ((SelectListItem)(cboTitles.SelectedItem)).ID,
                            Term_CategoryID  = ((SelectListItem)(cboCategories.SelectedItem)).ID,
                            IsActive         = chkIsActive.Checked
                        };
                        this.TermID = (new ServiceTermsAndConditions()).AddNewTermAndCondition(dbModel);
                        if (this.TermID != 0)
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    else
                    {
                        dbModel = (new ServiceTermsAndConditions()).GetTermConditionItemDBRecordByID(this.TermID);
                        if (dbModel != null)
                        {
                            dbModel.Term_Description = txtDescription.Text.Trim();
                            dbModel.Term_TitleID     = ((SelectListItem)(cboTitles.SelectedItem)).ID;
                            dbModel.Term_CategoryID  = ((SelectListItem)(cboCategories.SelectedItem)).ID;
                            dbModel.IsActive         = chkIsActive.Checked;
                            bool res = (new ServiceTermsAndConditions()).UpdateTermAndCondition(dbModel);
                            if (res)
                            {
                                this.DialogResult = DialogResult.OK;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmAddEditTermsAndCondition::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
        }
Exemplo n.º 5
0
        private void frmAddEditTermsAndCondition_Load(object sender, EventArgs e)
        {
            try
            {
                txtDescription.Text = string.Empty;
                chkIsActive.Checked = true;
                PopulateTnCCategoriesDropdown();
                PopulateTnCTitlesDropdown();
                if (this.CategoryID != 0)
                {
                    cboCategories.SelectedItem = ((List <SelectListItem>)cboCategories.DataSource).Where(X => X.ID == this.CategoryID).FirstOrDefault();
                }


                this.Text = "TERM & CONDITION - [ADD NEW]";

                if (this.TermID != 0)
                {
                    TBL_MP_Master_TnC objTerm = (new ServiceTermsAndConditions()).GetTermConditionItemDBRecordByID(this.TermID);
                    if (objTerm != null)
                    {
                        txtDescription.Text        = objTerm.Term_Description;
                        cboCategories.SelectedItem = ((List <SelectListItem>)cboCategories.DataSource).Where(x => x.ID == objTerm.Term_CategoryID).FirstOrDefault();
                        cboTitles.SelectedItem     = ((List <SelectListItem>)cboTitles.DataSource).Where(x => x.ID == objTerm.Term_TitleID).FirstOrDefault();
                        chkIsActive.Checked        = objTerm.IsActive;
                    }
                    this.Text = "TERM & CONDITION - [EDIT]";
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmAddEditTermsAndCondition::frmAddEditTermsAndCondition_Load", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }