public IActionResult Edit(CreatePartnerActivity2Dto model) { if (ModelState.IsValid) { var currentRoleId = _PartnerManager.GetCurrentUserRole(this.HttpContext); var permission = _partActRepo.GetPartAct("PartnerActivity.Edit", currentRoleId); if (permission == null) { toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions { Title = "" }); return(Redirect(Request.Headers["Referer"].ToString())); } var old = _partActRepo.GetPartAct(model.Id); if (old == null) { return(View(model)); } var pAct = new PartnerActivity(); pAct.Id = model.Id; pAct.Activity.Id = model.ActivityId; pAct.FromRole.Id = model.FromRoleId ?? 0; pAct.MaxQueryRows = model.MaxQueryRowsNo; pAct.MaxQueryDuration.Id = model.MaxQueryDurationId; pAct.Scope.Id = model.ScopeId; pAct.OnlyPartnerChildren = model.OnlyPartnerChildren; pAct.LastEditOn = DateTime.Now; var result = _partActRepo.Edit(pAct); if (result.Success) { var audit = new DataAudit(); audit.Activity.Id = "PartnerActivity.Edit"; audit.PartnerId = _PartnerManager.GetCurrentUserId(this.HttpContext); audit.PartnerAccount = _PartnerManager.GetCurrentUserAccount(this.HttpContext); audit.Action.Id = "Update"; audit.Success = true; audit.OldValue = old.ToString(); audit.NewValue = pAct.ToString(); _auditing.Create(audit); return(RedirectToAction("Index")); } else { model.Error = result.Error; } } var fromRoles = new RoleRepo(db, _partActRepo).GetRoles(); var activities = new ActivityRepo(db, _PartnerManager).GetActivities(); var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration"); var scopes = new CommonCodeRepo(db).GetCodesByType("activity.scope"); model.FromRoles = fromRoles; model.Activities = activities; model.MaxQueryDuration = maxQueryDuration; model.Scopes = scopes; return(View(model)); }
private PartnerActivity ConvertDataRowToDataModel(DataRow row) { var partAct = new PartnerActivity(); partAct.Id = row["row_id"] == DBNull.Value ? 0 : int.Parse(row["row_id"].ToString()); partAct.Activity.Id = row["act_id"] == DBNull.Value ? string.Empty : row["act_id"].ToString(); partAct.Activity.Name = row["act_name"] == DBNull.Value ? string.Empty : row["act_name"].ToString(); partAct.Activity.Type = row["act_type"] == DBNull.Value ? string.Empty : row["act_type"].ToString(); partAct.Activity.Order = row["act_order"] == DBNull.Value ? 0 : int.Parse(row["act_order"].ToString()); partAct.Activity.Internal = row["internal_use"] == DBNull.Value ? false : row["internal_use"].ToString() == "1" ? true : false; partAct.FromRole.Id = row["fromroleid"] == DBNull.Value ? 0 : int.Parse(row["fromroleid"].ToString()); partAct.FromRole.Name = row["fromrolename"] == DBNull.Value ? string.Empty : row["fromrolename"].ToString(); partAct.FromRole.IsActive = row["fromroleisactive"] == DBNull.Value ? false : row["fromroleisactive"].ToString() == "1" ? true : false; partAct.FromRole.Weight = row["fromroleweight"] == DBNull.Value ? 0 : int.Parse(row["fromroleweight"].ToString()); partAct.FromRole.Order = row["fromroleorder"] == DBNull.Value ? byte.MinValue : byte.Parse(row["fromroleorder"].ToString()); partAct.FromRole.Code = row["fromordercode"] == DBNull.Value ? string.Empty : row["fromordercode"].ToString(); partAct.MaxQueryDuration.Id = row["queryduration"] == DBNull.Value ? string.Empty : row["queryduration"].ToString(); partAct.MaxQueryDuration.Name = row["queryduration_name"] == DBNull.Value ? string.Empty : row["queryduration_name"].ToString(); partAct.Scope.Id = row["act_scope"] == DBNull.Value ? string.Empty : row["act_scope"].ToString(); partAct.Scope.Name = row["act_scope_name"] == DBNull.Value ? string.Empty : row["act_scope_name"].ToString(); partAct.MaxQueryRows = row["maxrec"] == DBNull.Value ? 0 : int.Parse(row["maxrec"].ToString()); partAct.OnlyPartnerChildren = row["onlypartchildren"] == DBNull.Value ? false : row["onlypartchildren"].ToString() == "1" ? true : false; partAct.CreatedOn = row["createdon"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["createdon"].ToString()); partAct.LastEditOn = row["lastediton"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["lastediton"].ToString()); partAct.CreatedBy.Id = row["createdby"] == DBNull.Value ? string.Empty : row["createdby"].ToString(); partAct.CreatedBy.Account = row["createdbyacc"] == DBNull.Value ? -1 : int.Parse(row["createdbyacc"].ToString()); partAct.CreatedBy.Name = row["createdname"] == DBNull.Value ? string.Empty : row["createdname"].ToString(); return(partAct); }
public PartnerActivity GetPartAct(string actId, int fromRoleId, int toRoleId) { var parameters = new List <OracleParameter> { new OracleParameter { ParameterName = "actId", OracleDbType = OracleDbType.Varchar2, Value = actId }, new OracleParameter { ParameterName = "fromRoleId", OracleDbType = OracleDbType.Int32, Value = fromRoleId } }; var actDataTable = this.db.GetData("Select * from v_partner_activity where act_id=:actId and fromroleid=:fromRoleId ", parameters); var partAct = new PartnerActivity(); if (actDataTable != null && actDataTable.Rows.Count > 0) { DataRow row = actDataTable.Rows[0]; partAct = ConvertDataRowToDataModel(row); partAct.Details = GetDetails(partAct.Id); return(partAct); } else { return(null); } }
public OpertionResult Create(PartnerActivity partnerActivity) { try { #region Parameters var parameters = new List <OracleParameter> { new OracleParameter { ParameterName = "retVal", OracleDbType = OracleDbType.Int32, Direction = ParameterDirection.ReturnValue }, new OracleParameter { ParameterName = "v_act_id", OracleDbType = OracleDbType.Varchar2, Value = partnerActivity.Activity.Id }, new OracleParameter { ParameterName = "v_fromroleid", OracleDbType = OracleDbType.Int32, Value = partnerActivity.FromRole.Id }, new OracleParameter { ParameterName = "v_queryduration", OracleDbType = OracleDbType.Varchar2, Value = partnerActivity.MaxQueryDuration.Id }, new OracleParameter { ParameterName = "v_act_scope", OracleDbType = OracleDbType.Varchar2, Value = partnerActivity.Scope.Id }, new OracleParameter { ParameterName = "v_maxrec", OracleDbType = OracleDbType.Int32, Value = partnerActivity.MaxQueryRows }, new OracleParameter { ParameterName = "v_onlypartchildren", OracleDbType = OracleDbType.Int32, Value = partnerActivity.OnlyPartnerChildren ? 1 : 0 }, new OracleParameter { ParameterName = "v_createdby", OracleDbType = OracleDbType.Varchar2, Value = partnerActivity.CreatedBy.Id }, new OracleParameter { ParameterName = "v_createdbyacc", OracleDbType = OracleDbType.Int32, Value = partnerActivity.CreatedBy.Account } }; #endregion db.ExecuteStoredProc("pk_Settings.fn_CreatePartnerActivity", parameters); var result = int.Parse(parameters.Find(x => x.ParameterName == "retVal").Value.ToString()); if (result > 0) { return(new OpertionResult { AffectedCount = result, Success = true, Error = string.Empty }); } else { return(new OpertionResult { AffectedCount = result, Success = false, Error = string.Empty }); } } catch (Exception ex) { return(new OpertionResult { AffectedCount = -1, Success = false, Error = ex.Message }); } }
public PartnerActivity GetPartActOnly(int id) { var parameters = new List <OracleParameter> { new OracleParameter { ParameterName = "pactrowid", OracleDbType = OracleDbType.Int32, Value = id } }; var actDataTable = this.db.GetData("Select * from v_partner_activity where row_id=:pactrowid ", parameters); var partAct = new PartnerActivity(); if (actDataTable != null) { DataRow row = actDataTable.Rows[0]; partAct = ConvertDataRowToDataModel(row); } return(partAct); }
public IActionResult CreateRule(CreatePartnerActivity2Dto model) { if (ModelState.IsValid) { var currentRoleId = _PartnerManager.GetCurrentUserRole(this.HttpContext); var permission = _partActRepo.GetPartAct("PartnerActivity.Create", currentRoleId); if (permission == null) { toastNotification.AddErrorToastMessage("ليس لديك الصلاحية الكافية", new ToastrOptions { Title = "" }); return(Redirect(Request.Headers["Referer"].ToString())); } var pAct = new PartnerActivity(); pAct.Activity.Id = model.ActivityId; pAct.FromRole.Id = model.FromRoleId ?? 0; pAct.MaxQueryRows = model.MaxQueryRowsNo; pAct.MaxQueryDuration.Id = model.MaxQueryDurationId; pAct.Scope.Id = model.ScopeId; pAct.OnlyPartnerChildren = model.OnlyPartnerChildren; pAct.CreatedBy.Id = _PartnerManager.GetCurrentUserId(this.HttpContext); pAct.CreatedBy.Account = _PartnerManager.GetCurrentUserAccount(this.HttpContext); var result = _partActRepo.Create(pAct); if (result.Success) { var listModel = new ListPartnerActivityDto(); listModel.Activities = new SelectList(new ActivityRepo(db, _PartnerManager).GetActivities(), "Id", "Name"); listModel.FromRoles = new SelectList(new RoleRepo(db, _partActRepo).GetRoles(), "Id", "Name"); //return View("Index", listModel); return(RedirectToAction("Detail", "PartActivity", new { id = result.AffectedCount })); } else if (result.AffectedCount == -504) { var permission2 = _partActRepo.GetPartAct("PartnerActivity.Query", currentRoleId); if (permission2 == null) { toastNotification.AddErrorToastMessage("تم انشاء هذه الصلاحية مسبقا ", new ToastrOptions { Title = "" }); } else { return(RedirectToAction("Detail", "PartActivity", new { id = permission2.Id })); } } else { toastNotification.AddErrorToastMessage("لم يتم انشاء الصلاحية ، يرجى المحاولة لاحقا ", new ToastrOptions { Title = "" }); } } var fromRoles = new RoleRepo(db, _partActRepo).GetRoles(); var activities = new ActivityRepo(db, _PartnerManager).GetActivities(); var maxQueryDuration = new CommonCodeRepo(db).GetCodesByType("queryduration"); var scopes = new CommonCodeRepo(db).GetCodesByType("activity.scope"); model.FromRoles = fromRoles; model.Activities = activities; model.MaxQueryDuration = maxQueryDuration; model.Scopes = scopes; return(View(model)); }
public async Task <List <AppBackgroundService> > GetBackgroundServicesAsync(BackgroundServiceListParam param, PartnerActivity permission, string currentPartnerId, int currentPartnerAccount) { #region Parameters var parameters = new List <OracleParameter>(); var whereCluase = new StringBuilder(); if (param != null) { if (!string.IsNullOrEmpty(param.Source) && param.Source != "-1") { whereCluase.Append(" WHERE bg_source = :Source"); var p = new OracleParameter { ParameterName = "Source", OracleDbType = OracleDbType.Varchar2, Value = param.Source }; parameters.Add(p); } if (param.Id > 0) { whereCluase.Append(whereCluase.Length > 0 ? " AND bg_id = :bgId" : " WHERE bg_id = :bgId"); var p = new OracleParameter { ParameterName = "bgId", OracleDbType = OracleDbType.Int32, Value = param.Id }; parameters.Add(p); } if (!string.IsNullOrEmpty(param.CreatedById)) { whereCluase.Append(whereCluase.Length > 0 ? " AND createdby = :CreatedById" : " WHERE createdby = :CreatedById"); var p = new OracleParameter { ParameterName = "CreatedById", OracleDbType = OracleDbType.Varchar2, Value = param.CreatedById }; parameters.Add(p); } if (param.ActionPartnerAccount > 0) { whereCluase.Append(whereCluase.Length > 0 ? " AND action_partner_acc = :ActionPartnerAcc " : " WHERE action_partner_acc = :ActionPartnerAcc "); var p = new OracleParameter { ParameterName = "ActionPartnerAcc", OracleDbType = OracleDbType.Int32, Value = param.ActionPartnerAccount }; parameters.Add(p); } if (permission.Scope.Id == "CurOpOnly") { whereCluase.Append(whereCluase.Length > 0 ? $" AND (partner_id = :PartnerId OR action_partner_acc = {currentPartnerAccount})" : $" WHERE (partner_id = :PartnerId OR action_partner_acc = {currentPartnerAccount})"); var p = new OracleParameter { ParameterName = "PartnerId", OracleDbType = OracleDbType.Varchar2, Value = currentPartnerId }; parameters.Add(p); } else if (!string.IsNullOrEmpty(param.PartnerId)) { whereCluase.Append(whereCluase.Length > 0 ? " AND partner_id = :PartnerId" : " WHERE partner_id = :PartnerId"); var p = new OracleParameter { ParameterName = "PartnerId", OracleDbType = OracleDbType.Varchar2, Value = param.PartnerId }; parameters.Add(p); } if (permission.Scope.Id == "Exclusive") { var parm = new OracleParameter { ParameterName = "RefId", OracleDbType = OracleDbType.Varchar2, Value = currentPartnerId }; whereCluase.Append(whereCluase.Length > 0 ? $" AND (ref_partner=:RefId OR action_partner_acc = {currentPartnerAccount})" : $" WHERE (ref_partner=:RefId OR action_partner_acc = {currentPartnerAccount})"); parameters.Add(parm); } if (!string.IsNullOrEmpty(param.Status) && param.Status != "-1") { whereCluase.Append(whereCluase.Length > 0 ? " AND status = :StatusId" : " WHERE status = :StatusId"); var p = new OracleParameter { ParameterName = "StatusId", OracleDbType = OracleDbType.Varchar2, Value = param.Status }; parameters.Add(p); } if (!string.IsNullOrEmpty(param.Name)) { whereCluase.Append(whereCluase.Length > 0 ? " AND service_name LIKE '%' || :Name || '%' " : " WHERE service_name LIKE '%' || :Name || '%' "); var p = new OracleParameter { ParameterName = "Name", OracleDbType = OracleDbType.Varchar2, Value = param.Name }; parameters.Add(p); } //if (param.IncludeDates) { if (param.StartDate > DateTime.MinValue && param.StartDate != null) { whereCluase.Append(whereCluase.Length > 0 ? " AND createdon >= :StartDate" : " WHERE createdon >= :StartDate"); var p = new OracleParameter { ParameterName = "StartDate", OracleDbType = OracleDbType.Date, Value = param.StartDate }; parameters.Add(p); } if (param.EndDate > DateTime.MinValue && param.EndDate != null) { whereCluase.Append(whereCluase.Length > 0 ? " AND createdon <= :EndDate" : " WHERE createdon <= :EndDate"); var p = new OracleParameter { ParameterName = "EndDate", OracleDbType = OracleDbType.Date, Value = param.EndDate.AddDays(1) }; parameters.Add(p); } } if (permission.Details == null || permission.Details.Count == 0) { whereCluase.Append(string.IsNullOrEmpty(whereCluase.ToString()) ? " WHERE roleid=-1 " : " AND roleid=-1 "); } else { var allowedRoles = string.Join(",", permission.Details.Select(x => x.ToRole.Id).ToList()); whereCluase.Append(string.IsNullOrEmpty(whereCluase.ToString()) ? $" WHERE (roleid in ( {allowedRoles} ) OR action_partner_acc = {currentPartnerAccount})" : $" AND ( roleid in ( {allowedRoles} ) OR action_partner_acc = {currentPartnerAccount})"); } } #endregion string strSql = $"select * from v_bg_service {whereCluase} order by bg_id"; DataTable masterDataTable; masterDataTable = await db.GetDataAsync(strSql, parameters); if (masterDataTable == null) { return(null); } if (masterDataTable.Rows.Count == 0) { return(null); } var results = new List <AppBackgroundService>(); foreach (DataRow row in masterDataTable.Rows) { var obj = ConvertDataRowToAppBackgroundService(row); results.Add(obj); } return(results); }