public async Task <MxReturnCode <bool> > CreateRoleAsync(string name, int rolecode, string purpose, string description) { MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.CreateRoleAsync()"); if ((String.IsNullOrWhiteSpace(name)) || (GdprUrd.IsValidRoleCode(rolecode) == false) || (String.IsNullOrWhiteSpace(purpose)) || (String.IsNullOrWhiteSpace(description))) { rc.SetError(1020101, MxError.Source.Param, "invalid name, rolecode, purpose, description"); } else { try { //ASPNETRole ID, //Get WST from Title //Create WXR if ((rc += CheckConnection()).IsSuccess()) { GdprUrd role = new GdprUrd { Name = name, RoleCode = rolecode, Purpose = purpose, Description = description, Status = (int)GdprUrd.StatusVal.NotImplemented }; var sql = "INSERT INTO GdprUrd(Name, RoleCode, Status, Purpose, Description) VALUES(@Name, @RoleCode, @Status, @Purpose, @Description);"; var res = await db.ExecuteAsync(sql, role); if (res != 1) { rc.SetError(1020102, MxError.Source.Data, String.Format("invalid record data {0}", role.ToString())); } else { rc.SetResult(true); } } } catch (Exception e) { rc.SetError(1020103, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException); } } return(rc); }
public async Task <MxReturnCode <bool> > CreateUrdAsync(string name, int roleCode, UrdStatus roleStatus, string purpose, string description, Guid wstId) { MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.CreateUrdAsync()"); if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(purpose) || string.IsNullOrWhiteSpace(description) || (GdprUrd.IsValidRoleCode(roleCode) == false) || (wstId == Guid.Empty)) { rc.SetError(1010201, MxError.Source.Param, $"name={name ?? "[null]"} or purpose or description null or empty, or roleCode {roleCode} is invalid, or wstId is empty"); } else { try { if ((rc += CheckConnection()).IsSuccess()) { GdprUrd role = new GdprUrd { Name = name, RoleCode = roleCode, Purpose = purpose, Description = description, Status = (int)roleStatus }; var sql = "INSERT INTO GdprUrd(Name, RoleCode, Status, Purpose, Description) VALUES(@Name, @RoleCode, @Status, @Purpose, @Description);"; var resultCreateUrd = await db.ExecuteAsync(sql, role); if (resultCreateUrd != 1) { rc.SetError(1010202, MxError.Source.Data, $"unable to create role={name}"); } else { var resGetUrd = await GetUrdAsync(name); rc += resGetUrd; if ((rc.IsError()) || (resGetUrd.GetResult() == null)) { rc.SetError(1010203, MxError.Source.Data, $"unable to access new role={name}"); } { GdprWxr wxr = new GdprWxr { UrdId = resGetUrd.GetResult().Id, WstId = wstId }; sql = "INSERT INTO GdprWxr(@UrdId, WstId) VALUES(@UrdId, @WstId);"; var resultCreateWxr = await db.ExecuteAsync(sql, wxr); if (resultCreateWxr != 1) { rc.SetError(1010204, MxError.Source.Data, $"unable to create WXR for role={name}, WstId={wstId}"); } else { rc.SetResult(true); } } } } } catch (Exception e) { rc.SetError(1010205, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException); } } return(rc); }
public async Task <MxReturnCode <bool> > UpdateRoleAsync(GdprUrd role, string name, int rolecode, string purpose, string description, GdprUrd.StatusVal status) { MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.UpdateRoleAsync()", false); if ((role == null) || (RepositoryBase.IsGuidSet(role.Id) == false) || (String.IsNullOrWhiteSpace(name)) || (GdprUrd.IsValidRoleCode(rolecode) == false)) { rc.SetError(1020401, MxError.Source.Param, "role is null, role.Id is not set, name is null or emptpy, or rolecode is invalid"); } else { try { if ((rc += CheckConnection()).IsSuccess()) { var sql = "UPDATE GdprUrd SET Name = @Name, RoleCode = @RoleCode, Status = @Status, Purpose = @Purpose, Description = @Description WHERE Id = @Id;"; var res = await db.ExecuteAsync(sql, new { Name = name, RoleCode = rolecode, Status = (int)status, Purpose = purpose, Description = description, Id = role.Id }); if (res != 1) { rc.SetError(1020402, MxError.Source.Data, String.Format("record not updated {0}", role.ToString())); } else { rc.SetResult(true); } } } catch (Exception e) { rc.SetError(1020403, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException); } } return(rc); }
public async Task <MxReturnCode <bool> > UpdateUrdAsync(string roleName, int roleCode, UrdStatus roleStatus, string purpose, string description) { MxReturnCode <bool> rc = new MxReturnCode <bool>($"AdminRepository.UpdateUrdAsync({roleName ?? "[null]"})"); if (String.IsNullOrWhiteSpace(roleName) || String.IsNullOrWhiteSpace(purpose) || String.IsNullOrWhiteSpace(description) || (GdprUrd.IsValidRoleCode(roleCode) == false)) { rc.SetError(1010401, MxError.Source.Param, "roleName, purpose or description is null or empty, or rolecode is invalid"); } else { try { if ((rc += CheckConnection()).IsSuccess()) { var sql = "UPDATE GdprUrd SET RoleCode = @RoleCode, Status = @Status, Purpose = @Purpose, Description = @Description WHERE Name = @Name;"; var res = await db.ExecuteAsync(sql, new { RoleCode = roleCode, Status = (int)roleStatus, Purpose = purpose, Description = description, Name = roleName }); if (res != 1) { rc.SetError(1010402, MxError.Source.Data, $"record not updated: Name={roleName}"); } else { rc.SetResult(true); } } } catch (Exception e) { rc.SetError(1010403, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException); } } return(rc); }