예제 #1
0
 public static string ReturnData(string categoryId)
 {
     using (MSIPortalContext ctx = new MSIPortalContext())
     {
         LU_tbl_Category category = ctx.LU_tbl_Category.Where(c => c.CategoryID == categoryId).FirstOrDefault();
         return(category.PSTID);
     }
 }
예제 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (MSIPortalContext ctx = new MSIPortalContext())
            {
                var    maxId       = ctx.LU_tbl_Category.Select(c => c.CategoryID).Max(); // Select Max Id
                int    newId       = Convert.ToInt32(maxId) + 1;
                string newStringId = newId.ToString("D4");

                var count = ctx.LU_tbl_Category.Where(c => c.CategoryName.Trim() == txtCategiryName.Text.Trim()).Count(); // Count Based on given Category Name

                if (Convert.ToInt32(count) > 0)                                                                           // Duplicacy Check
                {
                    lblError.Text        = "Duplicate entry not allowed.";
                    lblSuccess.Text      = string.Empty;
                    MessagePanel.Visible = true;
                }
                else
                {
                    if (TreeView1.SelectedNode == null)   // Validate if parent node is not selected
                    {
                        lblError.Text        = "Parent node must be selected.";
                        lblSuccess.Text      = string.Empty;
                        MessagePanel.Visible = true;
                        return;
                    }

                    LU_tbl_Category category = new LU_tbl_Category();
                    category.CategoryID   = newStringId;
                    category.ParentCatID  = TreeView1.SelectedNode.Value.ToString();
                    category.CategoryName = txtCategiryName.Text.Trim();
                    category.PSTID        = ddlSalesService.SelectedValue;
                    category.EditUser     = Guid.NewGuid(); // Needs Modification Will Come from Login Session
                    category.EditDate     = DateTime.Now;
                    ctx.LU_tbl_Category.Add(category);
                    ctx.SaveChanges();
                    lblSuccess.Text               = "Record saved successfully";
                    txtCategiryName.Text          = string.Empty;
                    ddlSalesService.SelectedValue = "000";
                    lblError.Text        = string.Empty;
                    MessagePanel.Visible = true;
                    txtCategiryName.Focus();
                }
            }
            this.PopulateTree();
        }// End of Method Populate Tree