예제 #1
0
        public async Task <ActionResult> Index(CancellationToken cancellationToken)
        {
            ViewData[Constant.FormTitle] = "ADD Role";
            IRoleModel model = await _service.IndexAsync(this.HttpContext.ApplicationInstance.Context, GetCanellationToken(cancellationToken));

            return(View(model));
        }
예제 #2
0
        private bool RecordExistsCheck(SqlCommand cmd, IRoleModel roleModel, TypeOfExistenceCheck typeOfExistenceCheck,
                                       RequestType requestType)
        {
            Int32 count0fRecordsFound     = 0;
            bool  recordExistsCheckPassed = true;

            DataAccessStatus dataAccessStatus = new DataAccessStatus();
            SqlCommand       cmdCheck         = new SqlCommand(null, cmd.Connection);

            cmdCheck.Prepare();


            if ((requestType == RequestType.Add) || (requestType == RequestType.ConfirmAdd))
            {
                cmdCheck.CommandText = "SELECT count(*) FROM [Roles] where [Name] = @Name";
                cmdCheck.Parameters.Add(new SqlParameter("@Name", System.Data.SqlDbType.VarChar, 20)).Value = roleModel.Name;
            }
            else if ((requestType == RequestType.Update) || (requestType == RequestType.Delete) || (requestType == RequestType.ConfirmDelete))
            {
                cmdCheck.CommandText = "SELECT count(*) FROM [Roles] WHERE [ID] = @ID";
                cmdCheck.Parameters.Add(new SqlParameter("@ID", roleModel.ID));
            }

            try
            {
                count0fRecordsFound = Convert.ToInt32(cmdCheck.ExecuteScalar());
            }
            catch (SqlException e)
            {
                string msg = e.Message;
                throw e;
            }

            if ((typeOfExistenceCheck == TypeOfExistenceCheck.DoesNotExistInDB) && (count0fRecordsFound > 0))
            {
                dataAccessStatus.Status = "Error";
                recordExistsCheckPassed = false;

                throw new DataAccessException(dataAccessStatus);
            }
            else if ((typeOfExistenceCheck == TypeOfExistenceCheck.DoesExistInDB) && (count0fRecordsFound == 0))
            {
                dataAccessStatus.Status = "Error";
                recordExistsCheckPassed = false;

                throw new DataAccessException(dataAccessStatus);
            }

            return(recordExistsCheckPassed);
        }
예제 #3
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public async Task <IRoleModel> SaveAsync()
        {
            ValidationSummary summary = Validator.Validate(this);

            if (!summary.IsValid)
            {
                throw new ValidationException(summary);
            }

            RoleDto role = await ServiceClient <IRoleService> .ExecuteAsync(d => d.SaveRoleAsync(Factory.Convert(this)));

            IRoleModel roleModel = Factory.Convert(role);

            return(roleModel);
        }
예제 #4
0
        public async Task <ActionResult> IndexEdit(long hdRoleId, CancellationToken cancellationToken)
        {
            if (hdRoleId > 0)
            {
                ViewData[Constant.FormTitle] = "EDIT Role";
                IRoleModel model = await _service.IndexAsync(this.HttpContext.ApplicationInstance.Context, hdRoleId, GetCanellationToken(cancellationToken));

                ViewData[Constant.QuerySuccess] = HttpContext.Items[Constant.QuerySuccess];
                return(View("Index", model));
            }
            else
            {
                return(Redirect("~/RoleSearch/Index"));
            }
        }
예제 #5
0
        public RoleEntryView(bool isNewData = true, IRoleModel model = null)
        {
            InitializeComponent();
            _isNewData        = isNewData;
            panelUp.LabelInfo = isNewData ? $"TAMBAH {_typeName.ToUpper()}" : $"UBAH {_typeName.ToUpper()}";

            if (!_isNewData)
            {
                _model                 = model;
                textBoxKode.Text       = _model.kode;
                textBoxNama.Text       = _model.nama;
                textBoxKeterangan.Text = _model.keterangan;
            }

            operationButtons.OnSaveButtonClick += OperationButtons_OnSaveButtonClick;
        }
예제 #6
0
 public void ValidateModel(IRoleModel model)
 {
     _modelDAC.ValidateModel(model);
     _modelDAC.ValidateModels(model.RoleDetails);
 }
예제 #7
0
 public void Delete(IRoleModel model)
 {
     _repo.Delete(model);
 }
예제 #8
0
 public void Update(IRoleModel model)
 {
     ValidateModel(model);
     _repo.Update(model);
 }
예제 #9
0
 public void Insert(IRoleModel model)
 {
     ValidateModel(model);
     _repo.Insert(model);
 }
예제 #10
0
 public void ValidateModelDataAnnotations(IRoleModel roleModel)
 {
     this.modelDataAnnotationCheck.ValidateModelDataAnnotations(roleModel);
 }
예제 #11
0
 public void Update(IRoleModel roleModel)
 {
     roleRepository.Update(roleModel);
 }
