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> > 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> > DeleteRoleAsync(GdprUrd role) { MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.DeleteRoleAsync()", false); if (role == null) { rc.SetError(1020301, MxError.Source.Param, "role is null"); } else { try { if ((rc += CheckConnection()).IsSuccess()) { var sql = "DELETE FROM GdprUrd WHERE Id = @Id"; var res = await db.ExecuteAsync(sql, new { Id = role.Id }); if (res != 1) { rc.SetError(1020302, MxError.Source.Data, String.Format("record not deleted {0}", role.ToString())); } else { rc.SetResult(true); } } } catch (Exception e) { rc.SetError(1020303, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException); } } return(rc); }