예제 #1
0
        public Task <grant_typeC> AddNew(dto_grant_type_newC _dto)
        {
            grant_typeC _obj = null;

            if (_dto == null)
            {
                AddErrorMessage("Insert Error", "Save Error", "Grant Type Object Is Null");
                _obj = null;
                return(Task.FromResult(_obj));
            }
            if (string.IsNullOrEmpty(_dto.grant_type_name))
            {
                AddErrorMessage("Insert Error", "Save Error", "Grant Type Name Is Null");
                _obj = null;
                return(Task.FromResult(_obj));
            }
            if (fnn.LOGGED_USER.DoesNotHaveRight(em.right_menu_types.can_create_new_grant))
            {
                _obj = null;
                AddErrorMessage("Limited Rights Error", "Limited Rights Error", "You Are Not Authorized To Perform This Operation");
                return(Task.FromResult(_obj));
            }
            using (var _db = fnn.GetDbContext())
            {
                _obj = new grant_typeC();
                _obj.grant_type_name    = _dto.grant_type_name.Trim().ToProperCase();
                _obj.fs_timestamp       = fnn.GetServerDate().ToUnixTimestamp();
                _obj.server_edate       = fnn.GetServerDate();
                _obj.created_by_user_id = fnn.LOGGED_USER.user_id;
                _db.GRANT_TYPES.Add(_obj);
                var _retVal = _db.SaveChangesWithDuplicateKeyDetected();
                if (_retVal == null || _retVal.Value == true)
                {
                    AddErrorMessage("Duplicate Key Error", "Duplicate Key Error", "You Have Entered A Duplicate Grant Type Name");
                    _obj = null;
                }
            }
            if (_obj != null)
            {
                using (var _dbb = fnn.GetDbContext())
                {
                    foreach (var k in Enum.GetValues(typeof(em.resource_typeS)))
                    {
                        var _robj = new voice_resource_categoryC();
                        _robj.created_by_user_id   = fnn.LOGGED_USER.user_id;
                        _robj.resource_cat_id      = _obj.grant_type_id;
                        _robj.resource_cat_type_id = em.resource_cat_typeS.grant_type.ToInt32();
                        _robj.resource_type_id     = k.ToInt16();
                        _robj.fs_timestamp         = fnn.GetServerDate().ToUnixTimestamp();
                        _robj.server_edate         = fnn.GetServerDate();
                        _dbb.VOICE_RESOURCE_CATEGORIES.Add(_robj);
                        _dbb.SaveChanges();
                    }
                }
            }
            return(Task.FromResult(_obj));
        }
예제 #2
0
        public Task <bool> Delete(int id)
        {
            bool _record_deleted = false;

            if (fnn.LOGGED_USER.DoesNotHaveRight(em.right_menu_types.can_delete_grant))
            {
                AddErrorMessage("Limited Rights Error", "Limited Rights Error", "You Are Not Authorized To Perform This Operation");
                return(Task.FromResult(_record_deleted));
            }
            grant_typeC _obj = null;

            using (var _db = fnn.GetDbContext())
            {
                _obj = _db.GRANT_TYPES.Where(e => e.grant_type_id == id & e.delete_id == 0).SingleOrDefault();
                if (_obj == null)
                {
                    _record_deleted = false;
                    AddErrorMessage("Delete Error", "Delete Error", "Could Not Find Grant Type Object");
                }
                else
                {
                    var _has_dependency = DbHelper.HasDbDependencies(_db.Database, new string[] { "grant_type_tb" }, DbHelper.GetDbSchema(), new string[] { "grant_type_id" }, id);
                    if (_has_dependency == null || _has_dependency == true)
                    {
                        AddErrorMessage("Delete Error", "Delete Error", "Unable To Delete Record Because It Has System Dependencies.");
                        _record_deleted = false;
                    }
                    else
                    {
                        var _result = DbHelper.DeleteRecordWithDeleteId(new DbHelperDeleteRecordC()
                        {
                            pk_col_name = "grant_type_id",
                            pk_id       = _obj.grant_type_id,
                            table_name  = DbHelper.GetTableSchemaName(_table_name)
                        }, _db);
                        if (_result == null || _result == false)
                        {
                            AddErrorMessage("Delete Error", "Delete Error", "Error Encountered While Trying To Delete Record");
                            _record_deleted = false;
                        }
                        else
                        {
                            _record_deleted = true;
                            _db.SaveChanges();
                        }
                    }
                }
            }
            if (_record_deleted)
            {
                Task.Factory.StartNew(() =>
                {
                    using (var _dbb = fnn.GetDbContext())
                    {
                        int _cat_type_id = em.resource_cat_typeS.grant_type.ToInt32();
                        var _r_list      = (from k in _dbb.VOICE_RESOURCE_CATEGORIES
                                            where k.resource_cat_type_id == _cat_type_id & k.resource_cat_id == _obj.grant_type_id
                                            & k.delete_id == 0
                                            select k).ToList();
                        foreach (var _v in _r_list)
                        {
                            var _result = DbHelper.DeleteRecordWithDeleteId(new DbHelperDeleteRecordC()
                            {
                                pk_col_name = _v.un_id.ToString(),
                                pk_id       = _v.un_id,
                                table_name  = DbHelper.GetTableSchemaName("voice_resource_cat_tb")
                            }, _dbb);
                            _dbb.SaveChanges();
                        }
                    }
                });
            }
            return(Task.FromResult(_record_deleted));
        }