예제 #12
0
        public void Remove(IRoleModel roleModel)
        {
            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                }
                catch (SqlException e)
                {
                    dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                               customMessage: "Unable to Delete Role Model. Could not open database connection.",
                                               helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                    throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                }

                string deleteQuery = "DELETE FROM [Roles] WHERE [ID] = @ID";

                using (SqlCommand cmd = new SqlCommand(deleteQuery, sqlConnection))
                {
                    try
                    {
                        RecordExistsCheck(cmd, roleModel, TypeOfExistenceCheck.DoesExistInDB, RequestType.Delete);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.CustomMessage    = "Role model could not be deleted because it could not be found in the database";
                        e.DataAccessStatusInfo.ExceptionMessage = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace       = string.Copy(e.StackTrace);

                        throw e;
                    }

                    cmd.CommandText = deleteQuery;

                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@ID", roleModel.ID);

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                                   customMessage: "Unable to Delete Roles Model.",
                                                   helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                        throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                    }

                    //Confirm that the department model has been deleted

                    try
                    {
                        RecordExistsCheck(cmd, roleModel, TypeOfExistenceCheck.DoesNotExistInDB, RequestType.ConfirmDelete);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.Status             = "Error";
                        e.DataAccessStatusInfo.OperationSucceeded = false;
                        e.DataAccessStatusInfo.CustomMessage      = "Failed to role Department model in database";
                        e.DataAccessStatusInfo.ExceptionMessage   = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace         = string.Copy(e.StackTrace);

                        throw e;
                    }
                }
                sqlConnection.Close();
            }
        }
예제 #13
0
 public UserModel()
 {
     Role = new RoleModel();
 }
예제 #14
0
 public RoleController(IRoleModel roleModel)
 {
     _roleModel = roleModel;
 }
 public RoleServicesFixture()
 {
     this.roleServices = new RoleServices(null, new ModelDataAnnotationCheck());
     this.roleModel    = new RoleModel();
 }
예제 #16
0
        public void Add(IRoleModel roleModel)
        {
            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                }
                catch (SqlException e)
                {
                    dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                               customMessage: "Unable to add Role Model. Could not open a database connection", helpLink: e.HelpLink, errorCode: e.ErrorCode,
                                               stackTrace: e.StackTrace);

                    throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                }

                string addQuery =
                    "INSERT INTO [Roles] ([Name]) " +
                    "VALUES (@Name)";

                using (SqlCommand cmd = new SqlCommand(null, sqlConnection))
                {
                    try
                    {
                        RecordExistsCheck(cmd, roleModel, TypeOfExistenceCheck.DoesNotExistInDB, RequestType.Add);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.CustomMessage    = "Role model could not be added because it is already in the database.";
                        e.DataAccessStatusInfo.ExceptionMessage = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace       = string.Copy(e.StackTrace);

                        throw e;
                    }

                    cmd.CommandText = addQuery;

                    SqlParameter roleName = new SqlParameter("@Name", System.Data.SqlDbType.VarChar, 20);
                    roleName.Value = roleModel.Name;
                    cmd.Parameters.Add(roleName);


                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                                   customMessage: "Unable to add Role Model.", helpLink: e.HelpLink, errorCode: e.ErrorCode,
                                                   stackTrace: e.StackTrace);

                        throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                    }

                    //Confirm the Department Model was Added to the database
                    try
                    {
                        RecordExistsCheck(cmd, roleModel, TypeOfExistenceCheck.DoesExistInDB, RequestType.ConfirmAdd);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.Status             = "Error";
                        e.DataAccessStatusInfo.OperationSucceeded = false;
                        e.DataAccessStatusInfo.CustomMessage      = "Failed to find role model in database after add operation completed.";
                        e.DataAccessStatusInfo.ExceptionMessage   = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace         = string.Copy(e.StackTrace);

                        throw new DataAccessException(dataAccessStatus);
                    }

                    sqlConnection.Close();
                }
            }
        }
예제 #17
0
 partial void OnConvertAdditionalFields(IRoleModel source, RoleDto dest)
 {
     dest.Rights = _rightFactory.Convert(source.Rights);
 }
예제 #18
0
 public void Remove(IRoleModel roleModel)
 {
     roleRepository.Remove(roleModel);
 }
예제 #19
0
 public void Add(IRoleModel roleModel)
 {
     roleRepository.Add(roleModel);
 }
예제 #20
0
        public void Update(IRoleModel roleModel)
        {
            int result = -1;

            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                }
                catch (SqlException e)
                {
                    dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                               customMessage: "Unable to Update Role Model. Could not open database connection.",
                                               helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                    throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                }

                string updateDepQuery =
                    "UPDATE [Roles] " +
                    "SET [Name] = @Name " +
                    "WHERE [ID] =  @ID ";

                using (SqlCommand cmd = new SqlCommand(updateDepQuery, sqlConnection))
                {
                    try
                    {
                        RecordExistsCheck(cmd, roleModel, TypeOfExistenceCheck.DoesExistInDB, RequestType.Update);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.CustomMessage    = "role model could not be updated because it could not be found in the database";
                        e.DataAccessStatusInfo.ExceptionMessage = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace       = string.Copy(e.StackTrace);

                        throw e;
                    }

                    cmd.CommandText = updateDepQuery;

                    cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar, 40).Value = roleModel.Name;
                    cmd.Parameters.Add("@ID", System.Data.SqlDbType.Int).Value           = Convert.ToInt32(roleModel.ID);

                    cmd.Prepare();


                    try
                    {
                        result = cmd.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                                   customMessage: "Unable to Update Role Model.",
                                                   helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                        throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                    }
                }
                sqlConnection.Close();
            }
        }