Exemple #1
0
 public void Insert(DirectorySubCategoryModel model)
 {
     try
     {
         var objToSave = new tblDirectorySubCategory()
         {
             DirectorySubCategoryId   = model.DirectorySubCategoryId,
             DirectorySubCategoryName = model.DirectorySubCategoryName,
             DirectoryCategoryId      = model.DirectoryCategoryId
         };
         //objToSave.CreatedBy = Utility.GetCurrentLoginUser();
         objToSave.CreatedDate = DateTime.Now.ToShortDateString().ToString();
         ent.tblDirectorySubCategories.Add(objToSave);
         ent.SaveChanges();
     }
     catch (Exception ex)
     {
     }
 }
        public bool InsertUpdateSubCategory(SubCategorySetupViewModel model)
        {
            try
            {
                using (var con = new DirectoryEntities())
                {
                    if (model.DirectorySubCategoryId > 0)
                    {
                        var record = con.tblDirectorySubCategories.Where(x => x.DirectorySubCategoryId == model.DirectorySubCategoryId).FirstOrDefault();
                        if (record != null)
                        {
                            record.DirectorySubCategoryId   = model.DirectorySubCategoryId;
                            record.DirectorySubCategoryName = model.DirectorySubCategoryName;
                            record.DirectoryCategoryId      = model.DirectoryCategoryId;
                            con.Entry(record).State         = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    else
                    {
                        tblDirectorySubCategory subCategory = new tblDirectorySubCategory()
                        {
                            DirectorySubCategoryId   = model.DirectorySubCategoryId,
                            DirectorySubCategoryName = model.DirectorySubCategoryName,
                            DirectoryCategoryId      = model.DirectoryCategoryId
                        };
                        //subCategory.CreatedBy = Utility.GetCurrentLoginUser();
                        subCategory.CreatedDate = DateTime.Now.ToShortDateString().ToString();
                        con.tblDirectorySubCategories.Add(subCategory);
                    }
                    con.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }