Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowTop.Repository.GetById(txtTermId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtTermCode.Text.Trim());
            }
            else
            {
                var topToUpdate = uowTop.Repository.GetById(txtTermId.Text.Trim());
                topToUpdate.TermCode    = txtTermCode.Text.Trim();
                topToUpdate.Description = txtDescription.Text.Trim();
                topToUpdate.ModifiedBy  = Properties.Settings.Default.CurrentUserId;
                topToUpdate.ModifiedAt  = DateTime.Now;

                uowTop.Repository.Update(topToUpdate);
                uowTop.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowBatch.Repository.GetById(txtBatchId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtBatchCode.Text.Trim());
            }
            else
            {
                var batchToUpdate = uowBatch.Repository.GetById(txtBatchId.Text.Trim());
                batchToUpdate.BatchCode   = txtBatchCode.Text.Trim();
                batchToUpdate.ProductId   = cbProductCode.SelectedValue.ToString();
                batchToUpdate.Quantity    = Convert.ToInt32(txtQuantity.Text.Trim());
                batchToUpdate.EntryDate   = DateTime.Parse(dtpEntryDate.Value.ToString("yyyy-MM-dd"));
                batchToUpdate.ExpiredDate = DateTime.Parse(dtpExpiredDate.Value.ToString("yyyy-MM-dd"));
                batchToUpdate.ModifiedBy  = Properties.Settings.Default.CurrentUserId;
                batchToUpdate.ModifiedAt  = DateTime.Now;

                uowBatch.Repository.Update(batchToUpdate);
                uowBatch.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            if (chkChangePassword.Checked && !txtPassword.Text.Trim().Equals(txtRetypePassword.Text.Trim()))
            {
                MessageBox.Show("Pastikan password yang anda masukkan sama."
                                , "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var repoLastUpdated = uowUser.Repository.GetById(txtUserId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtUserModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtUsername.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var uowUsr       = new UnitOfWork <User>(dbContext);
                    var userToUpdate = uowUsr.Repository.GetById(txtUserId.Text.Trim());
                    userToUpdate.Username = txtUsername.Text.Trim();

                    if (chkChangePassword.Checked)
                    {
                        userToUpdate.Password = new UserHelper().HashPassword(txtPassword.Text.Trim());
                    }

                    userToUpdate.FullName   = txtFullName.Text.Trim();
                    userToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                    userToUpdate.ModifiedAt = DateTime.Now;
                    uowUsr.Repository.Update(userToUpdate);
                    uowUsr.Commit();

                    var uowUsrRole       = new UnitOfWork <UserRole>(dbContext);
                    var userRoleToUpdate = uowUsrRole.Repository.GetById(txtUserRoleId.Text.ToString().Trim());
                    userRoleToUpdate.UserId     = txtUserId.Text.Trim();
                    userRoleToUpdate.RoleId     = cbRole.SelectedValue.ToString().Trim();
                    userRoleToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                    userRoleToUpdate.ModifiedAt = DateTime.Now;
                    uowUsrRole.Repository.Update(userRoleToUpdate);
                    uowUsrRole.Commit();

                    dbContextTransaction.Commit();
                }

                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowCust.Repository.GetById(txtCustomerId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtCustomerCode.Text.Trim());
            }
            else
            {
                var custToUpdate = uowCust.Repository.GetById(txtCustomerId.Text.Trim());
                custToUpdate.CustomerCode    = txtCustomerCode.Text.Trim();
                custToUpdate.CustomerName    = txtCustomerName.Text.Trim();
                custToUpdate.Address         = txtAddress.Text.Trim();
                custToUpdate.ProvinceId      = cbProvince.SelectedValue.ToString();
                custToUpdate.DistrictId      = cbDistrict.SelectedValue.ToString();
                custToUpdate.PostalCode      = txtPostCode.Text.Trim();
                custToUpdate.Phone           = txtPhone.Text.Trim();
                custToUpdate.Email           = txtEmail.Text.Trim();
                custToUpdate.Npwp            = txtNpwp.Text.Trim();
                custToUpdate.PharmacistName  = txtPharmacistName.Text.Trim();
                custToUpdate.SipaNo          = txtSipaNo.Text.Trim();
                custToUpdate.SipaExpiredDate = DateTime.Parse(dtpSipaExpiredDate.Value.ToString("yyyy-MM-dd"));
                custToUpdate.SiaNo           = txtSiaNo.Text.Trim();
                custToUpdate.OutletTypeId    = cbOutletType.SelectedValue.ToString();
                custToUpdate.SalesAreaId     = cbSalesArea.SelectedValue.ToString();

                custToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                custToUpdate.ModifiedAt = DateTime.Now;

                uowCust.Repository.Update(custToUpdate);
                uowCust.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowProduct.Repository.GetById(txtProductId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(GetCurrentProductCode());
            }
            else
            {
                var prodToUpdate = uowProduct.Repository.GetById(txtProductId.Text.Trim());
                prodToUpdate.ProductCode = GetCurrentProductCode();
                prodToUpdate.ProductName = txtProductName.Text.Trim();
                //Price = decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["price"].Value.ToString(), System.Globalization.NumberStyles.Currency),
                //prodToUpdate.Price = Convert.ToDecimal(txtPrice.Text.Trim());
                prodToUpdate.Price           = decimal.Parse(txtPrice.Text.Trim(), System.Globalization.NumberStyles.Currency);
                prodToUpdate.PriceDecreeDate = DateTime.Parse(dtpDecreeDate.Value.ToString("yyyy-MM-dd"));
                prodToUpdate.Discount        = float.Parse(txtDiscount.Text.Trim());
                prodToUpdate.RestockLevel    = Convert.ToInt32(txtRestock.Text.Trim());
                prodToUpdate.UnitId          = cbUom.SelectedValue.ToString();
                prodToUpdate.MedicineCatId   = cbMedCat.SelectedValue.ToString();
                prodToUpdate.UsageTypeId     = cbUsageType.SelectedValue.ToString();
                prodToUpdate.PrincipalId     = cbPrincipal.SelectedValue.ToString();
                prodToUpdate.ModifiedBy      = Properties.Settings.Default.CurrentUserId;
                prodToUpdate.ModifiedAt      = DateTime.Now;

                uowProduct.Repository.Update(prodToUpdate);
                uowProduct.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowSalesman.Repository.GetById(txtSalesmanId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtSalesmanCode.Text.Trim());
            }
            else
            {
                var salesmanToUpdate = uowSalesman.Repository.GetById(txtSalesmanId.Text.Trim());
                salesmanToUpdate.SalesmanCode = txtSalesmanCode.Text.Trim();
                salesmanToUpdate.FullName     = txtFullName.Text.Trim();
                salesmanToUpdate.Gender       = rbFemale.Checked ? Constant.Gender.Female : Constant.Gender.Male;
                salesmanToUpdate.Address      = txtAddress.Text.Trim();
                salesmanToUpdate.PostalCode   = txtPostCode.Text.Trim();
                salesmanToUpdate.Phone        = txtPhone.Text.Trim();
                salesmanToUpdate.Email        = txtEmail.Text.Trim();
                salesmanToUpdate.ProvinceId   = cbProvince.SelectedValue.ToString();
                salesmanToUpdate.DistrictId   = cbDistrict.SelectedValue.ToString();

                salesmanToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                salesmanToUpdate.ModifiedAt = DateTime.Now;

                uowSalesman.Repository.Update(salesmanToUpdate);
                uowSalesman.Commit();
                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = _uow.Repository.GetById(txtSalesOrderId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(lblSalesNo.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var customerId = cbCustomer.SelectedValue.ToString();
                    var customer   = new UnitOfWork <Customer>(dbContext).Repository.GetById(customerId);
                    var salesman   = new UnitOfWork <Salesman>(dbContext).Repository.GetById(cbSalesman.SelectedValue.ToString());
                    var top        = new UnitOfWork <TermOfPayment>(dbContext).Repository.GetById(cbTermOfPayment.SelectedValue.ToString());
                    var salesArea  = new UnitOfWork <SalesArea>(dbContext).Repository.GetById(cbSalesArea.SelectedValue.ToString());
                    var prov       = new UnitOfWork <Location>(dbContext).Repository.GetById(cbProvince.SelectedValue.ToString());
                    var district   = new UnitOfWork <Location>(dbContext).Repository.GetById(cbDistrict.SelectedValue.ToString());

                    #region parent
                    var uwSalesOrder = new UnitOfWork <SalesOrder>(dbContext);
                    var soToUpdate   = uwSalesOrder.Repository.GetById(txtSalesOrderId.Text.Trim());

                    soToUpdate.CustomerId          = customerId;
                    soToUpdate.CustomerName        = customer.CustomerName;
                    soToUpdate.CustomerAddress     = customer.Address;
                    soToUpdate.CustomerProvinceId  = customer.ProvinceId;
                    soToUpdate.CustomerProvince    = GetLocationName(customer.ProvinceId);
                    soToUpdate.CustomerDistrictId  = customer.DistrictId;
                    soToUpdate.CustomerDistrict    = GetLocationName(customer.DistrictId);
                    soToUpdate.CustomerPostalCode  = customer.PostalCode;
                    soToUpdate.CustomerPhone       = customer.Phone;
                    soToUpdate.CustomerEmail       = customer.Email;
                    soToUpdate.CustomerNpwp        = customer.Npwp;
                    soToUpdate.SalesmanId          = cbSalesman.SelectedValue.ToString();
                    soToUpdate.SalesmanCode        = salesman.SalesmanCode;
                    soToUpdate.TermOfPaymentId     = cbTermOfPayment.SelectedValue.ToString();
                    soToUpdate.TermOfPaymentCode   = top.TermCode;
                    soToUpdate.SalesDate           = dtpSalesOrderDate.Value;
                    soToUpdate.DueDate             = dtpDueDate.Value;
                    soToUpdate.DeliveryAddress     = txtDeliveryAddress.Text;
                    soToUpdate.DeliveryProvinceId  = cbProvince.SelectedValue.ToString();
                    soToUpdate.DeliveryProvince    = prov.Name;
                    soToUpdate.DeliveryDistrictId  = cbDistrict.SelectedValue.ToString();
                    soToUpdate.DeliveryDistrict    = district.Name;
                    soToUpdate.SalesAreaId         = cbSalesArea.SelectedValue.ToString();
                    soToUpdate.SalesAreaCode       = salesArea.AreaCode;
                    soToUpdate.SubTotalAmount      = decimal.Parse(txtSubTotal.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.ExtraDiscountAmount = decimal.Parse(txtExtraDiscount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.TaxBaseAmount       = decimal.Parse(txtTaxBaseAmount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.ValueAddedTaxAmount = decimal.Parse(txtValueAddedTaxAmount.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.GrandTotalAmount    = decimal.Parse(lblTotal.Text.Trim(), System.Globalization.NumberStyles.Currency);
                    soToUpdate.UserId   = Properties.Settings.Default.CurrentUserId;
                    soToUpdate.Username = Properties.Settings.Default.CurrentUser;

                    // Audit fields
                    soToUpdate.ModifiedBy = Properties.Settings.Default.CurrentUserId;
                    soToUpdate.ModifiedAt = DateTime.Now;

                    uwSalesOrder.Repository.Update(soToUpdate);
                    uwSalesOrder.Commit();

                    #endregion parent

                    #region child

                    var uwSoItem = new UnitOfWork <SalesOrderItem>(dbContext);

                    // clear all item for the identified Sales Order
                    var tobeClearedItems = uwSoItem.Repository.GetAll().Where(soi => soi.SalesOrderId == txtSalesOrderId.Text.Trim());
                    uwSoItem.Repository.Delete(tobeClearedItems);
                    uwSoItem.Commit();

                    // add with updated items
                    List <SalesOrderItem> orderItems = new List <SalesOrderItem>();
                    for (int i = 0; i < dgvSalesOrderItem.Rows.Count; ++i)
                    {
                        if (dgvSalesOrderItem.Rows[i].Cells["productCode"].Value == null)
                        {
                            continue;
                        }

                        var expiredDate     = commonHelper.GetEndOfMonth(DateTime.Parse(dgvSalesOrderItem.Rows[i].Cells["expDate"].Value.ToString()));
                        var qty             = Convert.ToInt32(decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["qty"].Value.ToString(), System.Globalization.NumberStyles.Currency));
                        var nettPrice       = Math.Round(decimal.Parse(dgvSalesOrderItem.Rows[i].Cells["price"].Value.ToString(), System.Globalization.NumberStyles.Currency), 5, MidpointRounding.AwayFromZero);
                        var discountPercent = Math.Round(Convert.ToDecimal(ValidateDiscount(dgvSalesOrderItem.Rows[i].Cells["discPercent"].Value.ToString().Replace("%", ""))) / 100, 5, MidpointRounding.AwayFromZero);
                        var grossValue      = Math.Round(qty * nettPrice, 5, MidpointRounding.AwayFromZero);
                        var subTotal        = salesOrderHelper.CalculateTaxBaseAmount(qty, nettPrice, discountPercent);

                        var soiToUpdate = new SalesOrderItem
                        {
                            SalesOrderId       = txtSalesOrderId.Text.Trim(),
                            ProductId          = dgvSalesOrderItem.Rows[i].Cells["productId"].Value.ToString(),
                            ProductCode        = dgvSalesOrderItem.Rows[i].Cells["productCode"].Value.ToString(),
                            ProductName        = dgvSalesOrderItem.Rows[i].Cells["productName"].Value.ToString(),
                            BatchId            = dgvSalesOrderItem.Rows[i].Cells["batchId"].Value.ToString(),
                            BatchCode          = dgvSalesOrderItem.Rows[i].Cells["batchCode"].Value.ToString(),
                            ExpiredDate        = commonHelper.StandardizeDate(expiredDate),
                            Quantity           = qty,
                            UomId              = dgvSalesOrderItem.Rows[i].Cells["uomId"].Value.ToString(),
                            UomCode            = dgvSalesOrderItem.Rows[i].Cells["uomCode"].Value.ToString(),
                            Price              = nettPrice,
                            DiscountPercentage = float.Parse(dgvSalesOrderItem.Rows[i].Cells["discPercent"].Value.ToString().Replace("%", "")),
                            TotalAmount        = subTotal,

                            // Audit Fields
                            CreatedBy  = Properties.Settings.Default.CurrentUserId,
                            CreatedAt  = DateTime.Now,
                            ModifiedBy = Properties.Settings.Default.CurrentUserId,
                            ModifiedAt = DateTime.Now
                        };
                        orderItems.Add(soiToUpdate);
                    }
                    uwSoItem.Repository.Add(orderItems);
                    uwSoItem.Commit();

                    #endregion child

                    dbContextTransaction.Commit();
                }

                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }
Exemplo n.º 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateMandatoryFields())
            {
                return;
            }

            var repoLastUpdated = uowRole.Repository.GetById(txtRoleId.Text.Trim()).ModifiedAt;
            var lastUpdated     = DateTime.Parse(txtModifiedAt.Text.Trim());

            var commonHelper = new CommonFunctionHelper();

            if (commonHelper.StandardizeDateTime(lastUpdated) != commonHelper.StandardizeDateTime(repoLastUpdated))
            {
                CommonMessageHelper.DataHasBeenUpdatedPriorToSave(txtRoleCode.Text.Trim());
            }
            else
            {
                using (var dbContextTransaction = dbContext.Database.BeginTransaction())
                {
                    var roleToUpdate = uowRole.Repository.GetById(txtRoleId.Text.Trim());
                    roleToUpdate.RoleCode    = txtRoleCode.Text.Trim();
                    roleToUpdate.Description = txtDescription.Text.Trim();
                    roleToUpdate.ModifiedBy  = Properties.Settings.Default.CurrentUserId;
                    roleToUpdate.ModifiedAt  = DateTime.Now;

                    var uwRole = new UnitOfWork <Role>(dbContext);
                    uwRole.Repository.Update(roleToUpdate);
                    uwRole.Commit();


                    var uwPermRole          = new UnitOfWork <PermissionRole>(dbContext);
                    var existingAccessCodes = GetExistingAccessCodes();
                    for (int i = 0; i < cblMasterData.Items.Count; i++)
                    {
                        var permissionCode = existingAccessCodes.Where(a => cblMasterData.Items[i].ToString().Contains(a.ToString())).FirstOrDefault().ToString();
                        var permission     = new UnitOfWork <Permission>(dbContext).Repository.GetAll()
                                             .Where(perm => perm.PermissionCode == permissionCode).FirstOrDefault();
                        var permRole = uwPermRole.Repository.GetAll().Where(pr => pr.PermisionId == permission.Id && pr.RoleId == roleToUpdate.Id).FirstOrDefault();

                        if (cblMasterData.GetItemCheckState(i) == CheckState.Unchecked && permRole != null)
                        {
                            uwPermRole.Repository.Delete(permRole);
                        }
                        else if (cblMasterData.GetItemCheckState(i) == CheckState.Checked && permRole == null)
                        {
                            var permRoleToAdd = new PermissionRole
                            {
                                RoleId      = roleToUpdate.Id,
                                PermisionId = permission.Id,

                                // Audit Fields
                                CreatedBy  = Properties.Settings.Default.CurrentUserId,
                                CreatedAt  = DateTime.Now,
                                ModifiedBy = Properties.Settings.Default.CurrentUserId,
                                ModifiedAt = DateTime.Now
                            };
                            uwPermRole.Repository.Add(permRoleToAdd);
                        }

                        uwPermRole.Commit();
                    }

                    for (int i = 0; i < cblTransaksi.Items.Count; i++)
                    {
                        var permissionCode = existingAccessCodes.Where(a => cblTransaksi.Items[i].ToString().Contains(a.ToString())).FirstOrDefault().ToString();
                        var permission     = new UnitOfWork <Permission>(dbContext).Repository.GetAll()
                                             .Where(perm => perm.PermissionCode == permissionCode).FirstOrDefault();
                        var permRole = uwPermRole.Repository.GetAll().Where(pr => pr.PermisionId == permission.Id && pr.RoleId == roleToUpdate.Id).FirstOrDefault();

                        if (cblTransaksi.GetItemCheckState(i) == CheckState.Unchecked && permRole != null)
                        {
                            uwPermRole.Repository.Delete(permRole);
                        }
                        else if (cblTransaksi.GetItemCheckState(i) == CheckState.Checked && permRole == null)
                        {
                            var permRoleToAdd = new PermissionRole
                            {
                                RoleId      = roleToUpdate.Id,
                                PermisionId = permission.Id,

                                // Audit Fields
                                CreatedBy  = Properties.Settings.Default.CurrentUserId,
                                CreatedAt  = DateTime.Now,
                                ModifiedBy = Properties.Settings.Default.CurrentUserId,
                                ModifiedAt = DateTime.Now
                            };
                            uwPermRole.Repository.Add(permRoleToAdd);
                        }

                        uwPermRole.Commit();
                    }

                    for (int i = 0; i < cblReporting.Items.Count; i++)
                    {
                        var permissionCode = existingAccessCodes.Where(a => cblReporting.Items[i].ToString().Contains(a.ToString())).FirstOrDefault().ToString();
                        var permission     = new UnitOfWork <Permission>(dbContext).Repository.GetAll()
                                             .Where(perm => perm.PermissionCode == permissionCode).FirstOrDefault();
                        var permRole = uwPermRole.Repository.GetAll().Where(pr => pr.PermisionId == permission.Id && pr.RoleId == roleToUpdate.Id).FirstOrDefault();

                        if (cblReporting.GetItemCheckState(i) == CheckState.Unchecked && permRole != null)
                        {
                            uwPermRole.Repository.Delete(permRole);
                        }
                        else if (cblReporting.GetItemCheckState(i) == CheckState.Checked && permRole == null)
                        {
                            var permRoleToAdd = new PermissionRole
                            {
                                RoleId      = roleToUpdate.Id,
                                PermisionId = permission.Id,

                                // Audit Fields
                                CreatedBy  = Properties.Settings.Default.CurrentUserId,
                                CreatedAt  = DateTime.Now,
                                ModifiedBy = Properties.Settings.Default.CurrentUserId,
                                ModifiedAt = DateTime.Now
                            };
                            uwPermRole.Repository.Add(permRoleToAdd);
                        }

                        uwPermRole.Commit();
                    }

                    dbContextTransaction.Commit();
                }


                btnReload.PerformClick();
                CommonMessageHelper.DataSavedSuccessfully();
            }
        }